Fix titleization handling of colons (#3) Fix titleization handling of colons Update README Add changelog entry for #3
Fix titleization handling of colons (#3)
Fix titleization handling of colons
Update README
Add changelog entry for #3
A Swift port of the string inflection functionality from Rails ActiveSupport, with localizations for the following locales adapted from Inflections by @davidcelis:
az
en
es
fr
it
kk
la
nb
pt-BR
se
tr
import Inflection // Rails-style inflectors "employee_salary".camelized() // "employeeSalary" "employee_salary".camelized(uppercasingFirstLetter: true) // "EmployeeSalary" "employee_salary".dasherized() // "employee-salary" "customer_support".humanized() // "Customer Support" "parent_id".humanized() // "Parent" "Donald E. Knuth".parameterized() // "donald-e-knuth" "^très|Jolie-- ".parameterized() // "tres-jolie" "TheIncredibleHulk".titleized() // "The Incredible Hulk" "spider-man: far from home".titleized() // "Spider Man: Far From Home" "guardians_of_the_galaxy".titleized() // "Guardians Of The Galaxy" "HTTPRequest".underscored() // "http_request" // Pluralization and singularization for singular in ["person", "tomato", "matrix", "octopus", "fish"] { let plural = singular.pluralized() print("\(singular) → \(plural) → \(plural.singularized())") } /* Prints: person → people → person tomato → tomatoes → tomato matrix → matrices → matrix octopus → octopi → octopus fish → fish → fish */ // Pass a `locale` argument to pluralize in other languages: let 🇮🇹 = Locale(identifier: "it-IT") let singular = "ragno" // 🕷 let plural = singular.pluralized(with: 🇮🇹) // 🕷🕷🕷 print("\(singular) → \(plural) → \(plural.singularized())") /* Prints: ragno → ragni → ragno */ // You can also add pluralization rules, // including irregular and uncountable words: let inflector = Inflector.default inflector.addPluralRule(#"^i(Pod|Pad)( Mini)?quot;#, replacement: #"i$1s$2"#) inflector.addIrregular(singular: "lol", plural: "lolz") inflector.addUncountable("Herokai") for singular in ["iPad Mini", "lol", "Herokai"] { print("\(singular) → \(singular.pluralized)") } /* Prints: iPad Mini → iPads Mini lol → lolz Herokai → Herokai */
Add the Inflection package to your target dependencies in Package.swift:
Package.swift
// swift-tools-version:5.3 import PackageDescription let package = Package( name: "YourProject", dependencies: [ .package( url: "https://github.com/SwiftDoc/Inflection", from: "0.0.1" ), ] )
Then run the swift build command to build your project.
swift build
MIT
Mattt (@mattt)
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
Inflection
A Swift port of the string inflection functionality from Rails ActiveSupport, with localizations for the following locales adapted from Inflections by @davidcelis:
az
)en
)es
)fr
)it
)kk
)la
)nb
)pt-BR
)se
)tr
)Requirements
Usage
Installation
Swift Package Manager
Add the Inflection package to your target dependencies in
Package.swift
:Then run the
swift build
command to build your project.License
MIT
Contact
Mattt (@mattt)