@warp-drive-mirror/utilities 5.8.0-beta.0 → 5.8.0-beta.2

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