@warp-drive-mirror/utilities 5.9.0-beta.0 → 5.9.0-beta.1

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
@@ -0,0 +1,448 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region ../../node_modules/.pnpm/@warp-d_f6d5a2b6297864aac1090915a29560e9/node_modules/@warp-drive-mirror/core/dist/utils/string.js
3
+ const DEFAULT_MAX_CACHE_SIZE = 1e4;
4
+ /**
5
+ * An LRUCache implementation with upsert semantics.
6
+ *
7
+ * This implementation is *not* generic, but focuses on
8
+ * performance tuning for the string transformation cases
9
+ * where the key maps to the value very simply.
10
+ *
11
+ * It takes a work function that should generate a new value
12
+ * for a given key when called. It will be called when the key
13
+ * is not found in the cache.
14
+ *
15
+ * It keeps track of the number of hits, misses, and ejections
16
+ * in DEBUG envs, which is useful for tuning the cache size.
17
+ *
18
+ * This is an internal utility class for use by this module
19
+ * and by `@warp-drive-mirror/utilities/string`. It is not intended
20
+ * for use outside of these modules at this time.
21
+ *
22
+ * @private
23
+ */
24
+ var LRUCache = class {
25
+ constructor(doWork, size) {
26
+ this.size = size || DEFAULT_MAX_CACHE_SIZE;
27
+ this.state = /* @__PURE__ */ new Map();
28
+ this.doWork = doWork;
29
+ }
30
+ get(key) {
31
+ const value = this.state.get(key);
32
+ if (value) {
33
+ this.state.delete(key);
34
+ this.state.set(key, value);
35
+ return value;
36
+ }
37
+ const newValue = this.doWork(key);
38
+ this.set(key, newValue);
39
+ return newValue;
40
+ }
41
+ set(key, value) {
42
+ if (this.state.size === this.size) for (const [k] of this.state) {
43
+ this.state.delete(k);
44
+ break;
45
+ }
46
+ this.state.set(key, value);
47
+ }
48
+ clear() {
49
+ this.state.clear();
50
+ }
51
+ };
52
+ const STRING_DASHERIZE_REGEXP = /[ _]/g;
53
+ const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g;
54
+ /**
55
+ * The {@link LRUCache} backing {@link dasherize}, keyed by the original
56
+ * (un-dasherized) string.
57
+ *
58
+ * @private
59
+ */
60
+ const STRING_DASHERIZE_CACHE = new LRUCache((key) => key.replace(STRING_DECAMELIZE_REGEXP, "$1_$2").toLowerCase().replace(STRING_DASHERIZE_REGEXP, "-"));
61
+ /**
62
+ * This is an internal utility function that converts a string
63
+ * to a dasherized format. Library consumers should use the
64
+ * re-exported version from `@warp-drive-mirror/utilities/string` instead.
65
+ *
66
+ * This version is only in this location to support a deprecated
67
+ * behavior in the core package and will be removed in a future.
68
+ *
69
+ * @private
70
+ */
71
+ function dasherize$1(str) {
72
+ return STRING_DASHERIZE_CACHE.get(str);
73
+ }
74
+
75
+ //#endregion
76
+ //#region src/-private/string/inflections.ts
77
+ const defaultRules = {
78
+ plurals: [
79
+ [/$/, "s"],
80
+ [/s$/i, "s"],
81
+ [/^(ax|test)is$/i, "$1es"],
82
+ [/(octop|vir)us$/i, "$1i"],
83
+ [/(octop|vir)i$/i, "$1i"],
84
+ [/(alias|status|bonus)$/i, "$1es"],
85
+ [/(tu|bu)s$/i, "$1ses"],
86
+ [/(buffal|tomat)o$/i, "$1oes"],
87
+ [/([ti])um$/i, "$1a"],
88
+ [/([ti])a$/i, "$1a"],
89
+ [/sis$/i, "ses"],
90
+ [/(?:([^f])fe|([lr])f)$/i, "$1$2ves"],
91
+ [/(hive)$/i, "$1s"],
92
+ [/([^aeiouy]|qu)y$/i, "$1ies"],
93
+ [/(x|ch|ss|sh)$/i, "$1es"],
94
+ [/(matr|vert|ind)(?:ix|ex)$/i, "$1ices"],
95
+ [/^(m|l)ouse$/i, "$1ice"],
96
+ [/^(m|l)ice$/i, "$1ice"],
97
+ [/^(ox)$/i, "$1en"],
98
+ [/^(oxen)$/i, "$1"],
99
+ [/(quiz)$/i, "$1zes"]
100
+ ],
101
+ singular: [
102
+ [/s$/i, ""],
103
+ [/(ss)$/i, "$1"],
104
+ [/(n)ews$/i, "$1ews"],
105
+ [/([ti])a$/i, "$1um"],
106
+ [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, "$1sis"],
107
+ [/(^analy)(sis|ses)$/i, "$1sis"],
108
+ [/([^f])ves$/i, "$1fe"],
109
+ [/(hive)s$/i, "$1"],
110
+ [/(tive)s$/i, "$1"],
111
+ [/([lr])ves$/i, "$1f"],
112
+ [/([^aeiouy]|qu)ies$/i, "$1y"],
113
+ [/(s)eries$/i, "$1eries"],
114
+ [/(m)ovies$/i, "$1ovie"],
115
+ [/(x|ch|ss|sh)es$/i, "$1"],
116
+ [/^(m|l)ice$/i, "$1ouse"],
117
+ [/(tus|bus)(es)?$/i, "$1"],
118
+ [/(o)es$/i, "$1"],
119
+ [/(shoe)s$/i, "$1"],
120
+ [/(cris|test)(is|es)$/i, "$1is"],
121
+ [/^(a)x[ie]s$/i, "$1xis"],
122
+ [/(octop|vir)(us|i)$/i, "$1us"],
123
+ [/(alias|status|bonus)(es)?$/i, "$1"],
124
+ [/^(ox)en/i, "$1"],
125
+ [/(vert|ind)ices$/i, "$1ex"],
126
+ [/(matr)ices$/i, "$1ix"],
127
+ [/(quiz)zes$/i, "$1"],
128
+ [/(database)s$/i, "$1"]
129
+ ],
130
+ irregularPairs: [
131
+ ["person", "people"],
132
+ ["man", "men"],
133
+ ["child", "children"],
134
+ ["sex", "sexes"],
135
+ ["move", "moves"],
136
+ ["cow", "kine"],
137
+ ["zombie", "zombies"]
138
+ ],
139
+ uncountable: [
140
+ "equipment",
141
+ "information",
142
+ "rice",
143
+ "money",
144
+ "species",
145
+ "series",
146
+ "fish",
147
+ "sheep",
148
+ "jeans",
149
+ "police"
150
+ ]
151
+ };
152
+
153
+ //#endregion
154
+ //#region src/-private/string/transform.ts
155
+ const STRING_CAMELIZE_REGEXP_1 = /(\-|\_|\.|\s)+(.)?/g;
156
+ const STRING_CAMELIZE_REGEXP_2 = /(^|\/)([A-Z])/g;
157
+ const CAMELIZE_CACHE = new LRUCache((key) => key.replace(STRING_CAMELIZE_REGEXP_1, (_match, _separator, chr) => chr ? chr.toUpperCase() : "").replace(STRING_CAMELIZE_REGEXP_2, (match) => match.toLowerCase()));
158
+ const STRING_UNDERSCORE_REGEXP_1 = /([a-z\d])([A-Z]+)/g;
159
+ const STRING_UNDERSCORE_REGEXP_2 = /\-|\s+/g;
160
+ const UNDERSCORE_CACHE = new LRUCache((str) => str.replace(STRING_UNDERSCORE_REGEXP_1, "$1_$2").replace(STRING_UNDERSCORE_REGEXP_2, "_").toLowerCase());
161
+ const STRING_CAPITALIZE_REGEXP = /(^|\/)([a-z\u00C0-\u024F])/g;
162
+ const CAPITALIZE_CACHE = new LRUCache((str) => str.replace(STRING_CAPITALIZE_REGEXP, (match) => match.toUpperCase()));
163
+ /**
164
+ * Replaces underscores, spaces, or camelCase with dashes.
165
+ *
166
+ * ```js
167
+ * import { dasherize } from '@warp-drive-mirror/utilities/string';
168
+ *
169
+ * dasherize('innerHTML'); // 'inner-html'
170
+ * dasherize('action_name'); // 'action-name'
171
+ * dasherize('css-class-name'); // 'css-class-name'
172
+ * dasherize('my favorite items'); // 'my-favorite-items'
173
+ * dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice'
174
+ * ```
175
+ *
176
+ * @public
177
+ * @since 4.13.0
178
+ */
179
+ const dasherize = dasherize$1;
180
+ /**
181
+ * Returns the lowerCamelCase form of a string.
182
+ *
183
+ * ```js
184
+ * import { camelize } from '@warp-drive-mirror/utilities/string';
185
+ *
186
+ * camelize('innerHTML'); // 'innerHTML'
187
+ * camelize('action_name'); // 'actionName'
188
+ * camelize('css-class-name'); // 'cssClassName'
189
+ * camelize('my favorite items'); // 'myFavoriteItems'
190
+ * camelize('My Favorite Items'); // 'myFavoriteItems'
191
+ * camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice'
192
+ * ```
193
+ *
194
+ * @public
195
+ * @since 4.13.0
196
+ */
197
+ function camelize(str) {
198
+ return CAMELIZE_CACHE.get(str);
199
+ }
200
+ /**
201
+ * Returns the lower\_case\_and\_underscored form of a string.
202
+ *
203
+ * ```js
204
+ * import { underscore } from '@warp-drive-mirror/utilities/string';
205
+ *
206
+ * underscore('innerHTML'); // 'inner_html'
207
+ * underscore('action_name'); // 'action_name'
208
+ * underscore('css-class-name'); // 'css_class_name'
209
+ * underscore('my favorite items'); // 'my_favorite_items'
210
+ * underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice'
211
+ * ```
212
+ *
213
+ * @public
214
+ * @since 4.13.0
215
+ */
216
+ function underscore(str) {
217
+ return UNDERSCORE_CACHE.get(str);
218
+ }
219
+ /**
220
+ * Returns the Capitalized form of a string
221
+ *
222
+ * ```js
223
+ * import { capitalize } from '@warp-drive-mirror/utilities/string';
224
+ *
225
+ * capitalize('innerHTML') // 'InnerHTML'
226
+ * capitalize('action_name') // 'Action_name'
227
+ * capitalize('css-class-name') // 'Css-class-name'
228
+ * capitalize('my favorite items') // 'My favorite items'
229
+ * capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice'
230
+ * ```
231
+ *
232
+ * @public
233
+ * @since 4.13.0
234
+ */
235
+ function capitalize(str) {
236
+ return CAPITALIZE_CACHE.get(str);
237
+ }
238
+ /**
239
+ * Sets the maximum size of the LRUCache for all string transformation functions.
240
+ * The default size is 10,000.
241
+ *
242
+ * @public
243
+ * @since 4.13.0
244
+ */
245
+ function setMaxLRUCacheSize(size) {
246
+ CAMELIZE_CACHE.size = size;
247
+ UNDERSCORE_CACHE.size = size;
248
+ CAPITALIZE_CACHE.size = size;
249
+ STRING_DASHERIZE_CACHE.size = size;
250
+ }
251
+
252
+ //#endregion
253
+ //#region src/-private/string/inflect.ts
254
+ const BLANK_REGEX = /^\s*$/;
255
+ const LAST_WORD_DASHED_REGEX = /([\w/-]+[_/\s-])([a-z\d]+$)/;
256
+ const LAST_WORD_CAMELIZED_REGEX = /([\w/\s-]+)([A-Z][a-z\d]*$)/;
257
+ const CAMELIZED_REGEX = /[A-Z][a-z\d]*$/;
258
+ const SINGULARS = new LRUCache((word) => {
259
+ return _singularize(word);
260
+ });
261
+ const PLURALS = new LRUCache((word) => {
262
+ return _pluralize(word);
263
+ });
264
+ const UNCOUNTABLE = new Set(defaultRules.uncountable);
265
+ const IRREGULAR = /* @__PURE__ */ new Map();
266
+ const INVERSE_IRREGULAR = /* @__PURE__ */ new Map();
267
+ const SINGULAR_RULES = new Map(defaultRules.singular.reverse());
268
+ const PLURAL_RULES = new Map(defaultRules.plurals.reverse());
269
+ /**
270
+ * Marks a word as uncountable. Uncountable words are not pluralized
271
+ * or singularized.
272
+ *
273
+ * @public
274
+ * @since 4.13.0
275
+ */
276
+ function uncountable(word) {
277
+ UNCOUNTABLE.add(word.toLowerCase());
278
+ }
279
+ /**
280
+ * Marks a list of words as uncountable. Uncountable words are not pluralized
281
+ * or singularized.
282
+ *
283
+ * @public
284
+ * @since 4.13.0
285
+ */
286
+ function loadUncountable(uncountables) {
287
+ uncountables.forEach((word) => {
288
+ uncountable(word);
289
+ });
290
+ }
291
+ /**
292
+ * Marks a word as irregular. Irregular words have unique
293
+ * pluralization and singularization rules.
294
+ *
295
+ * @public
296
+ * @since 4.13.0
297
+ */
298
+ function irregular(single, plur) {
299
+ IRREGULAR.set(single.toLowerCase(), plur);
300
+ IRREGULAR.set(plur.toLowerCase(), plur);
301
+ INVERSE_IRREGULAR.set(plur.toLowerCase(), single);
302
+ INVERSE_IRREGULAR.set(single.toLowerCase(), single);
303
+ }
304
+ /**
305
+ * Marks a list of word pairs as irregular. Irregular words have unique
306
+ * pluralization and singularization rules.
307
+ *
308
+ * @public
309
+ * @since 4.13.0
310
+ */
311
+ function loadIrregular(irregularPairs) {
312
+ irregularPairs.forEach((pair) => {
313
+ IRREGULAR.set(pair[0].toLowerCase(), pair[1]);
314
+ IRREGULAR.set(pair[1].toLowerCase(), pair[1]);
315
+ INVERSE_IRREGULAR.set(pair[1].toLowerCase(), pair[0]);
316
+ INVERSE_IRREGULAR.set(pair[0].toLowerCase(), pair[0]);
317
+ });
318
+ }
319
+ loadIrregular(defaultRules.irregularPairs);
320
+ /**
321
+ * Clears the caches for singularize and pluralize.
322
+ *
323
+ * @public
324
+ * @since 4.13.0
325
+ */
326
+ function clear() {
327
+ SINGULARS.clear();
328
+ PLURALS.clear();
329
+ }
330
+ /**
331
+ * Resets the inflection rules to the defaults.
332
+ *
333
+ * @public
334
+ * @since 4.13.0
335
+ */
336
+ function resetToDefaults() {
337
+ clearRules();
338
+ defaultRules.uncountable.forEach((v) => UNCOUNTABLE.add(v));
339
+ defaultRules.singular.forEach((v) => SINGULAR_RULES.set(v[0], v[1]));
340
+ defaultRules.plurals.forEach((v) => PLURAL_RULES.set(v[0], v[1]));
341
+ loadIrregular(defaultRules.irregularPairs);
342
+ }
343
+ /**
344
+ * Clears all inflection rules
345
+ * and resets the caches for singularize and pluralize.
346
+ *
347
+ * @public
348
+ * @since 4.13.0
349
+ */
350
+ function clearRules() {
351
+ SINGULARS.clear();
352
+ PLURALS.clear();
353
+ UNCOUNTABLE.clear();
354
+ IRREGULAR.clear();
355
+ INVERSE_IRREGULAR.clear();
356
+ SINGULAR_RULES.clear();
357
+ PLURAL_RULES.clear();
358
+ }
359
+ /**
360
+ * Singularizes a word.
361
+ *
362
+ * @public
363
+ * @since 4.13.0
364
+ */
365
+ function singularize(word) {
366
+ if (!word) return "";
367
+ return SINGULARS.get(word);
368
+ }
369
+ /**
370
+ * Pluralizes a word.
371
+ *
372
+ * @public
373
+ * @since 4.13.0
374
+ */
375
+ function pluralize(word) {
376
+ if (!word) return "";
377
+ return PLURALS.get(word);
378
+ }
379
+ function unshiftMap(v, map) {
380
+ const rules = [v, ...map.entries()];
381
+ map.clear();
382
+ rules.forEach((rule) => {
383
+ map.set(rule[0], rule[1]);
384
+ });
385
+ }
386
+ /**
387
+ * Adds a pluralization rule.
388
+ *
389
+ * @public
390
+ * @since 4.13.0
391
+ */
392
+ function plural(regex, string) {
393
+ if (PLURAL_RULES.has(regex)) PLURAL_RULES.delete(regex);
394
+ unshiftMap([regex, string], PLURAL_RULES);
395
+ }
396
+ /**
397
+ * Adds a singularization rule.
398
+ *
399
+ * @public
400
+ * @since 4.13.0
401
+ */
402
+ function singular(regex, string) {
403
+ if (SINGULAR_RULES.has(regex)) SINGULAR_RULES.delete(regex);
404
+ unshiftMap([regex, string], SINGULAR_RULES);
405
+ }
406
+ function _pluralize(word) {
407
+ return inflect(word, PLURAL_RULES, IRREGULAR);
408
+ }
409
+ function _singularize(word) {
410
+ return inflect(word, SINGULAR_RULES, INVERSE_IRREGULAR);
411
+ }
412
+ function inflect(word, typeRules, irregulars) {
413
+ if (!word || BLANK_REGEX.test(word)) return word;
414
+ const lowercase = word.toLowerCase();
415
+ if (UNCOUNTABLE.has(lowercase)) return word;
416
+ const wordSplit = LAST_WORD_DASHED_REGEX.exec(word) || LAST_WORD_CAMELIZED_REGEX.exec(word);
417
+ const lastWord = wordSplit ? wordSplit[2].toLowerCase() : null;
418
+ if (lastWord && UNCOUNTABLE.has(lastWord)) return word;
419
+ const isCamelized = CAMELIZED_REGEX.test(word);
420
+ for (let [rule, substitution] of irregulars) if (lowercase.match(rule + "$")) {
421
+ if (isCamelized && lastWord && irregulars.has(lastWord)) {
422
+ substitution = capitalize(substitution);
423
+ rule = capitalize(rule);
424
+ }
425
+ return word.replace(new RegExp(rule, "i"), substitution);
426
+ }
427
+ for (const [rule, substitution] of typeRules) if (rule.test(word)) return word.replace(rule, substitution);
428
+ return word;
429
+ }
430
+
431
+ //#endregion
432
+ exports.camelize = camelize;
433
+ exports.capitalize = capitalize;
434
+ exports.clear = clear;
435
+ exports.clearRules = clearRules;
436
+ exports.dasherize = dasherize;
437
+ exports.irregular = irregular;
438
+ exports.loadIrregular = loadIrregular;
439
+ exports.loadUncountable = loadUncountable;
440
+ exports.plural = plural;
441
+ exports.pluralize = pluralize;
442
+ exports.resetToDefaults = resetToDefaults;
443
+ exports.setMaxLRUCacheSize = setMaxLRUCacheSize;
444
+ exports.singular = singular;
445
+ exports.singularize = singularize;
446
+ exports.uncountable = uncountable;
447
+ exports.underscore = underscore;
448
+ //# sourceMappingURL=string.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.cjs","names":["DEFAULT_MAX_CACHE_SIZE","LRUCache","constructor","doWork","size","state","Map","get","key","value","delete","set","newValue","k","clear","STRING_DASHERIZE_REGEXP","STRING_DECAMELIZE_REGEXP","STRING_DASHERIZE_CACHE","replace","toLowerCase","dasherize","str","internalDasherize","LRUCache","defaultRules","capitalize","BLANK_REGEX","LAST_WORD_DASHED_REGEX","LAST_WORD_CAMELIZED_REGEX","CAMELIZED_REGEX","SINGULARS","word","_singularize","PLURALS","_pluralize","UNCOUNTABLE","Set","uncountable","IRREGULAR","Map","INVERSE_IRREGULAR","SINGULAR_RULES","singular","reverse","PLURAL_RULES","plurals","add","toLowerCase","loadUncountable","uncountables","forEach","irregular","single","plur","set","loadIrregular","irregularPairs","pair","clear","resetToDefaults","clearRules","v","singularize","get","pluralize","unshiftMap","map","rules","entries","rule","plural","regex","string","has","delete","inflect","typeRules","irregulars","isBlank","test","lowercase","wordSplit","exec","lastWord","isCamelized","substitution","match","replace","RegExp"],"sources":["../../../node_modules/.pnpm/@warp-d_f6d5a2b6297864aac1090915a29560e9/node_modules/@warp-drive-mirror/core/dist/utils/string.js","../src/-private/string/inflections.ts","../src/-private/string/transform.ts","../src/-private/string/inflect.ts"],"sourcesContent":["import { DEBUG } from '@warp-drive-mirror/core/build-config/env';\n\nconst DEFAULT_MAX_CACHE_SIZE = 10_000;\n\n/**\n * An LRUCache implementation with upsert semantics.\n *\n * This implementation is *not* generic, but focuses on\n * performance tuning for the string transformation cases\n * where the key maps to the value very simply.\n *\n * It takes a work function that should generate a new value\n * for a given key when called. It will be called when the key\n * is not found in the cache.\n *\n * It keeps track of the number of hits, misses, and ejections\n * in DEBUG envs, which is useful for tuning the cache size.\n *\n * This is an internal utility class for use by this module\n * and by `@warp-drive-mirror/utilities/string`. It is not intended\n * for use outside of these modules at this time.\n *\n * @private\n */\nexport class LRUCache<T, V> {\n declare size: number;\n declare state: Map<T, V>;\n declare doWork: (k: T) => V;\n\n // debug stats\n declare _hits: number;\n declare _misses: number;\n declare _ejected: number;\n\n constructor(doWork: (k: T) => V, size?: number) {\n this.size = size || DEFAULT_MAX_CACHE_SIZE;\n this.state = new Map();\n this.doWork = doWork;\n\n if (DEBUG) {\n this._hits = 0;\n this._misses = 0;\n this._ejected = 0;\n }\n }\n\n get(key: T): V {\n const value = this.state.get(key);\n if (value) {\n if (DEBUG) {\n this._hits++;\n }\n this.state.delete(key);\n this.state.set(key, value);\n return value;\n }\n if (DEBUG) {\n this._misses++;\n }\n\n const newValue = this.doWork(key);\n this.set(key, newValue);\n return newValue;\n }\n\n set(key: T, value: V): void {\n if (this.state.size === this.size) {\n for (const [k] of this.state) {\n if (DEBUG) {\n this._ejected++;\n }\n this.state.delete(k);\n break;\n }\n }\n this.state.set(key, value);\n }\n\n clear(): void {\n this.state.clear();\n if (DEBUG) {\n this._hits = 0;\n this._misses = 0;\n this._ejected = 0;\n }\n }\n}\n\nconst STRING_DASHERIZE_REGEXP = /[ _]/g;\nconst STRING_DECAMELIZE_REGEXP = /([a-z\\d])([A-Z])/g;\n/**\n * The {@link LRUCache} backing {@link dasherize}, keyed by the original\n * (un-dasherized) string.\n *\n * @private\n */\nexport const STRING_DASHERIZE_CACHE: LRUCache<string, string> = new LRUCache<string, string>((key: string) =>\n key.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase().replace(STRING_DASHERIZE_REGEXP, '-')\n);\n\n/**\n * This is an internal utility function that converts a string\n * to a dasherized format. Library consumers should use the\n * re-exported version from `@warp-drive-mirror/utilities/string` instead.\n *\n * This version is only in this location to support a deprecated\n * behavior in the core package and will be removed in a future.\n *\n * @private\n */\nexport function dasherize(str: string): string {\n return STRING_DASHERIZE_CACHE.get(str);\n}\n","export type RulesArray = Array<[RegExp, string]>;\ntype DefaultRulesType = {\n plurals: RulesArray;\n singular: RulesArray;\n irregularPairs: Array<[string, string]>;\n uncountable: string[];\n};\n\nexport const defaultRules: DefaultRulesType = {\n plurals: [\n [/$/, 's'],\n [/s$/i, 's'],\n [/^(ax|test)is$/i, '$1es'],\n [/(octop|vir)us$/i, '$1i'],\n [/(octop|vir)i$/i, '$1i'],\n [/(alias|status|bonus)$/i, '$1es'],\n [/(tu|bu)s$/i, '$1ses'],\n [/(buffal|tomat)o$/i, '$1oes'],\n [/([ti])um$/i, '$1a'],\n [/([ti])a$/i, '$1a'],\n [/sis$/i, 'ses'],\n [/(?:([^f])fe|([lr])f)$/i, '$1$2ves'],\n [/(hive)$/i, '$1s'],\n [/([^aeiouy]|qu)y$/i, '$1ies'],\n [/(x|ch|ss|sh)$/i, '$1es'],\n [/(matr|vert|ind)(?:ix|ex)$/i, '$1ices'],\n [/^(m|l)ouse$/i, '$1ice'],\n [/^(m|l)ice$/i, '$1ice'],\n [/^(ox)$/i, '$1en'],\n [/^(oxen)$/i, '$1'],\n [/(quiz)$/i, '$1zes'],\n ],\n\n singular: [\n [/s$/i, ''],\n [/(ss)$/i, '$1'],\n [/(n)ews$/i, '$1ews'],\n [/([ti])a$/i, '$1um'],\n [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '$1sis'],\n [/(^analy)(sis|ses)$/i, '$1sis'],\n [/([^f])ves$/i, '$1fe'],\n [/(hive)s$/i, '$1'],\n [/(tive)s$/i, '$1'],\n [/([lr])ves$/i, '$1f'],\n [/([^aeiouy]|qu)ies$/i, '$1y'],\n [/(s)eries$/i, '$1eries'],\n [/(m)ovies$/i, '$1ovie'],\n [/(x|ch|ss|sh)es$/i, '$1'],\n [/^(m|l)ice$/i, '$1ouse'],\n [/(tus|bus)(es)?$/i, '$1'],\n [/(o)es$/i, '$1'],\n [/(shoe)s$/i, '$1'],\n [/(cris|test)(is|es)$/i, '$1is'],\n [/^(a)x[ie]s$/i, '$1xis'],\n [/(octop|vir)(us|i)$/i, '$1us'],\n [/(alias|status|bonus)(es)?$/i, '$1'],\n [/^(ox)en/i, '$1'],\n [/(vert|ind)ices$/i, '$1ex'],\n [/(matr)ices$/i, '$1ix'],\n [/(quiz)zes$/i, '$1'],\n [/(database)s$/i, '$1'],\n ],\n\n irregularPairs: [\n ['person', 'people'],\n ['man', 'men'],\n ['child', 'children'],\n ['sex', 'sexes'],\n ['move', 'moves'],\n ['cow', 'kine'],\n ['zombie', 'zombies'],\n ],\n\n uncountable: ['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'police'],\n};\n","import { dasherize as internalDasherize, LRUCache, STRING_DASHERIZE_CACHE } from '@warp-drive-mirror/core/utils/string';\n\n// eslint-disable-next-line no-useless-escape\nconst STRING_CAMELIZE_REGEXP_1 = /(\\-|\\_|\\.|\\s)+(.)?/g;\nconst STRING_CAMELIZE_REGEXP_2 = /(^|\\/)([A-Z])/g;\nconst CAMELIZE_CACHE = new LRUCache<string, string>((key: string) =>\n key\n .replace(STRING_CAMELIZE_REGEXP_1, (_match, _separator, chr: string | null) => (chr ? chr.toUpperCase() : ''))\n .replace(STRING_CAMELIZE_REGEXP_2, (match /*, separator, chr */) => match.toLowerCase())\n);\n\nconst STRING_UNDERSCORE_REGEXP_1 = /([a-z\\d])([A-Z]+)/g;\n// eslint-disable-next-line no-useless-escape\nconst STRING_UNDERSCORE_REGEXP_2 = /\\-|\\s+/g;\nconst UNDERSCORE_CACHE = new LRUCache<string, string>((str: string) =>\n str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2').replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase()\n);\n\nconst STRING_CAPITALIZE_REGEXP = /(^|\\/)([a-z\\u00C0-\\u024F])/g;\nconst CAPITALIZE_CACHE = new LRUCache<string, string>((str: string) =>\n str.replace(STRING_CAPITALIZE_REGEXP, (match /*, separator, chr */) => match.toUpperCase())\n);\n\n/**\n * Replaces underscores, spaces, or camelCase with dashes.\n *\n * ```js\n * import { dasherize } from '@warp-drive-mirror/utilities/string';\n *\n * dasherize('innerHTML'); // 'inner-html'\n * dasherize('action_name'); // 'action-name'\n * dasherize('css-class-name'); // 'css-class-name'\n * dasherize('my favorite items'); // 'my-favorite-items'\n * dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice'\n * ```\n *\n * @public\n * @since 4.13.0\n */\nexport const dasherize: (str: string) => string = internalDasherize;\n\n/**\n * Returns the lowerCamelCase form of a string.\n *\n * ```js\n * import { camelize } from '@warp-drive-mirror/utilities/string';\n *\n * camelize('innerHTML'); // 'innerHTML'\n * camelize('action_name'); // 'actionName'\n * camelize('css-class-name'); // 'cssClassName'\n * camelize('my favorite items'); // 'myFavoriteItems'\n * camelize('My Favorite Items'); // 'myFavoriteItems'\n * camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice'\n * ```\n *\n * @public\n * @since 4.13.0\n */\nexport function camelize(str: string): string {\n return CAMELIZE_CACHE.get(str);\n}\n\n/**\n * Returns the lower\\_case\\_and\\_underscored form of a string.\n *\n * ```js\n * import { underscore } from '@warp-drive-mirror/utilities/string';\n *\n * underscore('innerHTML'); // 'inner_html'\n * underscore('action_name'); // 'action_name'\n * underscore('css-class-name'); // 'css_class_name'\n * underscore('my favorite items'); // 'my_favorite_items'\n * underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice'\n * ```\n *\n * @public\n * @since 4.13.0\n */\nexport function underscore(str: string): string {\n return UNDERSCORE_CACHE.get(str);\n}\n\n/**\n * Returns the Capitalized form of a string\n *\n * ```js\n * import { capitalize } from '@warp-drive-mirror/utilities/string';\n *\n * capitalize('innerHTML') // 'InnerHTML'\n * capitalize('action_name') // 'Action_name'\n * capitalize('css-class-name') // 'Css-class-name'\n * capitalize('my favorite items') // 'My favorite items'\n * capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice'\n * ```\n *\n * @public\n * @since 4.13.0\n */\nexport function capitalize(str: string): string {\n return CAPITALIZE_CACHE.get(str);\n}\n\n/**\n * Sets the maximum size of the LRUCache for all string transformation functions.\n * The default size is 10,000.\n *\n * @public\n * @since 4.13.0\n */\nexport function setMaxLRUCacheSize(size: number): void {\n CAMELIZE_CACHE.size = size;\n UNDERSCORE_CACHE.size = size;\n CAPITALIZE_CACHE.size = size;\n STRING_DASHERIZE_CACHE.size = size;\n}\n","import { assert } from '@warp-drive-mirror/core/build-config/macros';\nimport { LRUCache } from '@warp-drive-mirror/core/utils/string';\n\nimport { defaultRules } from './inflections.ts';\nimport { capitalize } from './transform.ts';\n\nconst BLANK_REGEX = /^\\s*$/;\nconst LAST_WORD_DASHED_REGEX = /([\\w/-]+[_/\\s-])([a-z\\d]+$)/;\nconst LAST_WORD_CAMELIZED_REGEX = /([\\w/\\s-]+)([A-Z][a-z\\d]*$)/;\nconst CAMELIZED_REGEX = /[A-Z][a-z\\d]*$/;\n\nconst SINGULARS = new LRUCache<string, string>((word: string) => {\n return _singularize(word);\n});\nconst PLURALS = new LRUCache<string, string>((word: string) => {\n return _pluralize(word);\n});\nconst UNCOUNTABLE = new Set(defaultRules.uncountable);\nconst IRREGULAR: Map<string, string> = new Map();\nconst INVERSE_IRREGULAR: Map<string, string> = new Map();\nconst SINGULAR_RULES = new Map(defaultRules.singular.reverse());\nconst PLURAL_RULES = new Map(defaultRules.plurals.reverse());\n\n/**\n * Marks a word as uncountable. Uncountable words are not pluralized\n * or singularized.\n *\n * @public\n * @since 4.13.0\n */\nexport function uncountable(word: string): void {\n UNCOUNTABLE.add(word.toLowerCase());\n}\n\n/**\n * Marks a list of words as uncountable. Uncountable words are not pluralized\n * or singularized.\n *\n * @public\n * @since 4.13.0\n */\nexport function loadUncountable(uncountables: string[]): void {\n uncountables.forEach((word) => {\n uncountable(word);\n });\n}\n\n/**\n * Marks a word as irregular. Irregular words have unique\n * pluralization and singularization rules.\n *\n * @public\n * @since 4.13.0\n */\nexport function irregular(single: string, plur: string): void {\n //pluralizing\n IRREGULAR.set(single.toLowerCase(), plur);\n IRREGULAR.set(plur.toLowerCase(), plur);\n\n //singularizing\n INVERSE_IRREGULAR.set(plur.toLowerCase(), single);\n INVERSE_IRREGULAR.set(single.toLowerCase(), single);\n}\n\n/**\n * Marks a list of word pairs as irregular. Irregular words have unique\n * pluralization and singularization rules.\n *\n * @public\n * @since 4.13.0\n */\nexport function loadIrregular(irregularPairs: Array<[string, string]>): void {\n irregularPairs.forEach((pair) => {\n //pluralizing\n IRREGULAR.set(pair[0].toLowerCase(), pair[1]);\n IRREGULAR.set(pair[1].toLowerCase(), pair[1]);\n\n //singularizing\n INVERSE_IRREGULAR.set(pair[1].toLowerCase(), pair[0]);\n INVERSE_IRREGULAR.set(pair[0].toLowerCase(), pair[0]);\n });\n}\nloadIrregular(defaultRules.irregularPairs);\n\n/**\n * Clears the caches for singularize and pluralize.\n *\n * @public\n * @since 4.13.0\n */\nexport function clear(): void {\n SINGULARS.clear();\n PLURALS.clear();\n}\n\n/**\n * Resets the inflection rules to the defaults.\n *\n * @public\n * @since 4.13.0\n */\nexport function resetToDefaults(): void {\n clearRules();\n defaultRules.uncountable.forEach((v) => UNCOUNTABLE.add(v));\n defaultRules.singular.forEach((v) => SINGULAR_RULES.set(v[0], v[1]));\n defaultRules.plurals.forEach((v) => PLURAL_RULES.set(v[0], v[1]));\n loadIrregular(defaultRules.irregularPairs);\n}\n\n/**\n * Clears all inflection rules\n * and resets the caches for singularize and pluralize.\n *\n * @public\n * @since 4.13.0\n */\nexport function clearRules(): void {\n SINGULARS.clear();\n PLURALS.clear();\n UNCOUNTABLE.clear();\n IRREGULAR.clear();\n INVERSE_IRREGULAR.clear();\n SINGULAR_RULES.clear();\n PLURAL_RULES.clear();\n}\n\n/**\n * Singularizes a word.\n *\n * @public\n * @since 4.13.0\n */\nexport function singularize(word: string): string {\n assert(`singularize expects to receive a non-empty string`, typeof word === 'string' && word.length > 0);\n if (!word) return '';\n return SINGULARS.get(word);\n}\n\n/**\n * Pluralizes a word.\n *\n * @public\n * @since 4.13.0\n */\nexport function pluralize(word: string): string {\n assert(`pluralize expects to receive a non-empty string`, typeof word === 'string' && word.length > 0);\n if (!word) return '';\n return PLURALS.get(word);\n}\n\nfunction unshiftMap<K, V>(v: [K, V], map: Map<K, V>) {\n // reorder\n const rules = [v, ...map.entries()];\n map.clear();\n rules.forEach((rule) => {\n map.set(rule[0], rule[1]);\n });\n}\n\n/**\n * Adds a pluralization rule.\n *\n * @public\n * @since 4.13.0\n */\nexport function plural(regex: RegExp, string: string): void {\n // rule requires reordering if exists, so remove it first\n if (PLURAL_RULES.has(regex)) {\n PLURAL_RULES.delete(regex);\n }\n\n // reorder\n unshiftMap([regex, string], PLURAL_RULES);\n}\n\n/**\n * Adds a singularization rule.\n *\n * @public\n * @since 4.13.0\n */\nexport function singular(regex: RegExp, string: string): void {\n // rule requires reordering if exists, so remove it first\n if (SINGULAR_RULES.has(regex)) {\n SINGULAR_RULES.delete(regex);\n }\n\n // reorder\n unshiftMap([regex, string], SINGULAR_RULES);\n}\n\nfunction _pluralize(word: string) {\n return inflect(word, PLURAL_RULES, IRREGULAR);\n}\n\nfunction _singularize(word: string) {\n return inflect(word, SINGULAR_RULES, INVERSE_IRREGULAR);\n}\n\nfunction inflect(word: string, typeRules: Map<RegExp, string>, irregulars: Map<string, string>) {\n // empty strings\n const isBlank = !word || BLANK_REGEX.test(word);\n if (isBlank) {\n return word;\n }\n\n // basic uncountables\n const lowercase = word.toLowerCase();\n if (UNCOUNTABLE.has(lowercase)) {\n return word;\n }\n\n // adv uncountables\n const wordSplit = LAST_WORD_DASHED_REGEX.exec(word) || LAST_WORD_CAMELIZED_REGEX.exec(word);\n const lastWord = wordSplit ? wordSplit[2].toLowerCase() : null;\n if (lastWord && UNCOUNTABLE.has(lastWord)) {\n return word;\n }\n\n // handle irregulars\n const isCamelized = CAMELIZED_REGEX.test(word);\n for (let [rule, substitution] of irregulars) {\n if (lowercase.match(rule + '$')) {\n if (isCamelized && lastWord && irregulars.has(lastWord)) {\n substitution = capitalize(substitution);\n rule = capitalize(rule);\n }\n\n return word.replace(new RegExp(rule, 'i'), substitution);\n }\n }\n\n // do the actual inflection\n for (const [rule, substitution] of typeRules) {\n if (rule.test(word)) {\n return word.replace(rule, substitution);\n }\n }\n\n return word;\n}\n"],"x_google_ignoreList":[0],"mappings":";;AAEA,MAAMA,yBAAyB;;;;;;;;;;;;;;;;;;;;;AAsB/B,IAAaC,WAAb,MAA4B;CAU1BC,YAAYC,QAAqBC,MAAe;EAC9C,KAAKA,OAAOA,QAAQJ;EACpB,KAAKK,wBAAQ,IAAIC,IAAI;EACrB,KAAKH,SAASA;CAOhB;CAEAI,IAAIC,KAAW;EACb,MAAMC,QAAQ,KAAKJ,MAAME,IAAIC,GAAG;EAChC,IAAIC,OAAO;GAIT,KAAKJ,MAAMK,OAAOF,GAAG;GACrB,KAAKH,MAAMM,IAAIH,KAAKC,KAAK;GACzB,OAAOA;EACT;EAKA,MAAMG,WAAW,KAAKT,OAAOK,GAAG;EAChC,KAAKG,IAAIH,KAAKI,QAAQ;EACtB,OAAOA;CACT;CAEAD,IAAIH,KAAQC,OAAgB;EAC1B,IAAI,KAAKJ,MAAMD,SAAS,KAAKA,MAC3B,KAAK,MAAM,CA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MAAMqD,cAAcvD,gBAAgBkD,KAAKhD,IAAI;CAC7C,KAAK,IAAI,CAACsC,MAAMgB,iBAAiBR,YAC/B,IAAIG,UAAUM,MAAMjB,OAAO,GAAG,GAAG;EAC/B,IAAIe,eAAeD,YAAYN,WAAWJ,IAAIU,QAAQ,GAAG;GACvDE,eAAe5D,WAAW4D,YAAY;GACtChB,OAAO5C,WAAW4C,IAAI;EACxB;EAEA,OAAOtC,KAAKwD,QAAQ,IAAIC,OAAOnB,MAAM,GAAG,GAAGgB,YAAY;CACzD;CAIF,KAAK,MAAM,CAAChB,MAAMgB,iBAAiBT,WACjC,IAAIP,KAAKU,KAAKhD,IAAI,GAChB,OAAOA,KAAKwD,QAAQlB,MAAMgB,YAAY;CAI1C,OAAOtD;AACT"}
@@ -1 +1,12 @@
1
- export { defaultRules as InflectionRuleDefaults } from "./-private/string/inflections.js";
1
+ //#region src/-private/string/inflections.d.ts
2
+ type RulesArray = Array<[RegExp, string]>;
3
+ type DefaultRulesType = {
4
+ plurals: RulesArray;
5
+ singular: RulesArray;
6
+ irregularPairs: Array<[string, string]>;
7
+ uncountable: string[];
8
+ };
9
+ declare const defaultRules: DefaultRulesType;
10
+ //#endregion
11
+ export { defaultRules as InflectionRuleDefaults };
12
+ //# sourceMappingURL=-private.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"-private.d.ts","names":[],"sources":["../src/-private/string/inflections.ts"],"mappings":";KAAY,aAAa,OAAO;KAC3B;EACH,SAAS;EACT,UAAU;EACV,gBAAgB;EAChB;;cAGW,cAAc"}