Skip to content

Commit 8cac6a8

Browse files
committed
Update README
1 parent 75bb588 commit 8cac6a8

File tree

1 file changed

+55
-36
lines changed

1 file changed

+55
-36
lines changed

README.md

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,87 @@
11
# InflectorKit
22
![CI][ci badge]
33

4-
**Efficiently Singularize and Pluralize Strings**
5-
6-
InflectorKit ports the string inflection functionality of [Rails ActiveSupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/inflections.rb) to Foundation.
4+
InflectorKit is a port of the string inflection functionality from
5+
[Rails ActiveSupport](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/inflections.rb) for Swift and Objective-C.
76

87
> InflectorKit joins [FormatterKit](https://github.com/mattt/FormatterKit) & [TransformerKit](https://github.com/mattt/TransformerKit) in providing well-designed APIs for manipulating user-facing content.
98
109
## Usage
1110

12-
```objective-c
13-
#import "NSString+InflectorKit.h"
14-
15-
for (NSString *singular in @[@"person", @"tomato", @"matrix", @"octopus", @"fish"]) {
16-
NSLog(@"%@: %@", singular, [singular pluralizedString]);
17-
}
18-
```
11+
### Swift
1912

2013
```swift
2114
import InflectorKit
2215

2316
for singular in ["person", "tomato", "matrix", "octopus", "fish"] {
24-
print(singular.pluralized)
17+
print("\(singular)\(singular.pluralized)")
2518
}
26-
```
19+
/*
20+
Prints:
21+
person → people
22+
tomato → tomatoes
23+
matrix → matrices
24+
octopus → octopi
25+
fish → fish
26+
*/
27+
28+
// You can also add pluralization rules,
29+
// including irregular and uncountable words:
2730

28-
person: people
29-
tomato: tomatoes
30-
matrix: matrices
31-
octopus: octopi
32-
fish: fish
31+
let inflector = StringInflector.default
32+
inflector.addPluralRule(#"^i(Pod|Pad)( Mini)?$"#, replacement: #"i$1s$2"#)
33+
inflector.addIrregular(singular: "lol", plural: "lolz")
34+
inflector.addUncountable("Herokai")
35+
36+
for singular in ["iPad Mini", "lol", "Herokai"] {
37+
print("\(singular)\(singular.pluralized)")
38+
}
39+
/*
40+
Prints:
41+
iPad Mini → iPads Mini
42+
lol → lolz
43+
Herokai → Herokai
44+
*/
45+
```
3346

34-
You can also add pluralization rules, including irregular and uncountable words:
47+
### Objective-C
3548

3649
```objective-c
37-
#import "TTTStringInflector.h"
50+
#import "NSString+InflectorKit.h"
51+
52+
for (NSString *singular in @[@"person", @"tomato", @"matrix", @"octopus", @"fish"]) {
53+
NSLog(@"%@ → %@", singular, [singular pluralizedString]);
54+
}
55+
56+
/*
57+
Prints:
58+
person → people
59+
tomato → tomatoes
60+
matrix → matrices
61+
octopus → octopi
62+
fish → fish
63+
*/
64+
65+
// You can also add pluralization rules,
66+
// including irregular and uncountable words:
3867

3968
TTTStringInflector *inflector = [TTTStringInflector defaultInflector];
4069
[inflector addPluralRule:@"^i(Pod|Pad)( Mini)?$" withReplacement:@"i$1s$2"];
4170
[inflector addIrregularWithSingular:@"lol" plural:@"lolz"];
4271
[inflector addUncountable:@"Herokai"];
4372

4473
for (NSString *singular in @[@"iPad Mini", @"lol", @"Herokai"]) {
45-
NSLog(@"%@: %@", singular, [singular pluralizedString]);
74+
NSLog(@"%@ %@", singular, [singular pluralizedString]);
4675
}
47-
```
48-
49-
```swift
50-
import InflectorKit
5176

52-
let inflector = StringInflector.default
53-
inflector.addPluralRule(#"^i(Pod|Pad)( Mini)?$"#, replacement: #"i$1s$2"#)
54-
inflector.addIrregular(singular: "lol", plural: "lolz")
55-
inflector.addUncountable("Herokai")
56-
57-
for singular in ["iPad Mini", "lol", "Herokai"] {
58-
print(singular.pluralized)
59-
}
77+
/*
78+
Prints:
79+
iPad Mini → iPads Mini
80+
lol → lolz
81+
Herokai → Herokai
82+
*/
6083
```
6184
62-
iPad Mini: iPads Mini
63-
lol: lolz
64-
Herokai: Herokai
65-
6685
## License
6786
6887
MIT

0 commit comments

Comments
 (0)