UNPKG

3.59 kBMarkdownView Raw
1# inflect
2
3customizable inflections for nodejs
4
5**NOTE: 0.3.2 was accidentally unpublished from the server and npm doesn't allow me to publish it back. Please upgrade to 0.3.3**
6
7## Installation
8
9```bash
10npm install i
11```
12
13## Usage
14
15Require the module before using
16
17```js
18var inflect = require('i')();
19```
20
21All the below api functions can be called directly on a string
22
23```js
24inflect.titleize('messages to store') // === 'Messages To Store'
25'messages to store'.titleize // === 'Messages To Store'
26```
27
28only if `true` is passed while initiating
29
30```js
31var inflect = require('i')(true);
32```
33
34### Pluralize
35
36```js
37inflect.pluralize('person'); // === 'people'
38inflect.pluralize('octopus'); // === 'octopi'
39inflect.pluralize('Hat'); // === 'Hats'
40```
41
42### Singularize
43
44```js
45inflect.singularize('people'); // === 'person'
46inflect.singularize('octopi'); // === 'octopus'
47inflect.singularize('Hats'); // === 'Hat'
48```
49
50### Camelize
51
52```js
53inflect.camelize('message_properties'); // === 'MessageProperties'
54inflect.camelize('message_properties', false); // === 'messageProperties'
55```
56
57### Underscore
58
59```js
60inflect.underscore('MessageProperties'); // === 'message_properties'
61inflect.underscore('messageProperties'); // === 'message_properties'
62```
63
64### Humanize
65
66```js
67inflect.humanize('message_id'); // === 'Message'
68```
69
70### Dasherize
71
72```js
73inflect.dasherize('message_properties'); // === 'message-properties'
74inflect.dasherize('Message Properties'); // === 'Message Properties'
75```
76
77### Titleize
78
79```js
80inflect.titleize('message_properties'); // === 'Message Properties'
81inflect.titleize('message properties to keep'); // === 'Message Properties to Keep'
82```
83
84### Demodulize
85
86```js
87inflect.demodulize('Message.Bus.Properties'); // === 'Properties'
88```
89
90### Tableize
91
92```js
93inflect.tableize('MessageBusProperty'); // === 'message_bus_properties'
94```
95
96### Classify
97
98```js
99inflect.classify('message_bus_properties'); // === 'MessageBusProperty'
100```
101
102### Foreign key
103
104```js
105inflect.foreign_key('MessageBusProperty'); // === 'message_bus_property_id'
106inflect.foreign_key('MessageBusProperty', false); // === 'message_bus_propertyid'
107```
108
109### Ordinalize
110
111```js
112inflect.ordinalize( '1' ); // === '1st'
113```
114
115## Custom rules for inflection
116
117### Custom plural
118
119We can use regexp in any of these custom rules
120
121```js
122inflect.inflections.plural('person', 'guys');
123inflect.pluralize('person'); // === 'guys'
124inflect.singularize('guys'); // === 'guy'
125```
126
127### Custom singular
128
129```js
130inflect.inflections.singular('guys', 'person')
131inflect.singularize('guys'); // === 'person'
132inflect.pluralize('person'); // === 'people'
133```
134
135### Custom irregular
136
137```js
138inflect.inflections.irregular('person', 'guys')
139inflect.pluralize('person'); // === 'guys'
140inflect.singularize('guys'); // === 'person'
141```
142
143### Custom human
144
145```js
146inflect.inflections.human(/^(.*)_cnt$/i, '$1_count');
147inflect.inflections.humanize('jargon_cnt'); // === 'Jargon count'
148```
149
150### Custom uncountable
151
152```js
153inflect.inflections.uncountable('oil')
154inflect.pluralize('oil'); // === 'oil'
155inflect.singularize('oil'); // === 'oil'
156```
157
158## Contributors
159Here is a list of [Contributors](http://github.com/pksunkara/inflect/contributors)
160
161### TODO
162
163- More obscure test cases
164
165__I accept pull requests and guarantee a reply back within a day__
166
167## License
168MIT/X11
169
170## Bug Reports
171Report [here](http://github.com/pksunkara/inflect/issues). __Guaranteed reply within a day__.
172
173## Contact
174Pavan Kumar Sunkara (pavan.sss1991@gmail.com)
175
176Follow me on [github](https://github.com/users/follow?target=pksunkara), [twitter](http://twitter.com/pksunkara)