@mythpe/quasar-ui-qui 0.1.93 → 0.1.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils/Str.ts +3 -3
- package/src/utils/__pluralize.js +503 -0
- package/src/utils/copy_pluralize.js +0 -241
package/package.json
CHANGED
package/src/utils/Str.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Github: https://github.com/mythpe
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import __pluralize from './__pluralize'
|
|
10
10
|
import { camelCase, capitalCase, dotCase, kebabCase, pascalCase, snakeCase } from 'change-case'
|
|
11
11
|
|
|
12
12
|
export const Str = {
|
|
@@ -92,10 +92,10 @@ export const Str = {
|
|
|
92
92
|
return string ? dotCase(string?.toString() || '') : ''
|
|
93
93
|
},
|
|
94
94
|
pluralize (string?: unknown): string {
|
|
95
|
-
return string ? plural(string?.toString() || '') : ''
|
|
95
|
+
return string ? __pluralize.plural(string?.toString() || '') : ''
|
|
96
96
|
},
|
|
97
97
|
singular (string?: unknown): string {
|
|
98
|
-
return string ? singular(string?.toString() || '') : ''
|
|
98
|
+
return string ? __pluralize.singular(string?.toString() || '') : ''
|
|
99
99
|
},
|
|
100
100
|
flipChoice (data: Record<any, any>) {
|
|
101
101
|
const f: Record<any, any> = {}
|
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
/* global define */
|
|
2
|
+
|
|
3
|
+
(function (root, pluralize) {
|
|
4
|
+
/* istanbul ignore else */
|
|
5
|
+
if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
|
|
6
|
+
// Node.
|
|
7
|
+
module.exports = pluralize();
|
|
8
|
+
} else if (typeof define === 'function' && define.amd) {
|
|
9
|
+
// AMD, registers as an anonymous module.
|
|
10
|
+
define(function () {
|
|
11
|
+
return pluralize();
|
|
12
|
+
});
|
|
13
|
+
} else {
|
|
14
|
+
// Browser global.
|
|
15
|
+
root.pluralize = pluralize();
|
|
16
|
+
}
|
|
17
|
+
})(this, function () {
|
|
18
|
+
// Rule storage - pluralize and singularize need to be run sequentially,
|
|
19
|
+
// while other rules can be optimized using an object for instant lookups.
|
|
20
|
+
var pluralRules = [];
|
|
21
|
+
var singularRules = [];
|
|
22
|
+
var uncountables = {};
|
|
23
|
+
var irregularPlurals = {};
|
|
24
|
+
var irregularSingles = {};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Sanitize a pluralization rule to a usable regular expression.
|
|
28
|
+
*
|
|
29
|
+
* @param {(RegExp|string)} rule
|
|
30
|
+
* @return {RegExp}
|
|
31
|
+
*/
|
|
32
|
+
function sanitizeRule (rule) {
|
|
33
|
+
if (typeof rule === 'string') {
|
|
34
|
+
return new RegExp('^' + rule + '$', 'i');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return rule;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Pass in a word token to produce a function that can replicate the case on
|
|
42
|
+
* another word.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} word
|
|
45
|
+
* @param {string} token
|
|
46
|
+
* @return {Function}
|
|
47
|
+
*/
|
|
48
|
+
function restoreCase (word, token) {
|
|
49
|
+
// Tokens are an exact match.
|
|
50
|
+
if (word === token) return token;
|
|
51
|
+
|
|
52
|
+
// Lower cased words. E.g. "hello".
|
|
53
|
+
if (word === word.toLowerCase()) return token.toLowerCase();
|
|
54
|
+
|
|
55
|
+
// Upper cased words. E.g. "WHISKY".
|
|
56
|
+
if (word === word.toUpperCase()) return token.toUpperCase();
|
|
57
|
+
|
|
58
|
+
// Title cased words. E.g. "Title".
|
|
59
|
+
if (word[0] === word[0].toUpperCase()) {
|
|
60
|
+
return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Lower cased words. E.g. "test".
|
|
64
|
+
return token.toLowerCase();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Interpolate a regexp string.
|
|
69
|
+
*
|
|
70
|
+
* @param {string} str
|
|
71
|
+
* @param {Array} args
|
|
72
|
+
* @return {string}
|
|
73
|
+
*/
|
|
74
|
+
function interpolate (str, args) {
|
|
75
|
+
return str.replace(/\$(\d{1,2})/g, function (match, index) {
|
|
76
|
+
return args[index] || '';
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Replace a word using a rule.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} word
|
|
84
|
+
* @param {Array} rule
|
|
85
|
+
* @return {string}
|
|
86
|
+
*/
|
|
87
|
+
function replace (word, rule) {
|
|
88
|
+
return word.replace(rule[0], function (match, index) {
|
|
89
|
+
var result = interpolate(rule[1], arguments);
|
|
90
|
+
|
|
91
|
+
if (match === '') {
|
|
92
|
+
return restoreCase(word[index - 1], result);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return restoreCase(match, result);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Sanitize a word by passing in the word and sanitization rules.
|
|
101
|
+
*
|
|
102
|
+
* @param {string} token
|
|
103
|
+
* @param {string} word
|
|
104
|
+
* @param {Array} rules
|
|
105
|
+
* @return {string}
|
|
106
|
+
*/
|
|
107
|
+
function sanitizeWord (token, word, rules) {
|
|
108
|
+
// Empty string or doesn't need fixing.
|
|
109
|
+
if (!token.length || uncountables.hasOwnProperty(token)) {
|
|
110
|
+
return word;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
var len = rules.length;
|
|
114
|
+
|
|
115
|
+
// Iterate over the sanitization rules and use the first one to match.
|
|
116
|
+
while (len--) {
|
|
117
|
+
var rule = rules[len];
|
|
118
|
+
|
|
119
|
+
if (rule[0].test(word)) return replace(word, rule);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return word;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Replace a word with the updated word.
|
|
127
|
+
*
|
|
128
|
+
* @param {Object} replaceMap
|
|
129
|
+
* @param {Object} keepMap
|
|
130
|
+
* @param {Array} rules
|
|
131
|
+
* @return {Function}
|
|
132
|
+
*/
|
|
133
|
+
function replaceWord (replaceMap, keepMap, rules) {
|
|
134
|
+
return function (word) {
|
|
135
|
+
// Get the correct token and case restoration functions.
|
|
136
|
+
var token = word.toLowerCase();
|
|
137
|
+
|
|
138
|
+
// Check against the keep object map.
|
|
139
|
+
if (keepMap.hasOwnProperty(token)) {
|
|
140
|
+
return restoreCase(word, token);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Check against the replacement map for a direct word replacement.
|
|
144
|
+
if (replaceMap.hasOwnProperty(token)) {
|
|
145
|
+
return restoreCase(word, replaceMap[token]);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Run all the rules against the word.
|
|
149
|
+
return sanitizeWord(token, word, rules);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Check if a word is part of the map.
|
|
155
|
+
*/
|
|
156
|
+
function checkWord (replaceMap, keepMap, rules, bool) {
|
|
157
|
+
return function (word) {
|
|
158
|
+
var token = word.toLowerCase();
|
|
159
|
+
|
|
160
|
+
if (keepMap.hasOwnProperty(token)) return true;
|
|
161
|
+
if (replaceMap.hasOwnProperty(token)) return false;
|
|
162
|
+
|
|
163
|
+
return sanitizeWord(token, token, rules) === token;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Pluralize or singularize a word based on the passed in count.
|
|
169
|
+
*
|
|
170
|
+
* @param {string} word The word to pluralize
|
|
171
|
+
* @param {number} count How many of the word exist
|
|
172
|
+
* @param {boolean} inclusive Whether to prefix with the number (e.g. 3 ducks)
|
|
173
|
+
* @return {string}
|
|
174
|
+
*/
|
|
175
|
+
function pluralize (word, count, inclusive) {
|
|
176
|
+
var pluralized = count === 1
|
|
177
|
+
? pluralize.singular(word) : pluralize.plural(word);
|
|
178
|
+
|
|
179
|
+
return (inclusive ? count + ' ' : '') + pluralized;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Pluralize a word.
|
|
184
|
+
*
|
|
185
|
+
* @type {Function}
|
|
186
|
+
*/
|
|
187
|
+
pluralize.plural = replaceWord(
|
|
188
|
+
irregularSingles, irregularPlurals, pluralRules
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Check if a word is plural.
|
|
193
|
+
*
|
|
194
|
+
* @type {Function}
|
|
195
|
+
*/
|
|
196
|
+
pluralize.isPlural = checkWord(
|
|
197
|
+
irregularSingles, irregularPlurals, pluralRules
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Singularize a word.
|
|
202
|
+
*
|
|
203
|
+
* @type {Function}
|
|
204
|
+
*/
|
|
205
|
+
pluralize.singular = replaceWord(
|
|
206
|
+
irregularPlurals, irregularSingles, singularRules
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Check if a word is singular.
|
|
211
|
+
*
|
|
212
|
+
* @type {Function}
|
|
213
|
+
*/
|
|
214
|
+
pluralize.isSingular = checkWord(
|
|
215
|
+
irregularPlurals, irregularSingles, singularRules
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Add a pluralization rule to the collection.
|
|
220
|
+
*
|
|
221
|
+
* @param {(string|RegExp)} rule
|
|
222
|
+
* @param {string} replacement
|
|
223
|
+
*/
|
|
224
|
+
pluralize.addPluralRule = function (rule, replacement) {
|
|
225
|
+
pluralRules.push([sanitizeRule(rule), replacement]);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Add a singularization rule to the collection.
|
|
230
|
+
*
|
|
231
|
+
* @param {(string|RegExp)} rule
|
|
232
|
+
* @param {string} replacement
|
|
233
|
+
*/
|
|
234
|
+
pluralize.addSingularRule = function (rule, replacement) {
|
|
235
|
+
singularRules.push([sanitizeRule(rule), replacement]);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Add an uncountable word rule.
|
|
240
|
+
*
|
|
241
|
+
* @param {(string|RegExp)} word
|
|
242
|
+
*/
|
|
243
|
+
pluralize.addUncountableRule = function (word) {
|
|
244
|
+
if (typeof word === 'string') {
|
|
245
|
+
uncountables[word.toLowerCase()] = true;
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Set singular and plural references for the word.
|
|
250
|
+
pluralize.addPluralRule(word, '$0');
|
|
251
|
+
pluralize.addSingularRule(word, '$0');
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Add an irregular word definition.
|
|
256
|
+
*
|
|
257
|
+
* @param {string} single
|
|
258
|
+
* @param {string} plural
|
|
259
|
+
*/
|
|
260
|
+
pluralize.addIrregularRule = function (single, plural) {
|
|
261
|
+
plural = plural.toLowerCase();
|
|
262
|
+
single = single.toLowerCase();
|
|
263
|
+
|
|
264
|
+
irregularSingles[single] = plural;
|
|
265
|
+
irregularPlurals[plural] = single;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Irregular rules.
|
|
270
|
+
*/
|
|
271
|
+
[
|
|
272
|
+
// Pronouns.
|
|
273
|
+
['I', 'we'],
|
|
274
|
+
['me', 'us'],
|
|
275
|
+
['he', 'they'],
|
|
276
|
+
['she', 'they'],
|
|
277
|
+
['them', 'them'],
|
|
278
|
+
['myself', 'ourselves'],
|
|
279
|
+
['yourself', 'yourselves'],
|
|
280
|
+
['itself', 'themselves'],
|
|
281
|
+
['herself', 'themselves'],
|
|
282
|
+
['himself', 'themselves'],
|
|
283
|
+
['themself', 'themselves'],
|
|
284
|
+
['is', 'are'],
|
|
285
|
+
['was', 'were'],
|
|
286
|
+
['has', 'have'],
|
|
287
|
+
['this', 'these'],
|
|
288
|
+
['that', 'those'],
|
|
289
|
+
// Words ending in with a consonant and `o`.
|
|
290
|
+
['echo', 'echoes'],
|
|
291
|
+
['dingo', 'dingoes'],
|
|
292
|
+
['volcano', 'volcanoes'],
|
|
293
|
+
['tornado', 'tornadoes'],
|
|
294
|
+
['torpedo', 'torpedoes'],
|
|
295
|
+
// Ends with `us`.
|
|
296
|
+
['genus', 'genera'],
|
|
297
|
+
['viscus', 'viscera'],
|
|
298
|
+
// Ends with `ma`.
|
|
299
|
+
['stigma', 'stigmata'],
|
|
300
|
+
['stoma', 'stomata'],
|
|
301
|
+
['dogma', 'dogmata'],
|
|
302
|
+
['lemma', 'lemmata'],
|
|
303
|
+
['schema', 'schemata'],
|
|
304
|
+
['anathema', 'anathemata'],
|
|
305
|
+
// Other irregular rules.
|
|
306
|
+
['ox', 'oxen'],
|
|
307
|
+
['axe', 'axes'],
|
|
308
|
+
['die', 'dice'],
|
|
309
|
+
['yes', 'yeses'],
|
|
310
|
+
['foot', 'feet'],
|
|
311
|
+
['eave', 'eaves'],
|
|
312
|
+
['goose', 'geese'],
|
|
313
|
+
['tooth', 'teeth'],
|
|
314
|
+
['quiz', 'quizzes'],
|
|
315
|
+
['human', 'humans'],
|
|
316
|
+
['proof', 'proofs'],
|
|
317
|
+
['carve', 'carves'],
|
|
318
|
+
['valve', 'valves'],
|
|
319
|
+
['looey', 'looies'],
|
|
320
|
+
['thief', 'thieves'],
|
|
321
|
+
['groove', 'grooves'],
|
|
322
|
+
['pickaxe', 'pickaxes'],
|
|
323
|
+
['passerby', 'passersby']
|
|
324
|
+
].forEach(function (rule) {
|
|
325
|
+
return pluralize.addIrregularRule(rule[0], rule[1]);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Pluralization rules.
|
|
330
|
+
*/
|
|
331
|
+
[
|
|
332
|
+
[/s?$/i, 's'],
|
|
333
|
+
[/[^\u0000-\u007F]$/i, '$0'],
|
|
334
|
+
[/([^aeiou]ese)$/i, '$1'],
|
|
335
|
+
[/(ax|test)is$/i, '$1es'],
|
|
336
|
+
[/(alias|[^aou]us|t[lm]as|gas|ris)$/i, '$1es'],
|
|
337
|
+
[/(e[mn]u)s?$/i, '$1s'],
|
|
338
|
+
[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, '$1'],
|
|
339
|
+
[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1i'],
|
|
340
|
+
[/(alumn|alg|vertebr)(?:a|ae)$/i, '$1ae'],
|
|
341
|
+
[/(seraph|cherub)(?:im)?$/i, '$1im'],
|
|
342
|
+
[/(her|at|gr)o$/i, '$1oes'],
|
|
343
|
+
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, '$1a'],
|
|
344
|
+
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, '$1a'],
|
|
345
|
+
[/sis$/i, 'ses'],
|
|
346
|
+
[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, '$1$2ves'],
|
|
347
|
+
[/([^aeiouy]|qu)y$/i, '$1ies'],
|
|
348
|
+
[/([^ch][ieo][ln])ey$/i, '$1ies'],
|
|
349
|
+
[/(x|ch|ss|sh|zz)$/i, '$1es'],
|
|
350
|
+
[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, '$1ices'],
|
|
351
|
+
[/\b((?:tit)?m|l)(?:ice|ouse)$/i, '$1ice'],
|
|
352
|
+
[/(pe)(?:rson|ople)$/i, '$1ople'],
|
|
353
|
+
[/(child)(?:ren)?$/i, '$1ren'],
|
|
354
|
+
[/eaux$/i, '$0'],
|
|
355
|
+
[/m[ae]n$/i, 'men'],
|
|
356
|
+
['thou', 'you']
|
|
357
|
+
].forEach(function (rule) {
|
|
358
|
+
return pluralize.addPluralRule(rule[0], rule[1]);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Singularization rules.
|
|
363
|
+
*/
|
|
364
|
+
[
|
|
365
|
+
[/s$/i, ''],
|
|
366
|
+
[/(ss)$/i, '$1'],
|
|
367
|
+
[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, '$1fe'],
|
|
368
|
+
[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, '$1f'],
|
|
369
|
+
[/ies$/i, 'y'],
|
|
370
|
+
[/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, '$1ie'],
|
|
371
|
+
[/\b(mon|smil)ies$/i, '$1ey'],
|
|
372
|
+
[/\b((?:tit)?m|l)ice$/i, '$1ouse'],
|
|
373
|
+
[/(seraph|cherub)im$/i, '$1'],
|
|
374
|
+
[/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, '$1'],
|
|
375
|
+
[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, '$1sis'],
|
|
376
|
+
[/(movie|twelve|abuse|e[mn]u)s$/i, '$1'],
|
|
377
|
+
[/(test)(?:is|es)$/i, '$1is'],
|
|
378
|
+
[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1us'],
|
|
379
|
+
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, '$1um'],
|
|
380
|
+
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, '$1on'],
|
|
381
|
+
[/(alumn|alg|vertebr)ae$/i, '$1a'],
|
|
382
|
+
[/(cod|mur|sil|vert|ind)ices$/i, '$1ex'],
|
|
383
|
+
[/(matr|append)ices$/i, '$1ix'],
|
|
384
|
+
[/(pe)(rson|ople)$/i, '$1rson'],
|
|
385
|
+
[/(child)ren$/i, '$1'],
|
|
386
|
+
[/(eau)x?$/i, '$1'],
|
|
387
|
+
[/men$/i, 'man']
|
|
388
|
+
].forEach(function (rule) {
|
|
389
|
+
return pluralize.addSingularRule(rule[0], rule[1]);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Uncountable rules.
|
|
394
|
+
*/
|
|
395
|
+
[
|
|
396
|
+
// Singular words with no plurals.
|
|
397
|
+
'adulthood',
|
|
398
|
+
'advice',
|
|
399
|
+
'agenda',
|
|
400
|
+
'aid',
|
|
401
|
+
'aircraft',
|
|
402
|
+
'alcohol',
|
|
403
|
+
'ammo',
|
|
404
|
+
'analytics',
|
|
405
|
+
'anime',
|
|
406
|
+
'athletics',
|
|
407
|
+
'audio',
|
|
408
|
+
'bison',
|
|
409
|
+
'blood',
|
|
410
|
+
'bream',
|
|
411
|
+
'buffalo',
|
|
412
|
+
'butter',
|
|
413
|
+
'carp',
|
|
414
|
+
'cash',
|
|
415
|
+
'chassis',
|
|
416
|
+
'chess',
|
|
417
|
+
'clothing',
|
|
418
|
+
'cod',
|
|
419
|
+
'commerce',
|
|
420
|
+
'cooperation',
|
|
421
|
+
'corps',
|
|
422
|
+
'debris',
|
|
423
|
+
'diabetes',
|
|
424
|
+
'digestion',
|
|
425
|
+
'elk',
|
|
426
|
+
'energy',
|
|
427
|
+
'equipment',
|
|
428
|
+
'excretion',
|
|
429
|
+
'expertise',
|
|
430
|
+
'firmware',
|
|
431
|
+
'flounder',
|
|
432
|
+
'fun',
|
|
433
|
+
'gallows',
|
|
434
|
+
'garbage',
|
|
435
|
+
'graffiti',
|
|
436
|
+
'hardware',
|
|
437
|
+
'headquarters',
|
|
438
|
+
'health',
|
|
439
|
+
'herpes',
|
|
440
|
+
'highjinks',
|
|
441
|
+
'homework',
|
|
442
|
+
'housework',
|
|
443
|
+
'information',
|
|
444
|
+
'jeans',
|
|
445
|
+
'justice',
|
|
446
|
+
'kudos',
|
|
447
|
+
'labour',
|
|
448
|
+
'literature',
|
|
449
|
+
'machinery',
|
|
450
|
+
'mackerel',
|
|
451
|
+
'mail',
|
|
452
|
+
'media',
|
|
453
|
+
'mews',
|
|
454
|
+
'moose',
|
|
455
|
+
'music',
|
|
456
|
+
'mud',
|
|
457
|
+
'manga',
|
|
458
|
+
'news',
|
|
459
|
+
'only',
|
|
460
|
+
'personnel',
|
|
461
|
+
'pike',
|
|
462
|
+
'plankton',
|
|
463
|
+
'pliers',
|
|
464
|
+
'police',
|
|
465
|
+
'pollution',
|
|
466
|
+
'premises',
|
|
467
|
+
'rain',
|
|
468
|
+
'research',
|
|
469
|
+
'rice',
|
|
470
|
+
'salmon',
|
|
471
|
+
'scissors',
|
|
472
|
+
'series',
|
|
473
|
+
'sewage',
|
|
474
|
+
'shambles',
|
|
475
|
+
'shrimp',
|
|
476
|
+
'software',
|
|
477
|
+
'species',
|
|
478
|
+
'staff',
|
|
479
|
+
'swine',
|
|
480
|
+
'tennis',
|
|
481
|
+
'traffic',
|
|
482
|
+
'transportation',
|
|
483
|
+
'trout',
|
|
484
|
+
'tuna',
|
|
485
|
+
'wealth',
|
|
486
|
+
'welfare',
|
|
487
|
+
'whiting',
|
|
488
|
+
'wildebeest',
|
|
489
|
+
'wildlife',
|
|
490
|
+
'you',
|
|
491
|
+
/pok[eé]mon$/i,
|
|
492
|
+
// Regexes.
|
|
493
|
+
/[^aeiou]ese$/i, // "chinese", "japanese"
|
|
494
|
+
/deer$/i, // "deer", "reindeer"
|
|
495
|
+
/fish$/i, // "fish", "blowfish", "angelfish"
|
|
496
|
+
/measles$/i,
|
|
497
|
+
/o[iu]s$/i, // "carnivorous"
|
|
498
|
+
/pox$/i, // "chickpox", "smallpox"
|
|
499
|
+
/sheep$/i
|
|
500
|
+
].forEach(pluralize.addUncountableRule);
|
|
501
|
+
|
|
502
|
+
return pluralize;
|
|
503
|
+
});
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
|
|
6
|
-
// __pluralize.js
|
|
7
|
-
|
|
8
|
-
// Rule storage - __pluralize and singularize need to be run sequentially,
|
|
9
|
-
// while other rules can be optimized using an object for instant lookups.
|
|
10
|
-
const pluralRules = []
|
|
11
|
-
const singularRules = []
|
|
12
|
-
const uncountables = {}
|
|
13
|
-
const irregularPlurals = {}
|
|
14
|
-
const irregularSingles = {}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Sanitize a pluralization rule to a usable regular expression.
|
|
18
|
-
* @param {(RegExp|string)} rule
|
|
19
|
-
* @return {RegExp}
|
|
20
|
-
*/
|
|
21
|
-
function sanitizeRule (rule) {
|
|
22
|
-
return typeof rule === 'string' ? new RegExp(`^${rule}$`, 'i') : rule
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Pass in a word token to produce a function that can replicate the case on another word.
|
|
27
|
-
* @param {string} word
|
|
28
|
-
* @param {string} token
|
|
29
|
-
* @return {string}
|
|
30
|
-
*/
|
|
31
|
-
function restoreCase (word, token) {
|
|
32
|
-
if (word === token) return token
|
|
33
|
-
if (word === word.toLowerCase()) return token.toLowerCase()
|
|
34
|
-
if (word === word.toUpperCase()) return token.toUpperCase()
|
|
35
|
-
if (word[0] === word[0].toUpperCase()) {
|
|
36
|
-
return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase()
|
|
37
|
-
}
|
|
38
|
-
return token.toLowerCase()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Interpolate a regexp string.
|
|
43
|
-
* @param {string} str
|
|
44
|
-
* @param {Array} args
|
|
45
|
-
* @return {string}
|
|
46
|
-
*/
|
|
47
|
-
function interpolate (str, args) {
|
|
48
|
-
return str.replace(/\$(\d{1,2})/g, (match, index) => args[index] || '')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Replace a word using a rule.
|
|
53
|
-
* @param {string} word
|
|
54
|
-
* @param {Array} rule
|
|
55
|
-
* @return {string}
|
|
56
|
-
*/
|
|
57
|
-
function replace (word, rule) {
|
|
58
|
-
return word.replace(rule[0], (match, ...args) => {
|
|
59
|
-
const result = interpolate(rule[1], args)
|
|
60
|
-
return match === '' ? restoreCase(word[args[args.length - 2] - 1], result) : restoreCase(match, result)
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Sanitize a word by passing in the word and sanitization rules.
|
|
66
|
-
* @param {string} token
|
|
67
|
-
* @param {string} word
|
|
68
|
-
* @param {Array} rules
|
|
69
|
-
* @return {string}
|
|
70
|
-
*/
|
|
71
|
-
function sanitizeWord (token, word, rules) {
|
|
72
|
-
if (!token.length || uncountables.hasOwnProperty(token)) return word
|
|
73
|
-
|
|
74
|
-
for (let i = rules.length - 1; i >= 0; i--) {
|
|
75
|
-
const rule = rules[i]
|
|
76
|
-
if (rule[0].test(word)) return replace(word, rule)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return word
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Replace a word with the updated word.
|
|
84
|
-
* @param {Object} replaceMap
|
|
85
|
-
* @param {Object} keepMap
|
|
86
|
-
* @param {Array} rules
|
|
87
|
-
* @return {Function}
|
|
88
|
-
*/
|
|
89
|
-
function replaceWord (replaceMap, keepMap, rules) {
|
|
90
|
-
return function (word) {
|
|
91
|
-
const token = word.toLowerCase()
|
|
92
|
-
|
|
93
|
-
if (keepMap.hasOwnProperty(token)) return restoreCase(word, token)
|
|
94
|
-
if (replaceMap.hasOwnProperty(token)) return restoreCase(word, replaceMap[token])
|
|
95
|
-
|
|
96
|
-
return sanitizeWord(token, word, rules)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Check if a word is part of the map.
|
|
102
|
-
*/
|
|
103
|
-
function checkWord (replaceMap, keepMap, rules) {
|
|
104
|
-
return function (word) {
|
|
105
|
-
const token = word.toLowerCase()
|
|
106
|
-
if (keepMap.hasOwnProperty(token)) return true
|
|
107
|
-
if (replaceMap.hasOwnProperty(token)) return false
|
|
108
|
-
return sanitizeWord(token, token, rules) === token
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Pluralize or singularize a word based on the passed in count.
|
|
114
|
-
* @param {string} word The word to __pluralize
|
|
115
|
-
* @param {number} count How many of the word exist
|
|
116
|
-
* @param {boolean} inclusive Whether to prefix with the number (e.g. 3 ducks)
|
|
117
|
-
* @return {string}
|
|
118
|
-
*/
|
|
119
|
-
function __pluralize (word, count, inclusive) {
|
|
120
|
-
const pluralized = count === 1 ? __pluralize.singular(word) : __pluralize.plural(word)
|
|
121
|
-
return (inclusive ? `${count} ` : '') + pluralized
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Attach methods to __pluralize function
|
|
125
|
-
__pluralize.plural = replaceWord(irregularSingles, irregularPlurals, pluralRules)
|
|
126
|
-
__pluralize.isPlural = checkWord(irregularSingles, irregularPlurals, pluralRules)
|
|
127
|
-
__pluralize.singular = replaceWord(irregularPlurals, irregularSingles, singularRules)
|
|
128
|
-
__pluralize.isSingular = checkWord(irregularPlurals, irregularSingles, singularRules)
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Add a pluralization rule to the collection.
|
|
132
|
-
* @param {(string|RegExp)} rule
|
|
133
|
-
* @param {string} replacement
|
|
134
|
-
*/
|
|
135
|
-
__pluralize.addPluralRule = function (rule, replacement) {
|
|
136
|
-
pluralRules.push([sanitizeRule(rule), replacement])
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Add a singularization rule to the collection.
|
|
141
|
-
* @param {(string|RegExp)} rule
|
|
142
|
-
* @param {string} replacement
|
|
143
|
-
*/
|
|
144
|
-
__pluralize.addSingularRule = function (rule, replacement) {
|
|
145
|
-
singularRules.push([sanitizeRule(rule), replacement])
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Add an uncountable word rule.
|
|
150
|
-
* @param {(string|RegExp)} word
|
|
151
|
-
*/
|
|
152
|
-
__pluralize.addUncountableRule = function (word) {
|
|
153
|
-
if (typeof word === 'string') {
|
|
154
|
-
uncountables[word.toLowerCase()] = true
|
|
155
|
-
return
|
|
156
|
-
}
|
|
157
|
-
__pluralize.addPluralRule(word, '$0')
|
|
158
|
-
__pluralize.addSingularRule(word, '$0')
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Add an irregular word definition.
|
|
163
|
-
* @param {string} single
|
|
164
|
-
* @param {string} plural
|
|
165
|
-
*/
|
|
166
|
-
__pluralize.addIrregularRule = function (single, plural) {
|
|
167
|
-
const pluralLower = plural.toLowerCase()
|
|
168
|
-
const singleLower = single.toLowerCase()
|
|
169
|
-
irregularSingles[singleLower] = pluralLower
|
|
170
|
-
irregularPlurals[pluralLower] = singleLower
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
// Irregular rules
|
|
174
|
-
[
|
|
175
|
-
['I', 'we'], ['me', 'us'], ['he', 'they'], ['she', 'they'], ['them', 'them'],
|
|
176
|
-
['myself', 'ourselves'], ['yourself', 'yourselves'], ['itself', 'themselves'],
|
|
177
|
-
['herself', 'themselves'], ['himself', 'themselves'], ['themself', 'themselves'],
|
|
178
|
-
['is', 'are'], ['was', 'were'], ['has', 'have'], ['this', 'these'], ['that', 'those'],
|
|
179
|
-
['echo', 'echoes'], ['dingo', 'dingoes'], ['volcano', 'volcanoes'], ['tornado', 'tornadoes'],
|
|
180
|
-
['torpedo', 'torpedoes'], ['genus', 'genera'], ['viscus', 'viscera'], ['stigma', 'stigmata'],
|
|
181
|
-
['stoma', 'stomata'], ['dogma', 'dogmata'], ['lemma', 'lemmata'], ['schema', 'schemata'],
|
|
182
|
-
['anathema', 'anathemata'], ['ox', 'oxen'], ['axe', 'axes'], ['die', 'dice'], ['yes', 'yeses'],
|
|
183
|
-
['foot', 'feet'], ['eave', 'eaves'], ['goose', 'geese'], ['tooth', 'teeth'], ['quiz', 'quizzes'],
|
|
184
|
-
['human', 'humans'], ['proof', 'proofs'], ['carve', 'carves'], ['valve', 'valves'],
|
|
185
|
-
['looey', 'looies'], ['thief', 'thieves'], ['groove', 'grooves'], ['pickaxe', 'pickaxes'],
|
|
186
|
-
['passerby', 'passersby']
|
|
187
|
-
].forEach(([single, plural]) => __pluralize.addIrregularRule(single, plural));
|
|
188
|
-
|
|
189
|
-
// Pluralization rules
|
|
190
|
-
[
|
|
191
|
-
[/s?$/i, 's'], [/[^\u0000-\u007F]$/i, '$0'], [/([^aeiou]ese)$/i, '$1'],
|
|
192
|
-
[/(ax|test)is$/i, '$1es'], [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, '$1es'],
|
|
193
|
-
[/(e[mn]u)s?$/i, '$1s'], [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, '$1'],
|
|
194
|
-
[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1i'],
|
|
195
|
-
[/(alumn|alg|vertebr)(?:a|ae)$/i, '$1ae'], [/(seraph|cherub)(?:im)?$/i, '$1im'],
|
|
196
|
-
[/(her|at|gr)o$/i, '$1oes'],
|
|
197
|
-
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, '$1a'],
|
|
198
|
-
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, '$1a'],
|
|
199
|
-
[/sis$/i, 'ses'], [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, '$1$2ves'],
|
|
200
|
-
[/([^aeiouy]|qu)y$/i, '$1ies'], [/([^ch][ieo][ln])ey$/i, '$1ies'],
|
|
201
|
-
[/(x|ch|ss|sh|zz)$/i, '$1es'], [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, '$1ices'],
|
|
202
|
-
[/\b((?:tit)?m|l)(?:ice|ouse)$/i, '$1ice'], [/(pe)(?:rson|ople)$/i, '$1ople'],
|
|
203
|
-
[/(child)(?:ren)?$/i, '$1ren'], [/eaux$/i, '$0'], [/m[ae]n$/i, 'men'], ['thou', 'you']
|
|
204
|
-
].forEach(([rule, replacement]) => __pluralize.addPluralRule(rule, replacement));
|
|
205
|
-
|
|
206
|
-
// Singularization rules
|
|
207
|
-
[
|
|
208
|
-
[/s$/i, ''], [/(ss)$/i, '$1'], [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, '$1fe'],
|
|
209
|
-
[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, '$1f'], [/ies$/i, 'y'],
|
|
210
|
-
[/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, '$1ie'],
|
|
211
|
-
[/\b(mon|smil)ies$/i, '$1ey'], [/\b((?:tit)?m|l)ice$/i, '$1ouse'],
|
|
212
|
-
[/(seraph|cherub)im$/i, '$1'], [/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, '$1'],
|
|
213
|
-
[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, '$1sis'],
|
|
214
|
-
[/(movie|twelve|abuse|e[mn]u)s$/i, '$1'], [/(test)(?:is|es)$/i, '$1is'],
|
|
215
|
-
[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1us'],
|
|
216
|
-
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, '$1um'],
|
|
217
|
-
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, '$1on'],
|
|
218
|
-
[/(alumn|alg|vertebr)ae$/i, '$1a'], [/(cod|mur|sil|vert|ind)ices$/i, '$1ex'],
|
|
219
|
-
[/(matr|append)ices$/i, '$1ix'], [/(pe)(rson|ople)$/i, '$1rson'], [/(child)ren$/i, '$1'],
|
|
220
|
-
[/(eau)x?$/i, '$1'], [/men$/i, 'man']
|
|
221
|
-
].forEach(([rule, replacement]) => __pluralize.addSingularRule(rule, replacement));
|
|
222
|
-
|
|
223
|
-
// Uncountable rules
|
|
224
|
-
[
|
|
225
|
-
'adulthood', 'advice', 'agenda', 'aid', 'aircraft', 'alcohol', 'ammo', 'analytics',
|
|
226
|
-
'anime', 'athletics', 'audio', 'bison', 'blood', 'bream', 'buffalo', 'butter',
|
|
227
|
-
'carp', 'cash', 'chassis', 'chess', 'clothing', 'cod', 'commerce', 'cooperation',
|
|
228
|
-
'corps', 'debris', 'diabetes', 'digestion', 'elk', 'energy', 'equipment',
|
|
229
|
-
'excretion', 'expertise', 'firmware', 'flounder', 'fun', 'gallows', 'garbage',
|
|
230
|
-
'graffiti', 'hardware', 'headquarters', 'health', 'herpes', 'highjinks', 'homework',
|
|
231
|
-
'housework', 'information', 'jeans', 'justice', 'kudos', 'labour', 'literature',
|
|
232
|
-
'machinery', 'mackerel', 'mail', 'media', 'mews', 'moose', 'music', 'mud', 'manga',
|
|
233
|
-
'news', 'only', 'personnel', 'pike', 'plankton', 'pliers', 'police', 'pollution',
|
|
234
|
-
'premises', 'rain', 'research', 'rice', 'salmon', 'scissors', 'series', 'sewage',
|
|
235
|
-
'shambles', 'shrimp', 'software', 'species', 'staff', 'swine', 'tennis', 'traffic',
|
|
236
|
-
'transportation', 'trout', 'tuna', 'wealth', 'welfare', 'whiting', 'wildebeest',
|
|
237
|
-
'wildlife', 'you', /pok[eé]mon$/i, /[^aeiou]ese$/i, /deer$/i, /fish$/i,
|
|
238
|
-
/measles$/i, /o[iu]s$/i, /pox$/i, /sheep$/i
|
|
239
|
-
].forEach(__pluralize.addUncountableRule)
|
|
240
|
-
|
|
241
|
-
export default __pluralize
|