JGString is a lightweight set of String helpers for Swift. This repository now includes:
- Swift Package Manager support
- XCTest coverage for the public extension methods
- modern CI through GitHub Actions
dependencies: [
.package(url: "https://github.com/JanyGee/JGString.git", from: "1.0.2")
]Then add "JGString" to your target dependencies.
pod "JGString"import JGString
"<a>foo</a>".between(left: "<a>", "</a>") // "foo"
"background-color".camelize() // "backgroundColor"
"Crème brûlée".slugify() // "creme-brulee"
", ".join(elements: [1, 2, 3]) // "1, 2, 3"
" hello world ".collapseWhitespace() // "hello world"
"The Weekend ‘King’".decodeHTML() // "The Weekend ‘King’"The extension includes helpers for:
- extracting content, searching, and prefix/suffix handling
- casing, slug generation, whitespace cleanup, and punctuation stripping
- initials, line splitting, padding, and repeated strings
- numeric, boolean, and date conversion
- HTML entity decoding
The most accurate behavioral reference is the test suite in Tests/JGStringTests/JGStringTests.swift.
Run the package tests with:
swift test"2.00".toDouble() // 2.0 "2".toDouble() // 2.0
**trimmedLeft()**
```swift
" How are you? ".trimmedLeft() // "How are you? "
trimmedRight()
" How are you? ".trimmedRight() // " How are you?"trimmed()
" How are you? ".trimmed() // "How are you?"slugify()
"Global Thermonuclear Warfare".slugify() // "global-thermonuclear-warfare"
"Crème brûlée".slugify() // "creme-brulee"stripPunctuation()
"My, st[ring] *full* of %punct)".stripPunctuation() // "My string full of punct"substring(startIndex, length)
"hello world".substring(startIndex: 0, length: 1) // "h"
"hello world".substring(startIndex: 0, length: 11) // "hello world"[subscript]
""hello world"[0..<2] == "he"" // "he"
""hello world"[0..<1] == "h"" // "h"
""hello world"[0] == "h""
""hello world"[0..<11] == "hello world"" // "hello world"Jany Gee, [email protected]
JGString is available under the MIT license. See the LICENSE file for more info.