String extension to write camelCase string and snakeCase string
To install StringCase with SwiftPackageManager, add the following lines to your Package.swift.
let package = Package(
name: "XXX",
products: [
.library(
name: "XXX",
targets: ["XXX"]),
],
dependencies: [
.package(url: "https://github.com/Digipolitan/string-case-swift.git", from: "1.0.0")
],
targets: [
.target(
name: "XXX",
dependencies: ["StringCase"])
]
)- CamelCase
Transform the current string to a camel case string as follow :
let res = "i love swift".camelCased()
print("\(res)") // Will print iLoveSwiftlet res = " i love swift ".camelCased(.capitalized)
print("\(res)") // Will print ILoveSwift- SnakeCase
Transform the current string to a snake case string as follow :
let res = "i love swift".snakeCased()
print("\(res)") // Will print i_love_swiftlet res = "i_LOVE SWIFT".snakeCased()
print("\(res)") // Will print i_love_swiftlet res = " iLove Swift ".snakeCased(.upper)
print("\(res)") // Will print I_LOVE_SWIFTSee CONTRIBUTING.md for more details!
This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to contact@digipolitan.com.
StringCase is licensed under the BSD 3-Clause license.