InflectorKit 0.0.1

InflectorKit 0.0.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Mattt.


Downloads

Total337,557
Week0
Month0

Installs

Apps1,416
Pod Tries8
Test Targets149
Watch Apps5
powered by Segment

GitHub

Stars448
Watchers11
Forks24
Issues0
Contributors1
Pull Requests2

Code

Files4
LOCLines of Code 208


  • By
  • Mattt Thompson

Efficiently Singularize and Pluralize Strings

InflectorKit ports the string inflection functionality of Rails ActiveSupport to Foundation.

Usage

#import "NSString+InflectorKit.h"

for (NSString *singular in @[@"person", @"tomato", @"matrix", @"octopus", @"fish"]) {
  NSLog(@"%@: %@", singular, [singular pluralizedString]);
}
person: people
tomato: tomatoes
matrix: matrices
octopus: octopi
fish: fish

You can also add pluralization rules, including irregular and uncountable words:

#import "TTTStringInflector.h"

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]);
}
iPad Mini: iPads Mini
lol: lolz
Herokai: Herokai

Contact

Mattt Thompson

License

InflectorKit is available under the MIT license. See the LICENSE file for more info.