1 | /*!
|
2 | * inflection
|
3 | * Copyright(c) 2011 Ben Lin <ben@dreamerslab.com>
|
4 | * MIT Licensed
|
5 | *
|
6 | * @fileoverview
|
7 | * A port of inflection-js to node.js module.
|
8 | */
|
9 | /**
|
10 | * This function adds pluralization support to every String object.
|
11 | * @param str The subject string.
|
12 | * @param plural Overrides normal output with said String.(optional)
|
13 | * @returns Singular English language nouns are returned in plural form.
|
14 | * @example
|
15 | *
|
16 | * const inflection = require( 'inflection' );
|
17 | *
|
18 | * inflection.pluralize( 'person' ); // === 'people'
|
19 | * inflection.pluralize( 'octopus' ); // === 'octopuses'
|
20 | * inflection.pluralize( 'Hat' ); // === 'Hats'
|
21 | * inflection.pluralize( 'person', 'guys' ); // === 'guys'
|
22 | */
|
23 | export declare function pluralize(str: string, plural?: string): string;
|
24 | /**
|
25 | * This function adds singularization support to every String object.
|
26 | * @param str The subject string.
|
27 | * @param singular Overrides normal output with said String.(optional)
|
28 | * @returns Plural English language nouns are returned in singular form.
|
29 | * @example
|
30 | *
|
31 | * const inflection = require( 'inflection' );
|
32 | *
|
33 | * inflection.singularize( 'people' ); // === 'person'
|
34 | * inflection.singularize( 'octopuses' ); // === 'octopus'
|
35 | * inflection.singularize( 'Hats' ); // === 'Hat'
|
36 | * inflection.singularize( 'guys', 'person' ); // === 'person'
|
37 | */
|
38 | export declare function singularize(str: string, singular?: string): string;
|
39 | /**
|
40 | * This function will pluralize or singularlize a String appropriately based on a number value
|
41 | * @param str The subject string.
|
42 | * @param count The number to base pluralization off of.
|
43 | * @param singular Overrides normal output with said String.(optional)
|
44 | * @param plural Overrides normal output with said String.(optional)
|
45 | * @returns English language nouns are returned in the plural or singular form based on the count.
|
46 | * @example
|
47 | *
|
48 | * const inflection = require( 'inflection' );
|
49 | *
|
50 | * inflection.inflect( 'people' 1 ); // === 'person'
|
51 | * inflection.inflect( 'octopuses' 1 ); // === 'octopus'
|
52 | * inflection.inflect( 'Hats' 1 ); // === 'Hat'
|
53 | * inflection.inflect( 'guys', 1 , 'person' ); // === 'person'
|
54 | * inflection.inflect( 'inches', 1.5 ); // === 'inches'
|
55 | * inflection.inflect( 'person', 2 ); // === 'people'
|
56 | * inflection.inflect( 'octopus', 2 ); // === 'octopuses'
|
57 | * inflection.inflect( 'Hat', 2 ); // === 'Hats'
|
58 | * inflection.inflect( 'person', 2, null, 'guys' ); // === 'guys'
|
59 | */
|
60 | export declare function inflect(str: string, count: number, singular?: string, plural?: string): string;
|
61 | /**
|
62 | * This function adds camelization support to every String object.
|
63 | * @param str The subject string.
|
64 | * @param lowFirstLetter Default is to capitalize the first letter of the results.(optional)
|
65 | * Passing true will lowercase it.
|
66 | * @returns Lower case underscored words will be returned in camel case.
|
67 | * additionally '/' is translated to '::'
|
68 | * @example
|
69 | *
|
70 | * const inflection = require( 'inflection' );
|
71 | *
|
72 | * inflection.camelize( 'message_properties' ); // === 'MessageProperties'
|
73 | * inflection.camelize( 'message_properties', true ); // === 'messageProperties'
|
74 | */
|
75 | export declare function camelize(str: string, lowFirstLetter?: boolean): string;
|
76 | /**
|
77 | * This function adds underscore support to every String object.
|
78 | * @param str The subject string.
|
79 | * @param allUpperCase Default is to lowercase and add underscore prefix.(optional)
|
80 | * Passing true will return as entered.
|
81 | * @returns Camel cased words are returned as lower cased and underscored.
|
82 | * additionally '::' is translated to '/'.
|
83 | * @example
|
84 | *
|
85 | * const inflection = require( 'inflection' );
|
86 | *
|
87 | * inflection.underscore( 'MessageProperties' ); // === 'message_properties'
|
88 | * inflection.underscore( 'messageProperties' ); // === 'message_properties'
|
89 | * inflection.underscore( 'MP', true ); // === 'MP'
|
90 | */
|
91 | export declare function underscore(str: string, allUpperCase?: boolean): string;
|
92 | /**
|
93 | * This function adds humanize support to every String object.
|
94 | * @param str The subject string.
|
95 | * @param lowFirstLetter Default is to capitalize the first letter of the results.(optional)
|
96 | * Passing true will lowercase it.
|
97 | * @returns Lower case underscored words will be returned in humanized form.
|
98 | * @example
|
99 | *
|
100 | * const inflection = require( 'inflection' );
|
101 | *
|
102 | * inflection.humanize( 'message_properties' ); // === 'Message properties'
|
103 | * inflection.humanize( 'message_properties', true ); // === 'message properties'
|
104 | */
|
105 | export declare function humanize(str: string, lowFirstLetter?: boolean): string;
|
106 | /**
|
107 | * This function adds capitalization support to every String object.
|
108 | * @param str The subject string.
|
109 | * @returns All characters will be lower case and the first will be upper.
|
110 | * @example
|
111 | *
|
112 | * const inflection = require( 'inflection' );
|
113 | *
|
114 | * inflection.capitalize( 'message_properties' ); // === 'Message_properties'
|
115 | * inflection.capitalize( 'message properties', true ); // === 'Message properties'
|
116 | */
|
117 | export declare function capitalize(str: string): string;
|
118 | /**
|
119 | * This function replaces underscores with dashes in the string.
|
120 | * @param str The subject string.
|
121 | * @returns Replaces all spaces or underscores with dashes.
|
122 | * @example
|
123 | *
|
124 | * const inflection = require( 'inflection' );
|
125 | *
|
126 | * inflection.dasherize( 'message_properties' ); // === 'message-properties'
|
127 | * inflection.dasherize( 'Message Properties' ); // === 'Message-Properties'
|
128 | */
|
129 | export declare function dasherize(str: string): string;
|
130 | /**
|
131 | * This function adds titleize support to every String object.
|
132 | * @param str The subject string.
|
133 | * @returns Capitalizes words as you would for a book title.
|
134 | * @example
|
135 | *
|
136 | * const inflection = require( 'inflection' );
|
137 | *
|
138 | * inflection.titleize( 'message_properties' ); // === 'Message Properties'
|
139 | * inflection.titleize( 'message properties to keep' ); // === 'Message Properties to Keep'
|
140 | */
|
141 | export declare function titleize(str: string): string;
|
142 | /**
|
143 | * This function adds demodulize support to every String object.
|
144 | * @param str The subject string.
|
145 | * @returns Removes module names leaving only class names.(Ruby style)
|
146 | * @example
|
147 | *
|
148 | * const inflection = require( 'inflection' );
|
149 | *
|
150 | * inflection.demodulize( 'Message::Bus::Properties' ); // === 'Properties'
|
151 | */
|
152 | export declare function demodulize(str: string): string;
|
153 | /**
|
154 | * This function adds tableize support to every String object.
|
155 | * @param str The subject string.
|
156 | * @returns Return camel cased words into their underscored plural form.
|
157 | * @example
|
158 | *
|
159 | * const inflection = require( 'inflection' );
|
160 | *
|
161 | * inflection.tableize( 'MessageBusProperty' ); // === 'message_bus_properties'
|
162 | */
|
163 | export declare function tableize(str: string): string;
|
164 | /**
|
165 | * This function adds classification support to every String object.
|
166 | * @param str The subject string.
|
167 | * @returns Underscored plural nouns become the camel cased singular form.
|
168 | * @example
|
169 | *
|
170 | * const inflection = require( 'inflection' );
|
171 | *
|
172 | * inflection.classify( 'message_bus_properties' ); // === 'MessageBusProperty'
|
173 | */
|
174 | export declare function classify(str: string): string;
|
175 | /**
|
176 | * This function adds foreign key support to every String object.
|
177 | * @param str The subject string.
|
178 | * @param dropIdUbar Default is to seperate id with an underbar at the end of the class name,
|
179 | you can pass true to skip it.(optional)
|
180 | * @returns Underscored plural nouns become the camel cased singular form.
|
181 | * @example
|
182 | *
|
183 | * const inflection = require( 'inflection' );
|
184 | *
|
185 | * inflection.foreign_key( 'MessageBusProperty' ); // === 'message_bus_property_id'
|
186 | * inflection.foreign_key( 'MessageBusProperty', true ); // === 'message_bus_propertyid'
|
187 | */
|
188 | export declare function foreignKey(str: string, dropIdUbar?: boolean): string;
|
189 | /**
|
190 | * This function adds ordinalize support to every String object.
|
191 | * @param str The subject string.
|
192 | * @returns Return all found numbers their sequence like '22nd'.
|
193 | * @example
|
194 | *
|
195 | * const inflection = require( 'inflection' );
|
196 | *
|
197 | * inflection.ordinalize( 'the 1 pitch' ); // === 'the 1st pitch'
|
198 | */
|
199 | export declare function ordinalize(str: string): string;
|
200 | declare const transformFunctions: {
|
201 | readonly pluralize: typeof pluralize;
|
202 | readonly singularize: typeof singularize;
|
203 | readonly camelize: typeof camelize;
|
204 | readonly underscore: typeof underscore;
|
205 | readonly humanize: typeof humanize;
|
206 | readonly capitalize: typeof capitalize;
|
207 | readonly dasherize: typeof dasherize;
|
208 | readonly titleize: typeof titleize;
|
209 | readonly demodulize: typeof demodulize;
|
210 | readonly tableize: typeof tableize;
|
211 | readonly classify: typeof classify;
|
212 | readonly foreignKey: typeof foreignKey;
|
213 | readonly ordinalize: typeof ordinalize;
|
214 | };
|
215 | /**
|
216 | * This function performs multiple inflection methods on a string
|
217 | * @param str The subject string.
|
218 | * @param arr An array of inflection methods.
|
219 | * @returns
|
220 | * @example
|
221 | *
|
222 | * const inflection = require( 'inflection' );
|
223 | *
|
224 | * inflection.transform( 'all job', [ 'pluralize', 'capitalize', 'dasherize' ]); // === 'All-jobs'
|
225 | */
|
226 | export declare function transform(str: string, arr: (keyof typeof transformFunctions)[]): string;
|
227 | export {};
|