@mythpe/quasar-ui-qui 0.1.94 → 0.1.96
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/__pluralize.js +78 -88
package/package.json
CHANGED
package/src/utils/__pluralize.js
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
|
-
|
|
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 () {
|
|
1
|
+
const __pluralize = function () {
|
|
18
2
|
// Rule storage - pluralize and singularize need to be run sequentially,
|
|
19
3
|
// while other rules can be optimized using an object for instant lookups.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
4
|
+
const pluralRules = []
|
|
5
|
+
const singularRules = []
|
|
6
|
+
const uncountables = {}
|
|
7
|
+
const irregularPlurals = {}
|
|
8
|
+
const irregularSingles = {}
|
|
25
9
|
|
|
26
10
|
/**
|
|
27
11
|
* Sanitize a pluralization rule to a usable regular expression.
|
|
@@ -31,10 +15,10 @@
|
|
|
31
15
|
*/
|
|
32
16
|
function sanitizeRule (rule) {
|
|
33
17
|
if (typeof rule === 'string') {
|
|
34
|
-
return new RegExp('^' + rule + '$', 'i')
|
|
18
|
+
return new RegExp('^' + rule + '$', 'i')
|
|
35
19
|
}
|
|
36
20
|
|
|
37
|
-
return rule
|
|
21
|
+
return rule
|
|
38
22
|
}
|
|
39
23
|
|
|
40
24
|
/**
|
|
@@ -47,21 +31,21 @@
|
|
|
47
31
|
*/
|
|
48
32
|
function restoreCase (word, token) {
|
|
49
33
|
// Tokens are an exact match.
|
|
50
|
-
if (word === token) return token
|
|
34
|
+
if (word === token) return token
|
|
51
35
|
|
|
52
36
|
// Lower cased words. E.g. "hello".
|
|
53
|
-
if (word === word.toLowerCase()) return token.toLowerCase()
|
|
37
|
+
if (word === word.toLowerCase()) return token.toLowerCase()
|
|
54
38
|
|
|
55
39
|
// Upper cased words. E.g. "WHISKY".
|
|
56
|
-
if (word === word.toUpperCase()) return token.toUpperCase()
|
|
40
|
+
if (word === word.toUpperCase()) return token.toUpperCase()
|
|
57
41
|
|
|
58
42
|
// Title cased words. E.g. "Title".
|
|
59
43
|
if (word[0] === word[0].toUpperCase()) {
|
|
60
|
-
return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase()
|
|
44
|
+
return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase()
|
|
61
45
|
}
|
|
62
46
|
|
|
63
47
|
// Lower cased words. E.g. "test".
|
|
64
|
-
return token.toLowerCase()
|
|
48
|
+
return token.toLowerCase()
|
|
65
49
|
}
|
|
66
50
|
|
|
67
51
|
/**
|
|
@@ -73,8 +57,8 @@
|
|
|
73
57
|
*/
|
|
74
58
|
function interpolate (str, args) {
|
|
75
59
|
return str.replace(/\$(\d{1,2})/g, function (match, index) {
|
|
76
|
-
return args[index] || ''
|
|
77
|
-
})
|
|
60
|
+
return args[index] || ''
|
|
61
|
+
})
|
|
78
62
|
}
|
|
79
63
|
|
|
80
64
|
/**
|
|
@@ -86,14 +70,14 @@
|
|
|
86
70
|
*/
|
|
87
71
|
function replace (word, rule) {
|
|
88
72
|
return word.replace(rule[0], function (match, index) {
|
|
89
|
-
|
|
73
|
+
const result = interpolate(rule[1], arguments)
|
|
90
74
|
|
|
91
75
|
if (match === '') {
|
|
92
|
-
return restoreCase(word[index - 1], result)
|
|
76
|
+
return restoreCase(word[index - 1], result)
|
|
93
77
|
}
|
|
94
78
|
|
|
95
|
-
return restoreCase(match, result)
|
|
96
|
-
})
|
|
79
|
+
return restoreCase(match, result)
|
|
80
|
+
})
|
|
97
81
|
}
|
|
98
82
|
|
|
99
83
|
/**
|
|
@@ -107,19 +91,19 @@
|
|
|
107
91
|
function sanitizeWord (token, word, rules) {
|
|
108
92
|
// Empty string or doesn't need fixing.
|
|
109
93
|
if (!token.length || uncountables.hasOwnProperty(token)) {
|
|
110
|
-
return word
|
|
94
|
+
return word
|
|
111
95
|
}
|
|
112
96
|
|
|
113
|
-
|
|
97
|
+
let len = rules.length
|
|
114
98
|
|
|
115
99
|
// Iterate over the sanitization rules and use the first one to match.
|
|
116
100
|
while (len--) {
|
|
117
|
-
|
|
101
|
+
const rule = rules[len]
|
|
118
102
|
|
|
119
|
-
if (rule[0].test(word)) return replace(word, rule)
|
|
103
|
+
if (rule[0].test(word)) return replace(word, rule)
|
|
120
104
|
}
|
|
121
105
|
|
|
122
|
-
return word
|
|
106
|
+
return word
|
|
123
107
|
}
|
|
124
108
|
|
|
125
109
|
/**
|
|
@@ -133,21 +117,21 @@
|
|
|
133
117
|
function replaceWord (replaceMap, keepMap, rules) {
|
|
134
118
|
return function (word) {
|
|
135
119
|
// Get the correct token and case restoration functions.
|
|
136
|
-
|
|
120
|
+
const token = word.toLowerCase()
|
|
137
121
|
|
|
138
122
|
// Check against the keep object map.
|
|
139
123
|
if (keepMap.hasOwnProperty(token)) {
|
|
140
|
-
return restoreCase(word, token)
|
|
124
|
+
return restoreCase(word, token)
|
|
141
125
|
}
|
|
142
126
|
|
|
143
127
|
// Check against the replacement map for a direct word replacement.
|
|
144
128
|
if (replaceMap.hasOwnProperty(token)) {
|
|
145
|
-
return restoreCase(word, replaceMap[token])
|
|
129
|
+
return restoreCase(word, replaceMap[token])
|
|
146
130
|
}
|
|
147
131
|
|
|
148
132
|
// Run all the rules against the word.
|
|
149
|
-
return sanitizeWord(token, word, rules)
|
|
150
|
-
}
|
|
133
|
+
return sanitizeWord(token, word, rules)
|
|
134
|
+
}
|
|
151
135
|
}
|
|
152
136
|
|
|
153
137
|
/**
|
|
@@ -155,13 +139,13 @@
|
|
|
155
139
|
*/
|
|
156
140
|
function checkWord (replaceMap, keepMap, rules, bool) {
|
|
157
141
|
return function (word) {
|
|
158
|
-
|
|
142
|
+
const token = word.toLowerCase()
|
|
159
143
|
|
|
160
|
-
if (keepMap.hasOwnProperty(token)) return true
|
|
161
|
-
if (replaceMap.hasOwnProperty(token)) return false
|
|
144
|
+
if (keepMap.hasOwnProperty(token)) return true
|
|
145
|
+
if (replaceMap.hasOwnProperty(token)) return false
|
|
162
146
|
|
|
163
|
-
return sanitizeWord(token, token, rules) === token
|
|
164
|
-
}
|
|
147
|
+
return sanitizeWord(token, token, rules) === token
|
|
148
|
+
}
|
|
165
149
|
}
|
|
166
150
|
|
|
167
151
|
/**
|
|
@@ -173,10 +157,10 @@
|
|
|
173
157
|
* @return {string}
|
|
174
158
|
*/
|
|
175
159
|
function pluralize (word, count, inclusive) {
|
|
176
|
-
|
|
177
|
-
? pluralize.singular(word) : pluralize.plural(word)
|
|
160
|
+
const pluralized = count === 1
|
|
161
|
+
? pluralize.singular(word) : pluralize.plural(word)
|
|
178
162
|
|
|
179
|
-
return (inclusive ? count + ' ' : '') + pluralized
|
|
163
|
+
return (inclusive ? count + ' ' : '') + pluralized
|
|
180
164
|
}
|
|
181
165
|
|
|
182
166
|
/**
|
|
@@ -186,7 +170,7 @@
|
|
|
186
170
|
*/
|
|
187
171
|
pluralize.plural = replaceWord(
|
|
188
172
|
irregularSingles, irregularPlurals, pluralRules
|
|
189
|
-
)
|
|
173
|
+
)
|
|
190
174
|
|
|
191
175
|
/**
|
|
192
176
|
* Check if a word is plural.
|
|
@@ -195,7 +179,7 @@
|
|
|
195
179
|
*/
|
|
196
180
|
pluralize.isPlural = checkWord(
|
|
197
181
|
irregularSingles, irregularPlurals, pluralRules
|
|
198
|
-
)
|
|
182
|
+
)
|
|
199
183
|
|
|
200
184
|
/**
|
|
201
185
|
* Singularize a word.
|
|
@@ -204,7 +188,7 @@
|
|
|
204
188
|
*/
|
|
205
189
|
pluralize.singular = replaceWord(
|
|
206
190
|
irregularPlurals, irregularSingles, singularRules
|
|
207
|
-
)
|
|
191
|
+
)
|
|
208
192
|
|
|
209
193
|
/**
|
|
210
194
|
* Check if a word is singular.
|
|
@@ -213,7 +197,7 @@
|
|
|
213
197
|
*/
|
|
214
198
|
pluralize.isSingular = checkWord(
|
|
215
199
|
irregularPlurals, irregularSingles, singularRules
|
|
216
|
-
)
|
|
200
|
+
)
|
|
217
201
|
|
|
218
202
|
/**
|
|
219
203
|
* Add a pluralization rule to the collection.
|
|
@@ -222,8 +206,8 @@
|
|
|
222
206
|
* @param {string} replacement
|
|
223
207
|
*/
|
|
224
208
|
pluralize.addPluralRule = function (rule, replacement) {
|
|
225
|
-
pluralRules.push([sanitizeRule(rule), replacement])
|
|
226
|
-
}
|
|
209
|
+
pluralRules.push([sanitizeRule(rule), replacement])
|
|
210
|
+
}
|
|
227
211
|
|
|
228
212
|
/**
|
|
229
213
|
* Add a singularization rule to the collection.
|
|
@@ -232,8 +216,8 @@
|
|
|
232
216
|
* @param {string} replacement
|
|
233
217
|
*/
|
|
234
218
|
pluralize.addSingularRule = function (rule, replacement) {
|
|
235
|
-
singularRules.push([sanitizeRule(rule), replacement])
|
|
236
|
-
}
|
|
219
|
+
singularRules.push([sanitizeRule(rule), replacement])
|
|
220
|
+
}
|
|
237
221
|
|
|
238
222
|
/**
|
|
239
223
|
* Add an uncountable word rule.
|
|
@@ -242,14 +226,14 @@
|
|
|
242
226
|
*/
|
|
243
227
|
pluralize.addUncountableRule = function (word) {
|
|
244
228
|
if (typeof word === 'string') {
|
|
245
|
-
uncountables[word.toLowerCase()] = true
|
|
246
|
-
return
|
|
229
|
+
uncountables[word.toLowerCase()] = true
|
|
230
|
+
return
|
|
247
231
|
}
|
|
248
232
|
|
|
249
233
|
// Set singular and plural references for the word.
|
|
250
|
-
pluralize.addPluralRule(word, '$0')
|
|
251
|
-
pluralize.addSingularRule(word, '$0')
|
|
252
|
-
}
|
|
234
|
+
pluralize.addPluralRule(word, '$0')
|
|
235
|
+
pluralize.addSingularRule(word, '$0')
|
|
236
|
+
}
|
|
253
237
|
|
|
254
238
|
/**
|
|
255
239
|
* Add an irregular word definition.
|
|
@@ -258,17 +242,17 @@
|
|
|
258
242
|
* @param {string} plural
|
|
259
243
|
*/
|
|
260
244
|
pluralize.addIrregularRule = function (single, plural) {
|
|
261
|
-
plural = plural.toLowerCase()
|
|
262
|
-
single = single.toLowerCase()
|
|
245
|
+
plural = plural.toLowerCase()
|
|
246
|
+
single = single.toLowerCase()
|
|
263
247
|
|
|
264
|
-
irregularSingles[single] = plural
|
|
265
|
-
irregularPlurals[plural] = single
|
|
266
|
-
}
|
|
248
|
+
irregularSingles[single] = plural
|
|
249
|
+
irregularPlurals[plural] = single
|
|
250
|
+
}
|
|
267
251
|
|
|
268
252
|
/**
|
|
269
253
|
* Irregular rules.
|
|
270
254
|
*/
|
|
271
|
-
[
|
|
255
|
+
const __irregularRules = [
|
|
272
256
|
// Pronouns.
|
|
273
257
|
['I', 'we'],
|
|
274
258
|
['me', 'us'],
|
|
@@ -321,14 +305,15 @@
|
|
|
321
305
|
['groove', 'grooves'],
|
|
322
306
|
['pickaxe', 'pickaxes'],
|
|
323
307
|
['passerby', 'passersby']
|
|
324
|
-
]
|
|
325
|
-
|
|
326
|
-
|
|
308
|
+
]
|
|
309
|
+
__irregularRules.forEach(function (rule) {
|
|
310
|
+
return pluralize.addIrregularRule(rule[0], rule[1])
|
|
311
|
+
})
|
|
327
312
|
|
|
328
313
|
/**
|
|
329
314
|
* Pluralization rules.
|
|
330
315
|
*/
|
|
331
|
-
[
|
|
316
|
+
const __pluralizationRules = [
|
|
332
317
|
[/s?$/i, 's'],
|
|
333
318
|
[/[^\u0000-\u007F]$/i, '$0'],
|
|
334
319
|
[/([^aeiou]ese)$/i, '$1'],
|
|
@@ -354,14 +339,16 @@
|
|
|
354
339
|
[/eaux$/i, '$0'],
|
|
355
340
|
[/m[ae]n$/i, 'men'],
|
|
356
341
|
['thou', 'you']
|
|
357
|
-
]
|
|
358
|
-
|
|
359
|
-
|
|
342
|
+
]
|
|
343
|
+
|
|
344
|
+
__pluralizationRules.forEach(function (rule) {
|
|
345
|
+
return pluralize.addPluralRule(rule[0], rule[1])
|
|
346
|
+
})
|
|
360
347
|
|
|
361
348
|
/**
|
|
362
349
|
* Singularization rules.
|
|
363
350
|
*/
|
|
364
|
-
[
|
|
351
|
+
const __singularizationRules = [
|
|
365
352
|
[/s$/i, ''],
|
|
366
353
|
[/(ss)$/i, '$1'],
|
|
367
354
|
[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, '$1fe'],
|
|
@@ -385,14 +372,15 @@
|
|
|
385
372
|
[/(child)ren$/i, '$1'],
|
|
386
373
|
[/(eau)x?$/i, '$1'],
|
|
387
374
|
[/men$/i, 'man']
|
|
388
|
-
]
|
|
389
|
-
|
|
390
|
-
|
|
375
|
+
]
|
|
376
|
+
__singularizationRules.forEach(function (rule) {
|
|
377
|
+
return pluralize.addSingularRule(rule[0], rule[1])
|
|
378
|
+
})
|
|
391
379
|
|
|
392
380
|
/**
|
|
393
381
|
* Uncountable rules.
|
|
394
382
|
*/
|
|
395
|
-
[
|
|
383
|
+
const __uncountableRules = [
|
|
396
384
|
// Singular words with no plurals.
|
|
397
385
|
'adulthood',
|
|
398
386
|
'advice',
|
|
@@ -497,7 +485,9 @@
|
|
|
497
485
|
/o[iu]s$/i, // "carnivorous"
|
|
498
486
|
/pox$/i, // "chickpox", "smallpox"
|
|
499
487
|
/sheep$/i
|
|
500
|
-
]
|
|
501
|
-
|
|
502
|
-
return pluralize
|
|
503
|
-
}
|
|
488
|
+
]
|
|
489
|
+
__uncountableRules.forEach(pluralize.addUncountableRule)
|
|
490
|
+
return pluralize
|
|
491
|
+
}
|
|
492
|
+
export const pluralize = __pluralize()
|
|
493
|
+
export default pluralize
|