@warp-drive-mirror/utilities 5.8.0-alpha.30 → 5.8.0-alpha.34

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.
Files changed (150) hide show
  1. package/dist/string.js +428 -1
  2. package/dist/unpkg/dev/-private.js +7 -0
  3. package/dist/unpkg/dev/active-record.js +395 -0
  4. package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +22 -0
  5. package/dist/unpkg/dev/declarations/-private/active-record/find-record.d.ts +64 -0
  6. package/dist/unpkg/dev/declarations/-private/active-record/query.d.ts +53 -0
  7. package/dist/unpkg/dev/declarations/-private/active-record/save-record.d.ts +146 -0
  8. package/dist/unpkg/dev/declarations/-private/builder-utils.d.ts +4 -0
  9. package/dist/unpkg/dev/declarations/-private/handlers/auto-compress.d.ts +158 -0
  10. package/dist/unpkg/dev/declarations/-private/handlers/gated.d.ts +19 -0
  11. package/dist/unpkg/dev/declarations/-private/handlers/meta-doc.d.ts +47 -0
  12. package/dist/unpkg/dev/declarations/-private/handlers/utils.d.ts +41 -0
  13. package/dist/unpkg/dev/declarations/-private/json-api/-utils.d.ts +109 -0
  14. package/dist/unpkg/dev/declarations/-private/json-api/find-record.d.ts +84 -0
  15. package/dist/unpkg/dev/declarations/-private/json-api/query.d.ts +100 -0
  16. package/dist/unpkg/dev/declarations/-private/json-api/save-record.d.ts +228 -0
  17. package/dist/unpkg/dev/declarations/-private/json-api/serialize.d.ts +70 -0
  18. package/dist/unpkg/dev/declarations/-private/rest/find-record.d.ts +62 -0
  19. package/dist/unpkg/dev/declarations/-private/rest/query.d.ts +53 -0
  20. package/dist/unpkg/dev/declarations/-private/rest/save-record.d.ts +146 -0
  21. package/dist/unpkg/dev/declarations/-private/string/inflect.d.ts +82 -0
  22. package/dist/unpkg/dev/declarations/-private/string/inflections.d.ts +9 -0
  23. package/dist/unpkg/dev/declarations/-private/string/transform.d.ts +77 -0
  24. package/dist/unpkg/dev/declarations/-private.d.ts +1 -0
  25. package/dist/unpkg/dev/declarations/active-record.d.ts +3 -0
  26. package/dist/unpkg/dev/declarations/derivations.d.ts +27 -0
  27. package/dist/unpkg/dev/declarations/handlers.d.ts +10 -0
  28. package/dist/unpkg/dev/declarations/index.d.ts +208 -0
  29. package/dist/unpkg/dev/declarations/json-api.d.ts +5 -0
  30. package/dist/unpkg/dev/declarations/rest.d.ts +3 -0
  31. package/dist/unpkg/dev/declarations/string.d.ts +14 -0
  32. package/dist/unpkg/dev/derivations.js +30 -0
  33. package/dist/unpkg/dev/handlers.js +317 -0
  34. package/dist/unpkg/dev/index.js +361 -0
  35. package/dist/unpkg/dev/inflect-BSG696t-.js +344 -0
  36. package/dist/unpkg/dev/json-api.js +740 -0
  37. package/dist/unpkg/dev/rest.js +393 -0
  38. package/dist/unpkg/dev/string.js +1 -0
  39. package/dist/unpkg/dev-deprecated/-private.js +7 -0
  40. package/dist/unpkg/dev-deprecated/active-record.js +395 -0
  41. package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +22 -0
  42. package/dist/unpkg/dev-deprecated/declarations/-private/active-record/find-record.d.ts +64 -0
  43. package/dist/unpkg/dev-deprecated/declarations/-private/active-record/query.d.ts +53 -0
  44. package/dist/unpkg/dev-deprecated/declarations/-private/active-record/save-record.d.ts +146 -0
  45. package/dist/unpkg/dev-deprecated/declarations/-private/builder-utils.d.ts +4 -0
  46. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/auto-compress.d.ts +158 -0
  47. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/gated.d.ts +19 -0
  48. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/meta-doc.d.ts +47 -0
  49. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/utils.d.ts +41 -0
  50. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/-utils.d.ts +109 -0
  51. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/find-record.d.ts +84 -0
  52. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/query.d.ts +100 -0
  53. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/save-record.d.ts +228 -0
  54. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/serialize.d.ts +70 -0
  55. package/dist/unpkg/dev-deprecated/declarations/-private/rest/find-record.d.ts +62 -0
  56. package/dist/unpkg/dev-deprecated/declarations/-private/rest/query.d.ts +53 -0
  57. package/dist/unpkg/dev-deprecated/declarations/-private/rest/save-record.d.ts +146 -0
  58. package/dist/unpkg/dev-deprecated/declarations/-private/string/inflect.d.ts +82 -0
  59. package/dist/unpkg/dev-deprecated/declarations/-private/string/inflections.d.ts +9 -0
  60. package/dist/unpkg/dev-deprecated/declarations/-private/string/transform.d.ts +77 -0
  61. package/dist/unpkg/dev-deprecated/declarations/-private.d.ts +1 -0
  62. package/dist/unpkg/dev-deprecated/declarations/active-record.d.ts +3 -0
  63. package/dist/unpkg/dev-deprecated/declarations/derivations.d.ts +27 -0
  64. package/dist/unpkg/dev-deprecated/declarations/handlers.d.ts +10 -0
  65. package/dist/unpkg/dev-deprecated/declarations/index.d.ts +208 -0
  66. package/dist/unpkg/dev-deprecated/declarations/json-api.d.ts +5 -0
  67. package/dist/unpkg/dev-deprecated/declarations/rest.d.ts +3 -0
  68. package/dist/unpkg/dev-deprecated/declarations/string.d.ts +14 -0
  69. package/dist/unpkg/dev-deprecated/derivations.js +30 -0
  70. package/dist/unpkg/dev-deprecated/handlers.js +317 -0
  71. package/dist/unpkg/dev-deprecated/index.js +361 -0
  72. package/dist/unpkg/dev-deprecated/inflect-BSG696t-.js +344 -0
  73. package/dist/unpkg/dev-deprecated/json-api.js +740 -0
  74. package/dist/unpkg/dev-deprecated/rest.js +393 -0
  75. package/dist/unpkg/dev-deprecated/string.js +1 -0
  76. package/dist/unpkg/prod/-private.js +7 -0
  77. package/dist/unpkg/prod/active-record.js +395 -0
  78. package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +22 -0
  79. package/dist/unpkg/prod/declarations/-private/active-record/find-record.d.ts +64 -0
  80. package/dist/unpkg/prod/declarations/-private/active-record/query.d.ts +53 -0
  81. package/dist/unpkg/prod/declarations/-private/active-record/save-record.d.ts +146 -0
  82. package/dist/unpkg/prod/declarations/-private/builder-utils.d.ts +4 -0
  83. package/dist/unpkg/prod/declarations/-private/handlers/auto-compress.d.ts +158 -0
  84. package/dist/unpkg/prod/declarations/-private/handlers/gated.d.ts +19 -0
  85. package/dist/unpkg/prod/declarations/-private/handlers/meta-doc.d.ts +47 -0
  86. package/dist/unpkg/prod/declarations/-private/handlers/utils.d.ts +41 -0
  87. package/dist/unpkg/prod/declarations/-private/json-api/-utils.d.ts +109 -0
  88. package/dist/unpkg/prod/declarations/-private/json-api/find-record.d.ts +84 -0
  89. package/dist/unpkg/prod/declarations/-private/json-api/query.d.ts +100 -0
  90. package/dist/unpkg/prod/declarations/-private/json-api/save-record.d.ts +228 -0
  91. package/dist/unpkg/prod/declarations/-private/json-api/serialize.d.ts +70 -0
  92. package/dist/unpkg/prod/declarations/-private/rest/find-record.d.ts +62 -0
  93. package/dist/unpkg/prod/declarations/-private/rest/query.d.ts +53 -0
  94. package/dist/unpkg/prod/declarations/-private/rest/save-record.d.ts +146 -0
  95. package/dist/unpkg/prod/declarations/-private/string/inflect.d.ts +82 -0
  96. package/dist/unpkg/prod/declarations/-private/string/inflections.d.ts +9 -0
  97. package/dist/unpkg/prod/declarations/-private/string/transform.d.ts +77 -0
  98. package/dist/unpkg/prod/declarations/-private.d.ts +1 -0
  99. package/dist/unpkg/prod/declarations/active-record.d.ts +3 -0
  100. package/dist/unpkg/prod/declarations/derivations.d.ts +27 -0
  101. package/dist/unpkg/prod/declarations/handlers.d.ts +10 -0
  102. package/dist/unpkg/prod/declarations/index.d.ts +208 -0
  103. package/dist/unpkg/prod/declarations/json-api.d.ts +5 -0
  104. package/dist/unpkg/prod/declarations/rest.d.ts +3 -0
  105. package/dist/unpkg/prod/declarations/string.d.ts +14 -0
  106. package/dist/unpkg/prod/derivations.js +30 -0
  107. package/dist/unpkg/prod/handlers.js +317 -0
  108. package/dist/unpkg/prod/index.js +361 -0
  109. package/dist/unpkg/prod/inflect-BSG696t-.js +344 -0
  110. package/dist/unpkg/prod/json-api.js +740 -0
  111. package/dist/unpkg/prod/rest.js +393 -0
  112. package/dist/unpkg/prod/string.js +1 -0
  113. package/dist/unpkg/prod-deprecated/-private.js +7 -0
  114. package/dist/unpkg/prod-deprecated/active-record.js +395 -0
  115. package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +22 -0
  116. package/dist/unpkg/prod-deprecated/declarations/-private/active-record/find-record.d.ts +64 -0
  117. package/dist/unpkg/prod-deprecated/declarations/-private/active-record/query.d.ts +53 -0
  118. package/dist/unpkg/prod-deprecated/declarations/-private/active-record/save-record.d.ts +146 -0
  119. package/dist/unpkg/prod-deprecated/declarations/-private/builder-utils.d.ts +4 -0
  120. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/auto-compress.d.ts +158 -0
  121. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/gated.d.ts +19 -0
  122. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/meta-doc.d.ts +47 -0
  123. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/utils.d.ts +41 -0
  124. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/-utils.d.ts +109 -0
  125. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/find-record.d.ts +84 -0
  126. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/query.d.ts +100 -0
  127. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/save-record.d.ts +228 -0
  128. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/serialize.d.ts +70 -0
  129. package/dist/unpkg/prod-deprecated/declarations/-private/rest/find-record.d.ts +62 -0
  130. package/dist/unpkg/prod-deprecated/declarations/-private/rest/query.d.ts +53 -0
  131. package/dist/unpkg/prod-deprecated/declarations/-private/rest/save-record.d.ts +146 -0
  132. package/dist/unpkg/prod-deprecated/declarations/-private/string/inflect.d.ts +82 -0
  133. package/dist/unpkg/prod-deprecated/declarations/-private/string/inflections.d.ts +9 -0
  134. package/dist/unpkg/prod-deprecated/declarations/-private/string/transform.d.ts +77 -0
  135. package/dist/unpkg/prod-deprecated/declarations/-private.d.ts +1 -0
  136. package/dist/unpkg/prod-deprecated/declarations/active-record.d.ts +3 -0
  137. package/dist/unpkg/prod-deprecated/declarations/derivations.d.ts +27 -0
  138. package/dist/unpkg/prod-deprecated/declarations/handlers.d.ts +10 -0
  139. package/dist/unpkg/prod-deprecated/declarations/index.d.ts +208 -0
  140. package/dist/unpkg/prod-deprecated/declarations/json-api.d.ts +5 -0
  141. package/dist/unpkg/prod-deprecated/declarations/rest.d.ts +3 -0
  142. package/dist/unpkg/prod-deprecated/declarations/string.d.ts +14 -0
  143. package/dist/unpkg/prod-deprecated/derivations.js +30 -0
  144. package/dist/unpkg/prod-deprecated/handlers.js +317 -0
  145. package/dist/unpkg/prod-deprecated/index.js +361 -0
  146. package/dist/unpkg/prod-deprecated/inflect-BSG696t-.js +344 -0
  147. package/dist/unpkg/prod-deprecated/json-api.js +740 -0
  148. package/dist/unpkg/prod-deprecated/rest.js +393 -0
  149. package/dist/unpkg/prod-deprecated/string.js +1 -0
  150. package/package.json +28 -4
