InflectorKit
Efficiently Singularize and Pluralize Strings
Install / Use
/learn @mattt/InflectorKitREADME
InflectorKit
InflectorKit is a port of the string inflection functionality from Rails ActiveSupport for Swift and Objective-C.
InflectorKit joins FormatterKit & TransformerKit in providing well-designed APIs for manipulating user-facing content.
Usage
Swift
import InflectorKit
for singular in ["person", "tomato", "matrix", "octopus", "fish"] {
print("\(singular) → \(singular.pluralized)")
}
/*
Prints:
person → people
tomato → tomatoes
matrix → matrices
octopus → octopi
fish → fish
*/
// You can also add pluralization rules,
// including irregular and uncountable words:
let inflector = StringInflector.default
inflector.addPluralRule(#"^i(Pod|Pad)( Mini)?$"#, 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
*/
Objective-C
#import "NSString+InflectorKit.h"
for (NSString *singular in @[@"person", @"tomato", @"matrix", @"octopus", @"fish"]) {
NSLog(@"%@ → %@", singular, [singular pluralizedString]);
}
/*
Prints:
person → people
tomato → tomatoes
matrix → matrices
octopus → octopi
fish → fish
*/
// You can also add pluralization rules,
// including irregular and uncountable words:
TTTStringInflector *inflector = [TTTStringInflector defaultInflector];
[inflector addPluralRule:@"^i(Pod|Pad)( Mini)?$" withReplacement:@"i$1s$2"];
[inflector addIrregularWithSingular:@"lol" plural:@"lolz"];
[inflector addUncountable:@"Herokai"];
for (NSString *singular in @[@"iPad Mini", @"lol", @"Herokai"]) {
NSLog(@"%@ → %@", singular, [singular pluralizedString]);
}
/*
Prints:
iPad Mini → iPads Mini
lol → lolz
Herokai → Herokai
*/
Installation
Swift Package Manager
Add the InflectorKit package to your target dependencies in Package.swift:
import PackageDescription
let package = Package(
name: "YourProject",
dependencies: [
.package(
url: "https://github.com/mattt/InflectorKit",
from: "1.0.0"
),
]
)
Then run the swift build command to build your project.
CocoaPods
You can install InflectorKit via CocoaPods,
by adding the following line to your Podfile:
pod 'InflectorKit', '~> 1.0.0'
Run the pod install command to download the library
and integrate it into your Xcode project.
License
MIT
Contact
Mattt (@mattt)
Related Skills
node-connect
341.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
341.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.4kCommit, push, and open a PR
