@warp-drive/utilities 5.9.0-alpha.2 → 5.9.0-alpha.21

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/cjs-dist/string.cjs +448 -0
  2. package/cjs-dist/string.cjs.map +1 -0
  3. package/declarations/-private.d.ts +12 -1
  4. package/declarations/-private.d.ts.map +1 -0
  5. package/declarations/active-record.d.ts +260 -3
  6. package/declarations/active-record.d.ts.map +1 -0
  7. package/declarations/derivations.d.ts +26 -23
  8. package/declarations/derivations.d.ts.map +1 -0
  9. package/declarations/handlers.d.ts +282 -9
  10. package/declarations/handlers.d.ts.map +1 -0
  11. package/declarations/index-BeMAuqgZ.d.ts +462 -0
  12. package/declarations/index-BeMAuqgZ.d.ts.map +1 -0
  13. package/declarations/index.d.ts +2 -208
  14. package/declarations/json-api.d.ts +496 -5
  15. package/declarations/json-api.d.ts.map +1 -0
  16. package/declarations/rest.d.ts +258 -3
  17. package/declarations/rest.d.ts.map +1 -0
  18. package/declarations/string.d.ts +164 -13
  19. package/declarations/string.d.ts.map +1 -0
  20. package/dist/-private.js +2 -6
  21. package/dist/active-record.js +254 -379
  22. package/dist/active-record.js.map +1 -0
  23. package/dist/builder-utils-BkXwUT0x.js +16 -0
  24. package/dist/builder-utils-BkXwUT0x.js.map +1 -0
  25. package/dist/derivations.js +26 -26
  26. package/dist/derivations.js.map +1 -0
  27. package/dist/handlers.js +240 -283
  28. package/dist/handlers.js.map +1 -0
  29. package/dist/index.js +357 -335
  30. package/dist/index.js.map +1 -0
  31. package/dist/inflections-DzBsjJqj.js +80 -0
  32. package/dist/inflections-DzBsjJqj.js.map +1 -0
  33. package/dist/json-api.js +470 -706
  34. package/dist/json-api.js.map +1 -0
  35. package/dist/rest.js +254 -377
  36. package/dist/rest.js.map +1 -0
  37. package/dist/string-CWmAluxh.js +290 -0
  38. package/dist/string-CWmAluxh.js.map +1 -0
  39. package/dist/string.js +2 -427
  40. package/dist/unpkg/dev/-private.js +2 -6
  41. package/dist/unpkg/dev/active-record.js +253 -378
  42. package/dist/unpkg/dev/active-record.js.map +1 -0
  43. package/dist/unpkg/dev/builder-utils-BkXwUT0x.js +16 -0
  44. package/dist/unpkg/dev/builder-utils-BkXwUT0x.js.map +1 -0
  45. package/dist/unpkg/dev/derivations.js +26 -26
  46. package/dist/unpkg/dev/derivations.js.map +1 -0
  47. package/dist/unpkg/dev/handlers.js +238 -282
  48. package/dist/unpkg/dev/handlers.js.map +1 -0
  49. package/dist/unpkg/dev/index.js +356 -336
  50. package/dist/unpkg/dev/index.js.map +1 -0
  51. package/dist/unpkg/dev/inflections-DzBsjJqj.js +80 -0
  52. package/dist/unpkg/dev/inflections-DzBsjJqj.js.map +1 -0
  53. package/dist/unpkg/dev/json-api.js +469 -706
  54. package/dist/unpkg/dev/json-api.js.map +1 -0
  55. package/dist/unpkg/dev/rest.js +253 -376
  56. package/dist/unpkg/dev/rest.js.map +1 -0
  57. package/dist/unpkg/dev/string-j4ur-TDs.js +289 -0
  58. package/dist/unpkg/dev/string-j4ur-TDs.js.map +1 -0
  59. package/dist/unpkg/dev/string.js +3 -1
  60. package/dist/unpkg/dev-deprecated/-private.js +2 -6
  61. package/dist/unpkg/dev-deprecated/active-record.js +253 -378
  62. package/dist/unpkg/dev-deprecated/active-record.js.map +1 -0
  63. package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js +16 -0
  64. package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
  65. package/dist/unpkg/dev-deprecated/derivations.js +26 -26
  66. package/dist/unpkg/dev-deprecated/derivations.js.map +1 -0
  67. package/dist/unpkg/dev-deprecated/handlers.js +238 -282
  68. package/dist/unpkg/dev-deprecated/handlers.js.map +1 -0
  69. package/dist/unpkg/dev-deprecated/index.js +356 -336
  70. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  71. package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js +80 -0
  72. package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js.map +1 -0
  73. package/dist/unpkg/dev-deprecated/json-api.js +469 -706
  74. package/dist/unpkg/dev-deprecated/json-api.js.map +1 -0
  75. package/dist/unpkg/dev-deprecated/rest.js +253 -376
  76. package/dist/unpkg/dev-deprecated/rest.js.map +1 -0
  77. package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js +289 -0
  78. package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +1 -0
  79. package/dist/unpkg/dev-deprecated/string.js +3 -1
  80. package/dist/unpkg/prod/-private.js +2 -6
  81. package/dist/unpkg/prod/active-record.js +236 -351
  82. package/dist/unpkg/prod/active-record.js.map +1 -0
  83. package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +16 -0
  84. package/dist/unpkg/prod/builder-utils-BkXwUT0x.js.map +1 -0
  85. package/dist/unpkg/prod/derivations.js +26 -26
  86. package/dist/unpkg/prod/derivations.js.map +1 -0
  87. package/dist/unpkg/prod/handlers.js +231 -272
  88. package/dist/unpkg/prod/handlers.js.map +1 -0
  89. package/dist/unpkg/prod/index.js +265 -215
  90. package/dist/unpkg/prod/index.js.map +1 -0
  91. package/dist/unpkg/prod/inflections-DzBsjJqj.js +80 -0
  92. package/dist/unpkg/prod/inflections-DzBsjJqj.js.map +1 -0
  93. package/dist/unpkg/prod/json-api.js +446 -669
  94. package/dist/unpkg/prod/json-api.js.map +1 -0
  95. package/dist/unpkg/prod/rest.js +236 -349
  96. package/dist/unpkg/prod/rest.js.map +1 -0
  97. package/dist/unpkg/prod/string-T1ahjLdj.js +283 -0
  98. package/dist/unpkg/prod/string-T1ahjLdj.js.map +1 -0
  99. package/dist/unpkg/prod/string.js +3 -1
  100. package/dist/unpkg/prod-deprecated/-private.js +2 -6
  101. package/dist/unpkg/prod-deprecated/active-record.js +236 -351
  102. package/dist/unpkg/prod-deprecated/active-record.js.map +1 -0
  103. package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js +16 -0
  104. package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
  105. package/dist/unpkg/prod-deprecated/derivations.js +26 -26
  106. package/dist/unpkg/prod-deprecated/derivations.js.map +1 -0
  107. package/dist/unpkg/prod-deprecated/handlers.js +231 -272
  108. package/dist/unpkg/prod-deprecated/handlers.js.map +1 -0
  109. package/dist/unpkg/prod-deprecated/index.js +265 -215
  110. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  111. package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js +80 -0
  112. package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js.map +1 -0
  113. package/dist/unpkg/prod-deprecated/json-api.js +446 -669
  114. package/dist/unpkg/prod-deprecated/json-api.js.map +1 -0
  115. package/dist/unpkg/prod-deprecated/rest.js +236 -349
  116. package/dist/unpkg/prod-deprecated/rest.js.map +1 -0
  117. package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js +283 -0
  118. package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +1 -0
  119. package/dist/unpkg/prod-deprecated/string.js +3 -1
  120. package/package.json +11 -10
  121. package/declarations/-private/active-record/find-record.d.ts +0 -64
  122. package/declarations/-private/active-record/query.d.ts +0 -53
  123. package/declarations/-private/active-record/save-record.d.ts +0 -146
  124. package/declarations/-private/builder-utils.d.ts +0 -4
  125. package/declarations/-private/handlers/auto-compress.d.ts +0 -158
  126. package/declarations/-private/handlers/gated.d.ts +0 -19
  127. package/declarations/-private/handlers/meta-doc.d.ts +0 -47
  128. package/declarations/-private/handlers/utils.d.ts +0 -41
  129. package/declarations/-private/json-api/-utils.d.ts +0 -109
  130. package/declarations/-private/json-api/find-record.d.ts +0 -84
  131. package/declarations/-private/json-api/query.d.ts +0 -100
  132. package/declarations/-private/json-api/save-record.d.ts +0 -228
  133. package/declarations/-private/json-api/serialize.d.ts +0 -70
  134. package/declarations/-private/rest/find-record.d.ts +0 -62
  135. package/declarations/-private/rest/query.d.ts +0 -53
  136. package/declarations/-private/rest/save-record.d.ts +0 -146
  137. package/declarations/-private/string/inflect.d.ts +0 -82
  138. package/declarations/-private/string/inflections.d.ts +0 -9
  139. package/declarations/-private/string/transform.d.ts +0 -77
  140. package/dist/builder-utils-Donkk-BZ.js +0 -22
  141. package/dist/inflect-BSG696t-.js +0 -344
  142. package/dist/string.cjs +0 -430
  143. package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +0 -22
  144. package/dist/unpkg/dev/inflect-BEv8WqY1.js +0 -343
  145. package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +0 -22
  146. package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +0 -343
  147. package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +0 -22
  148. package/dist/unpkg/prod/inflect-Dh9dyEYx.js +0 -333
  149. package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +0 -22
  150. package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +0 -333
