Refactoring
This commit is contained in:
parent
cf00c1cd30
commit
7d277a0e43
10 changed files with 384 additions and 312 deletions
|
@ -0,0 +1,7 @@
|
|||
import Foundation
|
||||
|
||||
extension FileWrapper {
|
||||
convenience init(_ string: String) {
|
||||
self.init(regularFileWithContents: Data(string.utf8))
|
||||
}
|
||||
}
|
40
Sources/LibMakeColors/Extensions/String+Extensions.swift
Normal file
40
Sources/LibMakeColors/Extensions/String+Extensions.swift
Normal file
|
@ -0,0 +1,40 @@
|
|||
extension StringProtocol {
|
||||
var capitalizeFirst: String {
|
||||
guard !isEmpty else {
|
||||
return String(self)
|
||||
}
|
||||
|
||||
return prefix(1).uppercased() + dropFirst()
|
||||
}
|
||||
|
||||
var lowercasedFirst: String {
|
||||
guard !isEmpty else {
|
||||
return String(self)
|
||||
}
|
||||
|
||||
return prefix(1).lowercased() + dropFirst()
|
||||
}
|
||||
|
||||
func droppingSuffix(_ suffix: String) -> SubSequence {
|
||||
guard hasSuffix(suffix) else {
|
||||
return self[...]
|
||||
}
|
||||
|
||||
return dropLast(suffix.count)
|
||||
}
|
||||
|
||||
func insertCamelCaseSeparators(separator: String = " ") -> String {
|
||||
replacingOccurrences(
|
||||
of: "(?<=[a-z0-9])([A-Z])",
|
||||
with: "\(separator)$1",
|
||||
options: .regularExpression,
|
||||
range: nil
|
||||
)
|
||||
}
|
||||
|
||||
func camelCasePathToSnakeCase() -> String {
|
||||
insertCamelCaseSeparators(separator: "_")
|
||||
.replacingOccurrences(of: "/", with: "_")
|
||||
.lowercased()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue