String - leacode/SwiftWings GitHub Wiki
Source: Sources/Extensions/Foundation/String
Tests: Tests/Extensions/String
-
asURL,asDict,asArray,localized, and JSON initializers/transformers mirror the functionality of theDatahelpers.
- Detects single emojis, purely-emoji strings, and strips emojis while respecting composed scalars.
-
fileExtensionextracts the file suffix without dealing withNSStringAPIs.
- Implements MD5 hashing entirely in Swift, exposing a
.md5computed property.
- Pluralization logic (with irregular forms), vowel/consonant lists, dictionary-based replacements, trimming trailing spaces, and capitalization helpers.
- Adds slicing support for
ClosedRange,Range, and all partial range flavors while preventing out-of-bounds traps.
- Contains a broad validation toolkit: phone numbers, links, addresses, email, JSON, UUID, numeric checks, Luhn algorithm for bank cards, condensed whitespace, etc.
let json = #"{"id":1}"#
print(json.asDict?["id"] as Any) // Optional(1)
print("hello😊".containsEmoji) // true
print("file.tar.gz".fileExtension ?? "") // "gz"
print("make".pluralize(2)) // "makes"
print("123456789".matches(pattern: #"^\d+$"#)) // true
print("[" + "abc".asArray.debugDescription) // Optional(["a", "b", "c"])