Skip to content

Digipolitan/string-case-swift

StringCase

Swift Version Swift Package Manager Twitter

String extension to write camelCase string and snakeCase string

Installation

SPM

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"])
    ]
)

The Basics

  • CamelCase

Transform the current string to a camel case string as follow :

let res = "i love swift".camelCased()
print("\(res)") // Will print iLoveSwift
let 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_swift
let res = "i_LOVE SWIFT".snakeCased()
print("\(res)") // Will print i_love_swift
let res = " iLove    Swift ".snakeCased(.upper)
print("\(res)") // Will print I_LOVE_SWIFT

Contributing

See 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.

License

StringCase is licensed under the BSD 3-Clause license.