@@ -0,0 +1,344 @@
1
+ import { LRUCache, dasherize as dasherize$1, STRING_DASHERIZE_CACHE } from '@warp-drive-mirror/core/utils/string';
2
+ import { InflectionRuleDefaults as defaultRules } from './-private.js';
3
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
+
5
+ // eslint-disable-next-line no-useless-escape
6
+ const STRING_CAMELIZE_REGEXP_1 = /(\-|\_|\.|\s)+(.)?/g;
7
+ const STRING_CAMELIZE_REGEXP_2 = /(^|\/)([A-Z])/g;
8
+ const CAMELIZE_CACHE = new LRUCache(key => key.replace(STRING_CAMELIZE_REGEXP_1, (_match, _separator, chr) => chr ? chr.toUpperCase() : '').replace(STRING_CAMELIZE_REGEXP_2, (match /*, separator, chr */) => match.toLowerCase()));
9
+ const STRING_UNDERSCORE_REGEXP_1 = /([a-z\d])([A-Z]+)/g;
10
+ // eslint-disable-next-line no-useless-escape
11
+ const STRING_UNDERSCORE_REGEXP_2 = /\-|\s+/g;
12
+ const UNDERSCORE_CACHE = new LRUCache(str => str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2').replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase());
13
+ const STRING_CAPITALIZE_REGEXP = /(^|\/)([a-z\u00C0-\u024F])/g;
14
+ const CAPITALIZE_CACHE = new LRUCache(str => str.replace(STRING_CAPITALIZE_REGEXP, (match /*, separator, chr */) => match.toUpperCase()));
15
+
16
+ /**
17
+ * Replaces underscores, spaces, or camelCase with dashes.
18
+ *
19
+ * ```js
20
+ * import { dasherize } from '@warp-drive-mirror/utilities/string';
21
+ *
22
+ * dasherize('innerHTML'); // 'inner-html'
23
+ * dasherize('action_name'); // 'action-name'
24
+ * dasherize('css-class-name'); // 'css-class-name'
25
+ * dasherize('my favorite items'); // 'my-favorite-items'
26
+ * dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice'
27
+ * ```
28
+ *
29
+ * @public
30
+ * @since 4.13.0
31
+ */
32
+ const dasherize = dasherize$1;
33
+
34
+ /**
35
+ * Returns the lowerCamelCase form of a string.
36
+ *
37
+ * ```js
38
+ * import { camelize } from '@warp-drive-mirror/utilities/string';
39
+ *
40
+ * camelize('innerHTML'); // 'innerHTML'
41
+ * camelize('action_name'); // 'actionName'
42
+ * camelize('css-class-name'); // 'cssClassName'
43
+ * camelize('my favorite items'); // 'myFavoriteItems'
44
+ * camelize('My Favorite Items'); // 'myFavoriteItems'
45
+ * camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice'
46
+ * ```
47
+ *
48
+ * @public
49
+ * @since 4.13.0
50
+ */
51
+ function camelize(str) {
52
+ return CAMELIZE_CACHE.get(str);
53
+ }
54
+
55
+ /**
56
+ * Returns the lower\_case\_and\_underscored form of a string.
57
+ *
58
+ * ```js
59
+ * import { underscore } from '@warp-drive-mirror/utilities/string';
60
+ *
61
+ * underscore('innerHTML'); // 'inner_html'
62
+ * underscore('action_name'); // 'action_name'
63
+ * underscore('css-class-name'); // 'css_class_name'
64
+ * underscore('my favorite items'); // 'my_favorite_items'
65
+ * underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice'
66
+ * ```
67
+ *
68
+ * @public
69
+ * @since 4.13.0
70
+ */
71
+ function underscore(str) {
72
+ return UNDERSCORE_CACHE.get(str);
73
+ }
74
+
75
+ /**
76
+ * Returns the Capitalized form of a string
77
+ *
78
+ * ```js
79
+ * import { capitalize } from '@warp-drive-mirror/utilities/string';
80
+ *
81
+ * capitalize('innerHTML') // 'InnerHTML'
82
+ * capitalize('action_name') // 'Action_name'
83
+ * capitalize('css-class-name') // 'Css-class-name'
84
+ * capitalize('my favorite items') // 'My favorite items'
85
+ * capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice'
86
+ * ```
87
+ *
88
+ * @public
89
+ * @since 4.13.0
90
+ */
91
+ function capitalize(str) {
92
+ return CAPITALIZE_CACHE.get(str);
93
+ }
94
+
95
+ /**
96
+ * Sets the maximum size of the LRUCache for all string transformation functions.
97
+ * The default size is 10,000.
98
+ *
99
+ * @public
100
+ * @since 4.13.0
101
+ */
102
+ function setMaxLRUCacheSize(size) {
103
+ CAMELIZE_CACHE.size = size;
104
+ UNDERSCORE_CACHE.size = size;
105
+ CAPITALIZE_CACHE.size = size;
106
+ STRING_DASHERIZE_CACHE.size = size;
107
+ }
108
+ const BLANK_REGEX = /^\s*$/;
109
+ const LAST_WORD_DASHED_REGEX = /([\w/-]+[_/\s-])([a-z\d]+$)/;
110
+ const LAST_WORD_CAMELIZED_REGEX = /([\w/\s-]+)([A-Z][a-z\d]*$)/;
111
+ const CAMELIZED_REGEX = /[A-Z][a-z\d]*$/;
112
+ const SINGULARS = new LRUCache(word => {
113
+ return _singularize(word);
114
+ });
115
+ const PLURALS = new LRUCache(word => {
116
+ return _pluralize(word);
117
+ });
118
+ const UNCOUNTABLE = new Set(defaultRules.uncountable);
119
+ const IRREGULAR = new Map();
120
+ const INVERSE_IRREGULAR = new Map();
121
+ const SINGULAR_RULES = new Map(defaultRules.singular.reverse());
122
+ const PLURAL_RULES = new Map(defaultRules.plurals.reverse());
123
+
124
+ /**
125
+ * Marks a word as uncountable. Uncountable words are not pluralized
126
+ * or singularized.
127
+ *
128
+ * @public
129
+ * @since 4.13.0
130
+ */
131
+ function uncountable(word) {
132
+ UNCOUNTABLE.add(word.toLowerCase());
133
+ }
134
+
135
+ /**
136
+ * Marks a list of words as uncountable. Uncountable words are not pluralized
137
+ * or singularized.
138
+ *
139
+ * @public
140
+ * @since 4.13.0
141
+ */
142
+ function loadUncountable(uncountables) {
143
+ uncountables.forEach(word => {
144
+ uncountable(word);
145
+ });
146
+ }
147
+
148
+ /**
149
+ * Marks a word as irregular. Irregular words have unique
150
+ * pluralization and singularization rules.
151
+ *
152
+ * @public
153
+ * @since 4.13.0
154
+ */
155
+ function irregular(single, plur) {
156
+ //pluralizing
157
+ IRREGULAR.set(single.toLowerCase(), plur);
158
+ IRREGULAR.set(plur.toLowerCase(), plur);
159
+
160
+ //singularizing
161
+ INVERSE_IRREGULAR.set(plur.toLowerCase(), single);
162
+ INVERSE_IRREGULAR.set(single.toLowerCase(), single);
163
+ }
164
+
165
+ /**
166
+ * Marks a list of word pairs as irregular. Irregular words have unique
167
+ * pluralization and singularization rules.
168
+ *
169
+ * @public
170
+ * @since 4.13.0
171
+ */
172
+ function loadIrregular(irregularPairs) {
173
+ irregularPairs.forEach(pair => {
174
+ //pluralizing
175
+ IRREGULAR.set(pair[0].toLowerCase(), pair[1]);
176
+ IRREGULAR.set(pair[1].toLowerCase(), pair[1]);
177
+
178
+ //singularizing
179
+ INVERSE_IRREGULAR.set(pair[1].toLowerCase(), pair[0]);
180
+ INVERSE_IRREGULAR.set(pair[0].toLowerCase(), pair[0]);
181
+ });
182
+ }
183
+ loadIrregular(defaultRules.irregularPairs);
184
+
185
+ /**
186
+ * Clears the caches for singularize and pluralize.
187
+ *
188
+ * @public
189
+ * @since 4.13.0
190
+ */
191
+ function clear() {
192
+ SINGULARS.clear();
193
+ PLURALS.clear();
194
+ }
195
+
196
+ /**
197
+ * Resets the inflection rules to the defaults.
198
+ *
199
+ * @public
200
+ * @since 4.13.0
201
+ */
202
+ function resetToDefaults() {
203
+ clearRules();
204
+ defaultRules.uncountable.forEach(v => UNCOUNTABLE.add(v));
205
+ defaultRules.singular.forEach(v => SINGULAR_RULES.set(v[0], v[1]));
206
+ defaultRules.plurals.forEach(v => PLURAL_RULES.set(v[0], v[1]));
207
+ loadIrregular(defaultRules.irregularPairs);
208
+ }
209
+
210
+ /**
211
+ * Clears all inflection rules
212
+ * and resets the caches for singularize and pluralize.
213
+ *
214
+ * @public
215
+ * @since 4.13.0
216
+ */
217
+ function clearRules() {
218
+ SINGULARS.clear();
219
+ PLURALS.clear();
220
+ UNCOUNTABLE.clear();
221
+ IRREGULAR.clear();
222
+ INVERSE_IRREGULAR.clear();
223
+ SINGULAR_RULES.clear();
224
+ PLURAL_RULES.clear();
225
+ }
226
+
227
+ /**
228
+ * Singularizes a word.
229
+ *
230
+ * @public
231
+ * @since 4.13.0
232
+ */
233
+ function singularize(word) {
234
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
235
+ if (!test) {
236
+ throw new Error(`singularize expects to receive a non-empty string`);
237
+ }
238
+ })(typeof word === 'string' && word.length > 0) : {};
239
+ if (!word) return '';
240
+ return SINGULARS.get(word);
241
+ }
242
+
243
+ /**
244
+ * Pluralizes a word.
245
+ *
246
+ * @public
247
+ * @since 4.13.0
248
+ */
249
+ function pluralize(word) {
250
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
251
+ if (!test) {
252
+ throw new Error(`pluralize expects to receive a non-empty string`);
253
+ }
254
+ })(typeof word === 'string' && word.length > 0) : {};
255
+ if (!word) return '';
256
+ return PLURALS.get(word);
257
+ }
258
+ function unshiftMap(v, map) {
259
+ // reorder
260
+ const rules = [v, ...map.entries()];
261
+ map.clear();
262
+ rules.forEach(rule => {
263
+ map.set(rule[0], rule[1]);
264
+ });
265
+ }
266
+
267
+ /**
268
+ * Adds a pluralization rule.
269
+ *
270
+ * @public
271
+ * @since 4.13.0
272
+ */
273
+ function plural(regex, string) {
274
+ // rule requires reordering if exists, so remove it first
275
+ if (PLURAL_RULES.has(regex)) {
276
+ PLURAL_RULES.delete(regex);
277
+ }
278
+
279
+ // reorder
280
+ unshiftMap([regex, string], PLURAL_RULES);
281
+ }
282
+
283
+ /**
284
+ * Adds a singularization rule.
285
+ *
286
+ * @public
287
+ * @since 4.13.0
288
+ */
289
+ function singular(regex, string) {
290
+ // rule requires reordering if exists, so remove it first
291
+ if (SINGULAR_RULES.has(regex)) {
292
+ SINGULAR_RULES.delete(regex);
293
+ }
294
+
295
+ // reorder
296
+ unshiftMap([regex, string], SINGULAR_RULES);
297
+ }
298
+ function _pluralize(word) {
299
+ return inflect(word, PLURAL_RULES, IRREGULAR);
300
+ }
301
+ function _singularize(word) {
302
+ return inflect(word, SINGULAR_RULES, INVERSE_IRREGULAR);
303
+ }
304
+ function inflect(word, typeRules, irregulars) {
305
+ // empty strings
306
+ const isBlank = !word || BLANK_REGEX.test(word);
307
+ if (isBlank) {
308
+ return word;
309
+ }
310
+
311
+ // basic uncountables
312
+ const lowercase = word.toLowerCase();
313
+ if (UNCOUNTABLE.has(lowercase)) {
314
+ return word;
315
+ }
316
+
317
+ // adv uncountables
318
+ const wordSplit = LAST_WORD_DASHED_REGEX.exec(word) || LAST_WORD_CAMELIZED_REGEX.exec(word);
319
+ const lastWord = wordSplit ? wordSplit[2].toLowerCase() : null;
320
+ if (lastWord && UNCOUNTABLE.has(lastWord)) {
321
+ return word;
322
+ }
323
+
324
+ // handle irregulars
325
+ const isCamelized = CAMELIZED_REGEX.test(word);
326
+ for (let [rule, substitution] of irregulars) {
327
+ if (lowercase.match(rule + '$')) {
328
+ if (isCamelized && lastWord && irregulars.has(lastWord)) {
329
+ substitution = capitalize(substitution);
330
+ rule = capitalize(rule);
331
+ }
332
+ return word.replace(new RegExp(rule, 'i'), substitution);
333
+ }
334
+ }
335
+
336
+ // do the actual inflection
337
+ for (const [rule, substitution] of typeRules) {
338
+ if (rule.test(word)) {
339
+ return word.replace(rule, substitution);
340
+ }
341
+ }
342
+ return word;
343
+ }
344
+ export { singular as a, plural as b, loadUncountable as c, clear as d, clearRules as e, dasherize as f, camelize as g, capitalize as h, irregular as i, underscore as j, setMaxLRUCacheSize as k, loadIrregular as l, pluralize as p, resetToDefaults as r, singularize as s, uncountable as u };