String - leacode/SwiftWings GitHub Wiki

String Extensions

Source: Sources/Extensions/Foundation/String

Tests: Tests/Extensions/String

JSON & URLs (String+Extensions.swift)

  • asURL, asDict, asArray, localized, and JSON initializers/transformers mirror the functionality of the Data helpers.

Emoji Utilities (String+Emoji.swift)

  • Detects single emojis, purely-emoji strings, and strips emojis while respecting composed scalars.

File Helpers (String+File.swift)

  • fileExtension extracts the file suffix without dealing with NSString APIs.

MD5 (String+MD5.swift)

  • Implements MD5 hashing entirely in Swift, exposing a .md5 computed property.

Text Modification (String+Modify.swift)

  • Pluralization logic (with irregular forms), vowel/consonant lists, dictionary-based replacements, trimming trailing spaces, and capitalization helpers.

Safe Subscripts (String+Subscript.swift)

  • Adds slicing support for ClosedRange, Range, and all partial range flavors while preventing out-of-bounds traps.

Validation (String+Validation.swift)

  • Contains a broad validation toolkit: phone numbers, links, addresses, email, JSON, UUID, numeric checks, Luhn algorithm for bank cards, condensed whitespace, etc.

Example

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"])
⚠️ **GitHub.com Fallback** ⚠️