@warp-drive-mirror/utilities 5.9.0-alpha.9 → 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.
- package/cjs-dist/string.cjs +349 -331
- package/cjs-dist/string.cjs.map +1 -0
- package/declarations/-private.d.ts +12 -1
- package/declarations/-private.d.ts.map +1 -0
- package/declarations/active-record.d.ts +260 -3
- package/declarations/active-record.d.ts.map +1 -0
- package/declarations/derivations.d.ts +26 -23
- package/declarations/derivations.d.ts.map +1 -0
- package/declarations/handlers.d.ts +282 -9
- package/declarations/handlers.d.ts.map +1 -0
- package/declarations/index-BeMAuqgZ.d.ts +462 -0
- package/declarations/index-BeMAuqgZ.d.ts.map +1 -0
- package/declarations/index.d.ts +2 -208
- package/declarations/json-api.d.ts +496 -5
- package/declarations/json-api.d.ts.map +1 -0
- package/declarations/rest.d.ts +258 -3
- package/declarations/rest.d.ts.map +1 -0
- package/declarations/string.d.ts +164 -13
- package/declarations/string.d.ts.map +1 -0
- package/dist/-private.js +2 -6
- package/dist/active-record.js +254 -379
- package/dist/active-record.js.map +1 -0
- package/dist/builder-utils-BkXwUT0x.js +16 -0
- package/dist/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/derivations.js +26 -26
- package/dist/derivations.js.map +1 -0
- package/dist/handlers.js +240 -283
- package/dist/handlers.js.map +1 -0
- package/dist/index.js +357 -335
- package/dist/index.js.map +1 -0
- package/dist/inflections-DzBsjJqj.js +80 -0
- package/dist/inflections-DzBsjJqj.js.map +1 -0
- package/dist/json-api.js +470 -706
- package/dist/json-api.js.map +1 -0
- package/dist/rest.js +254 -377
- package/dist/rest.js.map +1 -0
- package/dist/string-CWmAluxh.js +290 -0
- package/dist/string-CWmAluxh.js.map +1 -0
- package/dist/string.js +3 -1
- package/dist/unpkg/dev/-private.js +2 -6
- package/dist/unpkg/dev/active-record.js +253 -378
- package/dist/unpkg/dev/active-record.js.map +1 -0
- package/dist/unpkg/dev/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/dev/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/dev/derivations.js +26 -26
- package/dist/unpkg/dev/derivations.js.map +1 -0
- package/dist/unpkg/dev/handlers.js +238 -282
- package/dist/unpkg/dev/handlers.js.map +1 -0
- package/dist/unpkg/dev/index.js +356 -336
- package/dist/unpkg/dev/index.js.map +1 -0
- package/dist/unpkg/dev/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/dev/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/dev/json-api.js +469 -706
- package/dist/unpkg/dev/json-api.js.map +1 -0
- package/dist/unpkg/dev/rest.js +253 -376
- package/dist/unpkg/dev/rest.js.map +1 -0
- package/dist/unpkg/dev/string-j4ur-TDs.js +289 -0
- package/dist/unpkg/dev/string-j4ur-TDs.js.map +1 -0
- package/dist/unpkg/dev/string.js +3 -1
- package/dist/unpkg/dev-deprecated/-private.js +2 -6
- package/dist/unpkg/dev-deprecated/active-record.js +253 -378
- package/dist/unpkg/dev-deprecated/active-record.js.map +1 -0
- package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/dev-deprecated/derivations.js +26 -26
- package/dist/unpkg/dev-deprecated/derivations.js.map +1 -0
- package/dist/unpkg/dev-deprecated/handlers.js +238 -282
- package/dist/unpkg/dev-deprecated/handlers.js.map +1 -0
- package/dist/unpkg/dev-deprecated/index.js +356 -336
- package/dist/unpkg/dev-deprecated/index.js.map +1 -0
- package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/dev-deprecated/json-api.js +469 -706
- package/dist/unpkg/dev-deprecated/json-api.js.map +1 -0
- package/dist/unpkg/dev-deprecated/rest.js +253 -376
- package/dist/unpkg/dev-deprecated/rest.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js +289 -0
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string.js +3 -1
- package/dist/unpkg/prod/-private.js +2 -6
- package/dist/unpkg/prod/active-record.js +236 -351
- package/dist/unpkg/prod/active-record.js.map +1 -0
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/prod/derivations.js +26 -26
- package/dist/unpkg/prod/derivations.js.map +1 -0
- package/dist/unpkg/prod/handlers.js +231 -272
- package/dist/unpkg/prod/handlers.js.map +1 -0
- package/dist/unpkg/prod/index.js +265 -215
- package/dist/unpkg/prod/index.js.map +1 -0
- package/dist/unpkg/prod/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/prod/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/prod/json-api.js +446 -669
- package/dist/unpkg/prod/json-api.js.map +1 -0
- package/dist/unpkg/prod/rest.js +236 -349
- package/dist/unpkg/prod/rest.js.map +1 -0
- package/dist/unpkg/prod/string-T1ahjLdj.js +283 -0
- package/dist/unpkg/prod/string-T1ahjLdj.js.map +1 -0
- package/dist/unpkg/prod/string.js +3 -1
- package/dist/unpkg/prod-deprecated/-private.js +2 -6
- package/dist/unpkg/prod-deprecated/active-record.js +236 -351
- package/dist/unpkg/prod-deprecated/active-record.js.map +1 -0
- package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/prod-deprecated/derivations.js +26 -26
- package/dist/unpkg/prod-deprecated/derivations.js.map +1 -0
- package/dist/unpkg/prod-deprecated/handlers.js +231 -272
- package/dist/unpkg/prod-deprecated/handlers.js.map +1 -0
- package/dist/unpkg/prod-deprecated/index.js +265 -215
- package/dist/unpkg/prod-deprecated/index.js.map +1 -0
- package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/prod-deprecated/json-api.js +446 -669
- package/dist/unpkg/prod-deprecated/json-api.js.map +1 -0
- package/dist/unpkg/prod-deprecated/rest.js +236 -349
- package/dist/unpkg/prod-deprecated/rest.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js +283 -0
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string.js +3 -1
- package/package.json +9 -9
- package/declarations/-private/active-record/find-record.d.ts +0 -64
- package/declarations/-private/active-record/query.d.ts +0 -53
- package/declarations/-private/active-record/save-record.d.ts +0 -146
- package/declarations/-private/builder-utils.d.ts +0 -4
- package/declarations/-private/handlers/auto-compress.d.ts +0 -158
- package/declarations/-private/handlers/gated.d.ts +0 -19
- package/declarations/-private/handlers/meta-doc.d.ts +0 -47
- package/declarations/-private/handlers/utils.d.ts +0 -41
- package/declarations/-private/json-api/-utils.d.ts +0 -109
- package/declarations/-private/json-api/find-record.d.ts +0 -84
- package/declarations/-private/json-api/query.d.ts +0 -100
- package/declarations/-private/json-api/save-record.d.ts +0 -228
- package/declarations/-private/json-api/serialize.d.ts +0 -70
- package/declarations/-private/rest/find-record.d.ts +0 -62
- package/declarations/-private/rest/query.d.ts +0 -53
- package/declarations/-private/rest/save-record.d.ts +0 -146
- package/declarations/-private/string/inflect.d.ts +0 -82
- package/declarations/-private/string/inflections.d.ts +0 -9
- package/declarations/-private/string/transform.d.ts +0 -77
- package/dist/builder-utils-Donkk-BZ.js +0 -22
- package/dist/inflect-BSG696t-.js +0 -344
- package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/dev/inflect-BEv8WqY1.js +0 -343
- package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +0 -343
- package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/prod/inflect-Dh9dyEYx.js +0 -333
- package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +0 -333
package/cjs-dist/string.cjs
CHANGED
|
@@ -1,417 +1,434 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const DEFAULT_MAX_CACHE_SIZE =
|
|
6
|
-
|
|
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;
|
|
7
4
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
clear() {
|
|
56
|
-
this.state.clear();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
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
|
+
};
|
|
59
52
|
const STRING_DASHERIZE_REGEXP = /[ _]/g;
|
|
60
53
|
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
54
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
+
*/
|
|
73
71
|
function dasherize$1(str) {
|
|
74
|
-
|
|
72
|
+
return STRING_DASHERIZE_CACHE.get(str);
|
|
75
73
|
}
|
|
76
74
|
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/-private/string/inflections.ts
|
|
77
77
|
const defaultRules = {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
]
|
|
82
151
|
};
|
|
83
152
|
|
|
84
|
-
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/-private/string/transform.ts
|
|
85
155
|
const STRING_CAMELIZE_REGEXP_1 = /(\-|\_|\.|\s)+(.)?/g;
|
|
86
156
|
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() :
|
|
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()));
|
|
88
158
|
const STRING_UNDERSCORE_REGEXP_1 = /([a-z\d])([A-Z]+)/g;
|
|
89
|
-
// eslint-disable-next-line no-useless-escape
|
|
90
159
|
const STRING_UNDERSCORE_REGEXP_2 = /\-|\s+/g;
|
|
91
|
-
const UNDERSCORE_CACHE = new LRUCache(str => str.replace(STRING_UNDERSCORE_REGEXP_1,
|
|
160
|
+
const UNDERSCORE_CACHE = new LRUCache((str) => str.replace(STRING_UNDERSCORE_REGEXP_1, "$1_$2").replace(STRING_UNDERSCORE_REGEXP_2, "_").toLowerCase());
|
|
92
161
|
const STRING_CAPITALIZE_REGEXP = /(^|\/)([a-z\u00C0-\u024F])/g;
|
|
93
|
-
const CAPITALIZE_CACHE = new LRUCache(str => str.replace(STRING_CAPITALIZE_REGEXP, (match
|
|
94
|
-
|
|
162
|
+
const CAPITALIZE_CACHE = new LRUCache((str) => str.replace(STRING_CAPITALIZE_REGEXP, (match) => match.toUpperCase()));
|
|
95
163
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
+
*/
|
|
111
179
|
const dasherize = dasherize$1;
|
|
112
|
-
|
|
113
180
|
/**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
+
*/
|
|
130
197
|
function camelize(str) {
|
|
131
|
-
|
|
198
|
+
return CAMELIZE_CACHE.get(str);
|
|
132
199
|
}
|
|
133
|
-
|
|
134
200
|
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
*/
|
|
150
216
|
function underscore(str) {
|
|
151
|
-
|
|
217
|
+
return UNDERSCORE_CACHE.get(str);
|
|
152
218
|
}
|
|
153
|
-
|
|
154
219
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
+
*/
|
|
170
235
|
function capitalize(str) {
|
|
171
|
-
|
|
236
|
+
return CAPITALIZE_CACHE.get(str);
|
|
172
237
|
}
|
|
173
|
-
|
|
174
238
|
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
+
*/
|
|
181
245
|
function setMaxLRUCacheSize(size) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
246
|
+
CAMELIZE_CACHE.size = size;
|
|
247
|
+
UNDERSCORE_CACHE.size = size;
|
|
248
|
+
CAPITALIZE_CACHE.size = size;
|
|
249
|
+
STRING_DASHERIZE_CACHE.size = size;
|
|
186
250
|
}
|
|
187
251
|
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/-private/string/inflect.ts
|
|
188
254
|
const BLANK_REGEX = /^\s*$/;
|
|
189
255
|
const LAST_WORD_DASHED_REGEX = /([\w/-]+[_/\s-])([a-z\d]+$)/;
|
|
190
256
|
const LAST_WORD_CAMELIZED_REGEX = /([\w/\s-]+)([A-Z][a-z\d]*$)/;
|
|
191
257
|
const CAMELIZED_REGEX = /[A-Z][a-z\d]*$/;
|
|
192
|
-
const SINGULARS = new LRUCache(word => {
|
|
193
|
-
|
|
258
|
+
const SINGULARS = new LRUCache((word) => {
|
|
259
|
+
return _singularize(word);
|
|
194
260
|
});
|
|
195
|
-
const PLURALS = new LRUCache(word => {
|
|
196
|
-
|
|
261
|
+
const PLURALS = new LRUCache((word) => {
|
|
262
|
+
return _pluralize(word);
|
|
197
263
|
});
|
|
198
264
|
const UNCOUNTABLE = new Set(defaultRules.uncountable);
|
|
199
|
-
const IRREGULAR = new Map();
|
|
200
|
-
const INVERSE_IRREGULAR = new Map();
|
|
265
|
+
const IRREGULAR = /* @__PURE__ */ new Map();
|
|
266
|
+
const INVERSE_IRREGULAR = /* @__PURE__ */ new Map();
|
|
201
267
|
const SINGULAR_RULES = new Map(defaultRules.singular.reverse());
|
|
202
268
|
const PLURAL_RULES = new Map(defaultRules.plurals.reverse());
|
|
203
|
-
|
|
204
269
|
/**
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
270
|
+
* Marks a word as uncountable. Uncountable words are not pluralized
|
|
271
|
+
* or singularized.
|
|
272
|
+
*
|
|
273
|
+
* @public
|
|
274
|
+
* @since 4.13.0
|
|
275
|
+
*/
|
|
211
276
|
function uncountable(word) {
|
|
212
|
-
|
|
277
|
+
UNCOUNTABLE.add(word.toLowerCase());
|
|
213
278
|
}
|
|
214
|
-
|
|
215
279
|
/**
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
*/
|
|
222
286
|
function loadUncountable(uncountables) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
287
|
+
uncountables.forEach((word) => {
|
|
288
|
+
uncountable(word);
|
|
289
|
+
});
|
|
226
290
|
}
|
|
227
|
-
|
|
228
291
|
/**
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
292
|
+
* Marks a word as irregular. Irregular words have unique
|
|
293
|
+
* pluralization and singularization rules.
|
|
294
|
+
*
|
|
295
|
+
* @public
|
|
296
|
+
* @since 4.13.0
|
|
297
|
+
*/
|
|
235
298
|
function irregular(single, plur) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
//singularizing
|
|
241
|
-
INVERSE_IRREGULAR.set(plur.toLowerCase(), single);
|
|
242
|
-
INVERSE_IRREGULAR.set(single.toLowerCase(), single);
|
|
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);
|
|
243
303
|
}
|
|
244
|
-
|
|
245
304
|
/**
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
+
*/
|
|
252
311
|
function loadIrregular(irregularPairs) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
INVERSE_IRREGULAR.set(pair[1].toLowerCase(), pair[0]);
|
|
260
|
-
INVERSE_IRREGULAR.set(pair[0].toLowerCase(), pair[0]);
|
|
261
|
-
});
|
|
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
|
+
});
|
|
262
318
|
}
|
|
263
319
|
loadIrregular(defaultRules.irregularPairs);
|
|
264
|
-
|
|
265
320
|
/**
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
321
|
+
* Clears the caches for singularize and pluralize.
|
|
322
|
+
*
|
|
323
|
+
* @public
|
|
324
|
+
* @since 4.13.0
|
|
325
|
+
*/
|
|
271
326
|
function clear() {
|
|
272
|
-
|
|
273
|
-
|
|
327
|
+
SINGULARS.clear();
|
|
328
|
+
PLURALS.clear();
|
|
274
329
|
}
|
|
275
|
-
|
|
276
330
|
/**
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
331
|
+
* Resets the inflection rules to the defaults.
|
|
332
|
+
*
|
|
333
|
+
* @public
|
|
334
|
+
* @since 4.13.0
|
|
335
|
+
*/
|
|
282
336
|
function resetToDefaults() {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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);
|
|
288
342
|
}
|
|
289
|
-
|
|
290
343
|
/**
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
344
|
+
* Clears all inflection rules
|
|
345
|
+
* and resets the caches for singularize and pluralize.
|
|
346
|
+
*
|
|
347
|
+
* @public
|
|
348
|
+
* @since 4.13.0
|
|
349
|
+
*/
|
|
297
350
|
function clearRules() {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
351
|
+
SINGULARS.clear();
|
|
352
|
+
PLURALS.clear();
|
|
353
|
+
UNCOUNTABLE.clear();
|
|
354
|
+
IRREGULAR.clear();
|
|
355
|
+
INVERSE_IRREGULAR.clear();
|
|
356
|
+
SINGULAR_RULES.clear();
|
|
357
|
+
PLURAL_RULES.clear();
|
|
305
358
|
}
|
|
306
|
-
|
|
307
359
|
/**
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
360
|
+
* Singularizes a word.
|
|
361
|
+
*
|
|
362
|
+
* @public
|
|
363
|
+
* @since 4.13.0
|
|
364
|
+
*/
|
|
313
365
|
function singularize(word) {
|
|
314
|
-
|
|
315
|
-
|
|
366
|
+
if (!word) return "";
|
|
367
|
+
return SINGULARS.get(word);
|
|
316
368
|
}
|
|
317
|
-
|
|
318
369
|
/**
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
370
|
+
* Pluralizes a word.
|
|
371
|
+
*
|
|
372
|
+
* @public
|
|
373
|
+
* @since 4.13.0
|
|
374
|
+
*/
|
|
324
375
|
function pluralize(word) {
|
|
325
|
-
|
|
326
|
-
|
|
376
|
+
if (!word) return "";
|
|
377
|
+
return PLURALS.get(word);
|
|
327
378
|
}
|
|
328
379
|
function unshiftMap(v, map) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
});
|
|
380
|
+
const rules = [v, ...map.entries()];
|
|
381
|
+
map.clear();
|
|
382
|
+
rules.forEach((rule) => {
|
|
383
|
+
map.set(rule[0], rule[1]);
|
|
384
|
+
});
|
|
335
385
|
}
|
|
336
|
-
|
|
337
386
|
/**
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
387
|
+
* Adds a pluralization rule.
|
|
388
|
+
*
|
|
389
|
+
* @public
|
|
390
|
+
* @since 4.13.0
|
|
391
|
+
*/
|
|
343
392
|
function plural(regex, string) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
PLURAL_RULES.delete(regex);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// reorder
|
|
350
|
-
unshiftMap([regex, string], PLURAL_RULES);
|
|
393
|
+
if (PLURAL_RULES.has(regex)) PLURAL_RULES.delete(regex);
|
|
394
|
+
unshiftMap([regex, string], PLURAL_RULES);
|
|
351
395
|
}
|
|
352
|
-
|
|
353
396
|
/**
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
397
|
+
* Adds a singularization rule.
|
|
398
|
+
*
|
|
399
|
+
* @public
|
|
400
|
+
* @since 4.13.0
|
|
401
|
+
*/
|
|
359
402
|
function singular(regex, string) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
SINGULAR_RULES.delete(regex);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// reorder
|
|
366
|
-
unshiftMap([regex, string], SINGULAR_RULES);
|
|
403
|
+
if (SINGULAR_RULES.has(regex)) SINGULAR_RULES.delete(regex);
|
|
404
|
+
unshiftMap([regex, string], SINGULAR_RULES);
|
|
367
405
|
}
|
|
368
406
|
function _pluralize(word) {
|
|
369
|
-
|
|
407
|
+
return inflect(word, PLURAL_RULES, IRREGULAR);
|
|
370
408
|
}
|
|
371
409
|
function _singularize(word) {
|
|
372
|
-
|
|
410
|
+
return inflect(word, SINGULAR_RULES, INVERSE_IRREGULAR);
|
|
373
411
|
}
|
|
374
412
|
function inflect(word, typeRules, irregulars) {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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
|
+
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;
|
|
413
429
|
}
|
|
414
430
|
|
|
431
|
+
//#endregion
|
|
415
432
|
exports.camelize = camelize;
|
|
416
433
|
exports.capitalize = capitalize;
|
|
417
434
|
exports.clear = clear;
|
|
@@ -428,3 +445,4 @@ exports.singular = singular;
|
|
|
428
445
|
exports.singularize = singularize;
|
|
429
446
|
exports.uncountable = uncountable;
|
|
430
447
|
exports.underscore = underscore;
|
|
448
|
+
//# sourceMappingURL=string.cjs.map
|