|
1 |
| -# string-case-swift |
| 1 | +StringCase |
| 2 | +================================= |
| 3 | + |
| 4 | +[](https://swift.org/package-manager/) |
| 5 | +[](http://twitter.com/Digipolitan) |
| 6 | + |
| 7 | +String extension to write camelCase string and snakeCase string |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +### SPM |
| 12 | + |
| 13 | +To install StringCase with SwiftPackageManager, add the following lines to your `Package.swift`. |
| 14 | + |
| 15 | +```swift |
| 16 | +let package = Package( |
| 17 | + name: "XXX", |
| 18 | + products: [ |
| 19 | + .library( |
| 20 | + name: "XXX", |
| 21 | + targets: ["XXX"]), |
| 22 | + ], |
| 23 | + dependencies: [ |
| 24 | + .package(url: "https://github.com/Digipolitan/string-case-swift.git", .branch("master")) |
| 25 | + ], |
| 26 | + targets: [ |
| 27 | + .target( |
| 28 | + name: "XXX", |
| 29 | + dependencies: ["StringCase"]), |
| 30 | + .testTarget( |
| 31 | + name: "XXXTests", |
| 32 | + dependencies: ["CommandLineArgs"]) |
| 33 | + ] |
| 34 | +) |
| 35 | +``` |
| 36 | + |
| 37 | +## The Basics |
| 38 | + |
| 39 | +- CamelCase |
| 40 | + |
| 41 | +Transform the current string to a camel case string as follow : |
| 42 | + |
| 43 | +```swift |
| 44 | +let res = "i love swift".camelCased() |
| 45 | +print("\(res)") // Will print iLoveSwift |
| 46 | +``` |
| 47 | + |
| 48 | +```swift |
| 49 | +let res = " i love swift ".camelCased(.capitalized) |
| 50 | +print("\(res)") // Will print ILoveSwift |
| 51 | +``` |
| 52 | + |
| 53 | +- SnakeCase |
| 54 | + |
| 55 | +Transform the current string to a snake case string as follow : |
| 56 | + |
| 57 | +```swift |
| 58 | +let res = "i love swift".snakeCased() |
| 59 | +print("\(res)") // Will print i_love_swift |
| 60 | +``` |
| 61 | + |
| 62 | +```swift |
| 63 | +let res = "i_LOVE SWIFT".snakeCased() |
| 64 | +print("\(res)") // Will print i_love_swift |
| 65 | +``` |
| 66 | + |
| 67 | +```swift |
| 68 | +let res = " iLove Swift ".snakeCased(.upper) |
| 69 | +print("\(res)") // Will print I_LOVE_SWIFT |
| 70 | +``` |
| 71 | + |
| 72 | +## Contributing |
| 73 | + |
| 74 | +See [CONTRIBUTING.md](CONTRIBUTING.md) for more details! |
| 75 | + |
| 76 | +This project adheres to the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). |
| 77 | +By participating, you are expected to uphold this code. Please report |
| 78 | +unacceptable behavior to [[email protected]](mailto:[email protected]). |
| 79 | + |
| 80 | +## License |
| 81 | + |
| 82 | +StringCase is licensed under the [BSD 3-Clause license](LICENSE). |
0 commit comments