package/dist/string.cjs DELETED
@@ -1,430 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const DEFAULT_MAX_CACHE_SIZE = 10_000;
6
-
7
- /**
8
- * An LRUCache implementation with upsert semantics.
9
- *
10
- * This implementation is *not* generic, but focuses on
11
- * performance tuning for the string transformation cases
12
- * where the key maps to the value very simply.
13
- *
14
- * It takes a work function that should generate a new value
15
- * for a given key when called. It will be called when the key
16
- * is not found in the cache.
17
- *
18
- * It keeps track of the number of hits, misses, and ejections
19
- * in DEBUG envs, which is useful for tuning the cache size.
20
- *
21
- * This is an internal utility class for use by this module
22
- * and by `@warp-drive/utilities/string`. It is not intended
23
- * for use outside of these modules at this time.
24
- *
25
- * @private
26
- */
27
- class LRUCache {
28
- // debug stats
29
-
30
- constructor(doWork, size) {
31
- this.size = size || DEFAULT_MAX_CACHE_SIZE;
32
- this.state = new Map();
33
- this.doWork = doWork;
34
- }
35
- get(key) {
36
- const value = this.state.get(key);
37
- if (value) {
38
- this.state.delete(key);
39
- this.state.set(key, value);
40
- return value;
41
- }
42
- const newValue = this.doWork(key);
43
- this.set(key, newValue);
44
- return newValue;
45
- }
46
- set(key, value) {
47
- if (this.state.size === this.size) {
48
- for (const [k] of this.state) {
49
- this.state.delete(k);
50
- break;
51
- }
52
- }
53
- this.state.set(key, value);
54
- }
55
- clear() {
56
- this.state.clear();
57
- }
58
- }
59
- const STRING_DASHERIZE_REGEXP = /[ _]/g;
60
- const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g;
61
- const STRING_DASHERIZE_CACHE = new LRUCache(key => key.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase().replace(STRING_DASHERIZE_REGEXP, '-'));
62
-
63
- /**
64
- * This is an internal utility function that converts a string
65
- * to a dasherized format. Library consumers should use the
66
- * re-exported version from `@warp-drive/utilities/string` instead.
67
- *
68
- * This version is only in this location to support a deprecated
69
- * behavior in the core package and will be removed in a future.
70
- *
71
- * @private
72
- */
73
- function dasherize$1(str) {
74
- return STRING_DASHERIZE_CACHE.get(str);
75
- }
76
-
77
- const defaultRules = {
78
- plurals: [[/$/, 's'], [/s$/i, 's'], [/^(ax|test)is$/i, '$1es'], [/(octop|vir)us$/i, '$1i'], [/(octop|vir)i$/i, '$1i'], [/(alias|status|bonus)$/i, '$1es'], [/(bu)s$/i, '$1ses'], [/(buffal|tomat)o$/i, '$1oes'], [/([ti])um$/i, '$1a'], [/([ti])a$/i, '$1a'], [/sis$/i, 'ses'], [/(?:([^f])fe|([lr])f)$/i, '$1$2ves'], [/(hive)$/i, '$1s'], [/([^aeiouy]|qu)y$/i, '$1ies'], [/(x|ch|ss|sh)$/i, '$1es'], [/(matr|vert|ind)(?:ix|ex)$/i, '$1ices'], [/^(m|l)ouse$/i, '$1ice'], [/^(m|l)ice$/i, '$1ice'], [/^(ox)$/i, '$1en'], [/^(oxen)$/i, '$1'], [/(quiz)$/i, '$1zes']],
79
- singular: [[/s$/i, ''], [/(ss)$/i, '$1'], [/(n)ews$/i, '$1ews'], [/([ti])a$/i, '$1um'], [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '$1sis'], [/(^analy)(sis|ses)$/i, '$1sis'], [/([^f])ves$/i, '$1fe'], [/(hive)s$/i, '$1'], [/(tive)s$/i, '$1'], [/([lr])ves$/i, '$1f'], [/([^aeiouy]|qu)ies$/i, '$1y'], [/(s)eries$/i, '$1eries'], [/(m)ovies$/i, '$1ovie'], [/(x|ch|ss|sh)es$/i, '$1'], [/^(m|l)ice$/i, '$1ouse'], [/(bus)(es)?$/i, '$1'], [/(o)es$/i, '$1'], [/(shoe)s$/i, '$1'], [/(cris|test)(is|es)$/i, '$1is'], [/^(a)x[ie]s$/i, '$1xis'], [/(octop|vir)(us|i)$/i, '$1us'], [/(alias|status|bonus)(es)?$/i, '$1'], [/^(ox)en/i, '$1'], [/(vert|ind)ices$/i, '$1ex'], [/(matr)ices$/i, '$1ix'], [/(quiz)zes$/i, '$1'], [/(database)s$/i, '$1']],
80
- irregularPairs: [['person', 'people'], ['man', 'men'], ['child', 'children'], ['sex', 'sexes'], ['move', 'moves'], ['cow', 'kine'], ['zombie', 'zombies']],
81
- uncountable: ['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'police']
82
- };
83
-
84
- // eslint-disable-next-line no-useless-escape
85
- const STRING_CAMELIZE_REGEXP_1 = /(\-|\_|\.|\s)+(.)?/g;
86
- const STRING_CAMELIZE_REGEXP_2 = /(^|\/)([A-Z])/g;
87
- 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()));
88
- const STRING_UNDERSCORE_REGEXP_1 = /([a-z\d])([A-Z]+)/g;
89
- // eslint-disable-next-line no-useless-escape
90
- const STRING_UNDERSCORE_REGEXP_2 = /\-|\s+/g;
91
- const UNDERSCORE_CACHE = new LRUCache(str => str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2').replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase());
92
- const STRING_CAPITALIZE_REGEXP = /(^|\/)([a-z\u00C0-\u024F])/g;
93
- const CAPITALIZE_CACHE = new LRUCache(str => str.replace(STRING_CAPITALIZE_REGEXP, (match /*, separator, chr */) => match.toUpperCase()));
94
-
95
- /**
96
- * Replaces underscores, spaces, or camelCase with dashes.
97
- *
98
- * ```js
99
- * import { dasherize } from '@warp-drive/utilities/string';
100
- *
101
- * dasherize('innerHTML'); // 'inner-html'
102
- * dasherize('action_name'); // 'action-name'
103
- * dasherize('css-class-name'); // 'css-class-name'
104
- * dasherize('my favorite items'); // 'my-favorite-items'
105
- * dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice'
106
- * ```
107
- *
108
- * @public
109
- * @since 4.13.0
110
- */
111
- const dasherize = dasherize$1;
112
-
113
- /**
114
- * Returns the lowerCamelCase form of a string.
115
- *
116
- * ```js
117
- * import { camelize } from '@warp-drive/utilities/string';
118
- *
119
- * camelize('innerHTML'); // 'innerHTML'
120
- * camelize('action_name'); // 'actionName'
121
- * camelize('css-class-name'); // 'cssClassName'
122
- * camelize('my favorite items'); // 'myFavoriteItems'
123
- * camelize('My Favorite Items'); // 'myFavoriteItems'
124
- * camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice'
125
- * ```
126
- *
127
- * @public
128
- * @since 4.13.0
129
- */
130
- function camelize(str) {
131
- return CAMELIZE_CACHE.get(str);
132
- }
133
-
134
- /**
135
- * Returns the lower\_case\_and\_underscored form of a string.
136
- *
137
- * ```js
138
- * import { underscore } from '@warp-drive/utilities/string';
139
- *
140
- * underscore('innerHTML'); // 'inner_html'
141
- * underscore('action_name'); // 'action_name'
142
- * underscore('css-class-name'); // 'css_class_name'
143
- * underscore('my favorite items'); // 'my_favorite_items'
144
- * underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice'
145
- * ```
146
- *
147
- * @public
148
- * @since 4.13.0
149
- */
150
- function underscore(str) {
151
- return UNDERSCORE_CACHE.get(str);
152
- }
153
-
154
- /**
155
- * Returns the Capitalized form of a string
156
- *
157
- * ```js
158
- * import { capitalize } from '@warp-drive/utilities/string';
159
- *
160
- * capitalize('innerHTML') // 'InnerHTML'
161
- * capitalize('action_name') // 'Action_name'
162
- * capitalize('css-class-name') // 'Css-class-name'
163
- * capitalize('my favorite items') // 'My favorite items'
164
- * capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice'
165
- * ```
166
- *
167
- * @public
168
- * @since 4.13.0
169
- */
170
- function capitalize(str) {
171
- return CAPITALIZE_CACHE.get(str);
172
- }
173
-
174
- /**
175
- * Sets the maximum size of the LRUCache for all string transformation functions.
176
- * The default size is 10,000.
177
- *
178
- * @public
179
- * @since 4.13.0
180
- */
181
- function setMaxLRUCacheSize(size) {
182
- CAMELIZE_CACHE.size = size;
183
- UNDERSCORE_CACHE.size = size;
184
- CAPITALIZE_CACHE.size = size;
185
- STRING_DASHERIZE_CACHE.size = size;
186
- }
187
-
188
- const BLANK_REGEX = /^\s*$/;
189
- const LAST_WORD_DASHED_REGEX = /([\w/-]+[_/\s-])([a-z\d]+$)/;
190
- const LAST_WORD_CAMELIZED_REGEX = /([\w/\s-]+)([A-Z][a-z\d]*$)/;
191
- const CAMELIZED_REGEX = /[A-Z][a-z\d]*$/;
192
- const SINGULARS = new LRUCache(word => {
193
- return _singularize(word);
194
- });
195
- const PLURALS = new LRUCache(word => {
196
- return _pluralize(word);
197
- });
198
- const UNCOUNTABLE = new Set(defaultRules.uncountable);
199
- const IRREGULAR = new Map();
200
- const INVERSE_IRREGULAR = new Map();
201
- const SINGULAR_RULES = new Map(defaultRules.singular.reverse());
202
- const PLURAL_RULES = new Map(defaultRules.plurals.reverse());
203
-
204
- /**
205
- * Marks a word as uncountable. Uncountable words are not pluralized
206
- * or singularized.
207
- *
208
- * @public
209
- * @since 4.13.0
210
- */
211
- function uncountable(word) {
212
- UNCOUNTABLE.add(word.toLowerCase());
213
- }
214
-
215
- /**
216
- * Marks a list of words as uncountable. Uncountable words are not pluralized
217
- * or singularized.
218
- *
219
- * @public
220
- * @since 4.13.0
221
- */
222
- function loadUncountable(uncountables) {
223
- uncountables.forEach(word => {
224
- uncountable(word);
225
- });
226
- }
227
-
228
- /**
229
- * Marks a word as irregular. Irregular words have unique
230
- * pluralization and singularization rules.
231
- *
232
- * @public
233
- * @since 4.13.0
234
- */
235
- function irregular(single, plur) {
236
- //pluralizing
237
- IRREGULAR.set(single.toLowerCase(), plur);
238
- IRREGULAR.set(plur.toLowerCase(), plur);
239
-
240
- //singularizing
241
- INVERSE_IRREGULAR.set(plur.toLowerCase(), single);
242
- INVERSE_IRREGULAR.set(single.toLowerCase(), single);
243
- }
244
-
245
- /**
246
- * Marks a list of word pairs as irregular. Irregular words have unique
247
- * pluralization and singularization rules.
248
- *
249
- * @public
250
- * @since 4.13.0
251
- */
252
- function loadIrregular(irregularPairs) {
253
- irregularPairs.forEach(pair => {
254
- //pluralizing
255
- IRREGULAR.set(pair[0].toLowerCase(), pair[1]);
256
- IRREGULAR.set(pair[1].toLowerCase(), pair[1]);
257
-
258
- //singularizing
259
- INVERSE_IRREGULAR.set(pair[1].toLowerCase(), pair[0]);
260
- INVERSE_IRREGULAR.set(pair[0].toLowerCase(), pair[0]);
261
- });
262
- }
263
- loadIrregular(defaultRules.irregularPairs);
264
-
265
- /**
266
- * Clears the caches for singularize and pluralize.
267
- *
268
- * @public
269
- * @since 4.13.0
270
- */
271
- function clear() {
272
- SINGULARS.clear();
273
- PLURALS.clear();
274
- }
275
-
276
- /**
277
- * Resets the inflection rules to the defaults.
278
- *
279
- * @public
280
- * @since 4.13.0
281
- */
282
- function resetToDefaults() {
283
- clearRules();
284
- defaultRules.uncountable.forEach(v => UNCOUNTABLE.add(v));
285
- defaultRules.singular.forEach(v => SINGULAR_RULES.set(v[0], v[1]));
286
- defaultRules.plurals.forEach(v => PLURAL_RULES.set(v[0], v[1]));
287
- loadIrregular(defaultRules.irregularPairs);
288
- }
289
-
290
- /**
291
- * Clears all inflection rules
292
- * and resets the caches for singularize and pluralize.
293
- *
294
- * @public
295
- * @since 4.13.0
296
- */
297
- function clearRules() {
298
- SINGULARS.clear();
299
- PLURALS.clear();
300
- UNCOUNTABLE.clear();
301
- IRREGULAR.clear();
302
- INVERSE_IRREGULAR.clear();
303
- SINGULAR_RULES.clear();
304
- PLURAL_RULES.clear();
305
- }
306
-
307
- /**
308
- * Singularizes a word.
309
- *
310
- * @public
311
- * @since 4.13.0
312
- */
313
- function singularize(word) {
314
- if (!word) return '';
315
- return SINGULARS.get(word);
316
- }
317
-
318
- /**
319
- * Pluralizes a word.
320
- *
321
- * @public
322
- * @since 4.13.0
323
- */
324
- function pluralize(word) {
325
- if (!word) return '';
326
- return PLURALS.get(word);
327
- }
328
- function unshiftMap(v, map) {
329
- // reorder
330
- const rules = [v, ...map.entries()];
331
- map.clear();
332
- rules.forEach(rule => {
333
- map.set(rule[0], rule[1]);
334
- });
335
- }
336
-
337
- /**
338
- * Adds a pluralization rule.
339
- *
340
- * @public
341
- * @since 4.13.0
342
- */
343
- function plural(regex, string) {
344
- // rule requires reordering if exists, so remove it first
345
- if (PLURAL_RULES.has(regex)) {
346
- PLURAL_RULES.delete(regex);
347
- }
348
-
349
- // reorder
350
- unshiftMap([regex, string], PLURAL_RULES);
351
- }
352
-
353
- /**
354
- * Adds a singularization rule.
355
- *
356
- * @public
357
- * @since 4.13.0
358
- */
359
- function singular(regex, string) {
360
- // rule requires reordering if exists, so remove it first
361
- if (SINGULAR_RULES.has(regex)) {
362
- SINGULAR_RULES.delete(regex);
363
- }
364
-
365
- // reorder
366
- unshiftMap([regex, string], SINGULAR_RULES);
367
- }
368
- function _pluralize(word) {
369
- return inflect(word, PLURAL_RULES, IRREGULAR);
370
- }
371
- function _singularize(word) {
372
- return inflect(word, SINGULAR_RULES, INVERSE_IRREGULAR);
373
- }
374
- function inflect(word, typeRules, irregulars) {
375
- // empty strings
376
- const isBlank = !word || BLANK_REGEX.test(word);
377
- if (isBlank) {
378
- return word;
379
- }
380
-
381
- // basic uncountables
382
- const lowercase = word.toLowerCase();
383
- if (UNCOUNTABLE.has(lowercase)) {
384
- return word;
385
- }
386
-
387
- // adv uncountables
388
- const wordSplit = LAST_WORD_DASHED_REGEX.exec(word) || LAST_WORD_CAMELIZED_REGEX.exec(word);
389
- const lastWord = wordSplit ? wordSplit[2].toLowerCase() : null;
390
- if (lastWord && UNCOUNTABLE.has(lastWord)) {
391
- return word;
392
- }
393
-
394
- // handle irregulars
395
- const isCamelized = CAMELIZED_REGEX.test(word);
396
- for (let [rule, substitution] of irregulars) {
397
- if (lowercase.match(rule + '$')) {
398
- if (isCamelized && lastWord && irregulars.has(lastWord)) {
399
- substitution = capitalize(substitution);
400
- rule = capitalize(rule);
401
- }
402
- return word.replace(new RegExp(rule, 'i'), substitution);
403
- }
404
- }
405
-
406
- // do the actual inflection
407
- for (const [rule, substitution] of typeRules) {
408
- if (rule.test(word)) {
409
- return word.replace(rule, substitution);
410
- }
411
- }
412
- return word;
413
- }
414
-
415
- exports.camelize = camelize;
416
- exports.capitalize = capitalize;
417
- exports.clear = clear;
418
- exports.clearRules = clearRules;
419
- exports.dasherize = dasherize;
420
- exports.irregular = irregular;
421
- exports.loadIrregular = loadIrregular;
422
- exports.loadUncountable = loadUncountable;
423
- exports.plural = plural;
424
- exports.pluralize = pluralize;
425
- exports.resetToDefaults = resetToDefaults;
426
- exports.setMaxLRUCacheSize = setMaxLRUCacheSize;
427
- exports.singular = singular;
428
- exports.singularize = singularize;
429
- exports.uncountable = uncountable;
430
- exports.underscore = underscore;
@@ -1,22 +0,0 @@
1
- function copyForwardUrlOptions(urlOptions, options) {
2
- if ('host' in options) {
3
- urlOptions.host = options.host;
4
- }
5
- if ('namespace' in options) {
6
- urlOptions.namespace = options.namespace;
7
- }
8
- if ('resourcePath' in options) {
9
- urlOptions.resourcePath = options.resourcePath;
10
- }
11
- }
12
- function extractCacheOptions(options) {
13
- const cacheOptions = {};
14
- if ('reload' in options) {
15
- cacheOptions.reload = options.reload;
16
- }
17
- if ('backgroundReload' in options) {
18
- cacheOptions.backgroundReload = options.backgroundReload;
19
- }
20
- return cacheOptions;
21
- }
22
- export { copyForwardUrlOptions as c, extractCacheOptions as e };