es-toolkit 1.26.1-dev.836 → 1.26.1-dev.837

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.
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ const deburrMap = new Map(Object.entries({
4
+ Æ: 'Ae',
5
+ Ð: 'D',
6
+ Ø: 'O',
7
+ Þ: 'Th',
8
+ ß: 'ss',
9
+ æ: 'ae',
10
+ ð: 'd',
11
+ ø: 'o',
12
+ þ: 'th',
13
+ Đ: 'D',
14
+ đ: 'd',
15
+ Ħ: 'H',
16
+ ħ: 'h',
17
+ ı: 'i',
18
+ IJ: 'IJ',
19
+ ij: 'ij',
20
+ ĸ: 'k',
21
+ Ŀ: 'L',
22
+ ŀ: 'l',
23
+ Ł: 'L',
24
+ ł: 'l',
25
+ ʼn: "'n",
26
+ Ŋ: 'N',
27
+ ŋ: 'n',
28
+ Œ: 'Oe',
29
+ œ: 'oe',
30
+ Ŧ: 'T',
31
+ ŧ: 't',
32
+ ſ: 's',
33
+ }));
34
+ function deburr(str) {
35
+ str = str.normalize('NFD');
36
+ let result = '';
37
+ for (let i = 0; i < str.length; i++) {
38
+ const char = str[i];
39
+ if ((char >= '\u0300' && char <= '\u036f') || (char >= '\ufe20' && char <= '\ufe23')) {
40
+ continue;
41
+ }
42
+ result += deburrMap.get(char) ?? char;
43
+ }
44
+ return result;
45
+ }
46
+
47
+ exports.deburr = deburr;
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ const partialRight = require('./partialRight-CRhV1h.js');
3
4
  const isPlainObject = require('./isPlainObject-octpoD.js');
4
- const noop = require('./noop-2IwLUk.js');
5
+ require('./deburr-BPmkoM.js');
5
6
 
6
7
  function isArrayBuffer(value) {
7
8
  return value instanceof ArrayBuffer;
@@ -18,11 +19,16 @@ function isDate(value) {
18
19
  return value instanceof Date;
19
20
  }
20
21
 
21
- function getTag(value) {
22
- if (value == null) {
23
- return value === undefined ? '[object Undefined]' : '[object Null]';
24
- }
25
- return Object.prototype.toString.call(value);
22
+ function isLength(value) {
23
+ return Number.isSafeInteger(value) && value >= 0;
24
+ }
25
+
26
+ function isArrayLike(value) {
27
+ return value != null && typeof value !== 'function' && isLength(value.length);
28
+ }
29
+
30
+ function eq(value, other) {
31
+ return value === other || (Number.isNaN(value) && Number.isNaN(other));
26
32
  }
27
33
 
28
34
  const regexpTag = '[object RegExp]';
@@ -52,9 +58,187 @@ const bigInt64ArrayTag = '[object BigInt64Array]';
52
58
  const float32ArrayTag = '[object Float32Array]';
53
59
  const float64ArrayTag = '[object Float64Array]';
54
60
 
55
- function eq(value, other) {
56
- return value === other || (Number.isNaN(value) && Number.isNaN(other));
61
+ function getTag(value) {
62
+ if (value == null) {
63
+ return value === undefined ? '[object Undefined]' : '[object Null]';
64
+ }
65
+ return Object.prototype.toString.call(value);
66
+ }
67
+
68
+ function isNil(x) {
69
+ return x == null;
70
+ }
71
+
72
+ function bind(func, thisObj, ...partialArgs) {
73
+ const bound = function (...providedArgs) {
74
+ const args = [];
75
+ let startIndex = 0;
76
+ for (let i = 0; i < partialArgs.length; i++) {
77
+ const arg = partialArgs[i];
78
+ if (arg === bind.placeholder) {
79
+ args.push(providedArgs[startIndex++]);
80
+ }
81
+ else {
82
+ args.push(arg);
83
+ }
84
+ }
85
+ for (let i = startIndex; i < providedArgs.length; i++) {
86
+ args.push(providedArgs[i]);
87
+ }
88
+ if (this instanceof bound) {
89
+ return new func(...args);
90
+ }
91
+ return func.apply(thisObj, args);
92
+ };
93
+ return bound;
94
+ }
95
+ const bindPlaceholder = Symbol('bind.placeholder');
96
+ bind.placeholder = bindPlaceholder;
97
+
98
+ function bindKey(object, key, ...partialArgs) {
99
+ const bound = function (...providedArgs) {
100
+ const args = [];
101
+ let startIndex = 0;
102
+ for (let i = 0; i < partialArgs.length; i++) {
103
+ const arg = partialArgs[i];
104
+ if (arg === bindKey.placeholder) {
105
+ args.push(providedArgs[startIndex++]);
106
+ }
107
+ else {
108
+ args.push(arg);
109
+ }
110
+ }
111
+ for (let i = startIndex; i < providedArgs.length; i++) {
112
+ args.push(providedArgs[i]);
113
+ }
114
+ if (this instanceof bound) {
115
+ return new object[key](...args);
116
+ }
117
+ return object[key].apply(object, args);
118
+ };
119
+ return bound;
120
+ }
121
+ const bindKeyPlaceholder = Symbol('bindKey.placeholder');
122
+ bindKey.placeholder = bindKeyPlaceholder;
123
+
124
+ function curry(func, arity = func.length, guard) {
125
+ arity = guard ? func.length : arity;
126
+ arity = Number.parseInt(arity, 10);
127
+ if (Number.isNaN(arity) || arity < 1) {
128
+ arity = 0;
129
+ }
130
+ const wrapper = function (...partialArgs) {
131
+ const holders = partialArgs.filter(item => item === curry.placeholder);
132
+ const length = partialArgs.length - holders.length;
133
+ if (length < arity) {
134
+ return makeCurry(func, arity - length, partialArgs);
135
+ }
136
+ if (this instanceof wrapper) {
137
+ return new func(...partialArgs);
138
+ }
139
+ return func.apply(this, partialArgs);
140
+ };
141
+ wrapper.placeholder = curryPlaceholder;
142
+ return wrapper;
143
+ }
144
+ function makeCurry(func, arity, partialArgs) {
145
+ function wrapper(...providedArgs) {
146
+ const holders = providedArgs.filter(item => item === curry.placeholder);
147
+ const length = providedArgs.length - holders.length;
148
+ providedArgs = composeArgs$1(providedArgs, partialArgs);
149
+ if (length < arity) {
150
+ return makeCurry(func, arity - length, providedArgs);
151
+ }
152
+ if (this instanceof wrapper) {
153
+ return new func(...providedArgs);
154
+ }
155
+ return func.apply(this, providedArgs);
156
+ }
157
+ wrapper.placeholder = curryPlaceholder;
158
+ return wrapper;
159
+ }
160
+ function composeArgs$1(providedArgs, partialArgs) {
161
+ const args = [];
162
+ let startIndex = 0;
163
+ for (let i = 0; i < partialArgs.length; i++) {
164
+ const arg = partialArgs[i];
165
+ if (arg === curry.placeholder && startIndex < providedArgs.length) {
166
+ args.push(providedArgs[startIndex++]);
167
+ }
168
+ else {
169
+ args.push(arg);
170
+ }
171
+ }
172
+ for (let i = startIndex; i < providedArgs.length; i++) {
173
+ args.push(providedArgs[i]);
174
+ }
175
+ return args;
176
+ }
177
+ const curryPlaceholder = Symbol('curry.placeholder');
178
+ curry.placeholder = curryPlaceholder;
179
+
180
+ function curryRight(func, arity = func.length, guard) {
181
+ arity = guard ? func.length : arity;
182
+ arity = Number.parseInt(arity, 10);
183
+ if (Number.isNaN(arity) || arity < 1) {
184
+ arity = 0;
185
+ }
186
+ const wrapper = function (...partialArgs) {
187
+ const holders = partialArgs.filter(item => item === curryRight.placeholder);
188
+ const length = partialArgs.length - holders.length;
189
+ if (length < arity) {
190
+ return makeCurryRight(func, arity - length, partialArgs);
191
+ }
192
+ if (this instanceof wrapper) {
193
+ return new func(...partialArgs);
194
+ }
195
+ return func.apply(this, partialArgs);
196
+ };
197
+ wrapper.placeholder = curryRightPlaceholder;
198
+ return wrapper;
199
+ }
200
+ function makeCurryRight(func, arity, partialArgs) {
201
+ function wrapper(...providedArgs) {
202
+ const holders = providedArgs.filter(item => item === curryRight.placeholder);
203
+ const length = providedArgs.length - holders.length;
204
+ providedArgs = composeArgs(providedArgs, partialArgs);
205
+ if (length < arity) {
206
+ return makeCurryRight(func, arity - length, providedArgs);
207
+ }
208
+ if (this instanceof wrapper) {
209
+ return new func(...providedArgs);
210
+ }
211
+ return func.apply(this, providedArgs);
212
+ }
213
+ wrapper.placeholder = curryRightPlaceholder;
214
+ return wrapper;
215
+ }
216
+ function composeArgs(providedArgs, partialArgs) {
217
+ const placeholderLength = partialArgs.filter(arg => arg === curryRight.placeholder).length;
218
+ const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
219
+ const args = [];
220
+ let providedIndex = 0;
221
+ for (let i = 0; i < rangeLength; i++) {
222
+ args.push(providedArgs[providedIndex++]);
223
+ }
224
+ for (let i = 0; i < partialArgs.length; i++) {
225
+ const arg = partialArgs[i];
226
+ if (arg === curryRight.placeholder) {
227
+ if (providedIndex < providedArgs.length) {
228
+ args.push(providedArgs[providedIndex++]);
229
+ }
230
+ else {
231
+ args.push(arg);
232
+ }
233
+ }
234
+ else {
235
+ args.push(arg);
236
+ }
237
+ }
238
+ return args;
57
239
  }
240
+ const curryRightPlaceholder = Symbol('curryRight.placeholder');
241
+ curryRight.placeholder = curryRightPlaceholder;
58
242
 
59
243
  function isEqualWith(a, b, areValuesEqual) {
60
244
  return isEqualWithImpl(a, b, undefined, undefined, undefined, undefined, areValuesEqual);
@@ -234,8 +418,48 @@ function areObjectsEqual(a, b, stack, areValuesEqual) {
234
418
  }
235
419
  }
236
420
 
421
+ function isMap(value) {
422
+ return value instanceof Map;
423
+ }
424
+
425
+ function isRegExp(value) {
426
+ return value instanceof RegExp;
427
+ }
428
+
429
+ function isSet(value) {
430
+ return value instanceof Set;
431
+ }
432
+
433
+ function isWeakMap(value) {
434
+ return value instanceof WeakMap;
435
+ }
436
+
437
+ function isWeakSet(value) {
438
+ return value instanceof WeakSet;
439
+ }
440
+
441
+ function isEmpty(value) {
442
+ if (value == null) {
443
+ return true;
444
+ }
445
+ if (isArrayLike(value)) {
446
+ return value.length === 0;
447
+ }
448
+ if (value instanceof Map || value instanceof Set) {
449
+ return value.size === 0;
450
+ }
451
+ switch (typeof value) {
452
+ case 'object': {
453
+ return Object.keys(value).length === 0 && isPlainObject.getSymbols(value).length === 0;
454
+ }
455
+ default: {
456
+ return true;
457
+ }
458
+ }
459
+ }
460
+
237
461
  function isEqual(a, b) {
238
- return isEqualWith(a, b, noop.noop);
462
+ return isEqualWith(a, b, partialRight.noop);
239
463
  }
240
464
 
241
465
  function isFile(x) {
@@ -288,18 +512,6 @@ function isJSONObject(obj) {
288
512
  return true;
289
513
  }
290
514
 
291
- function isLength(value) {
292
- return Number.isSafeInteger(value) && value >= 0;
293
- }
294
-
295
- function isMap(value) {
296
- return value instanceof Map;
297
- }
298
-
299
- function isNil(x) {
300
- return x == null;
301
- }
302
-
303
515
  function isNotNil(x) {
304
516
  return x != null;
305
517
  }
@@ -308,33 +520,23 @@ function isNull(x) {
308
520
  return x === null;
309
521
  }
310
522
 
311
- function isRegExp(value) {
312
- return value instanceof RegExp;
313
- }
314
-
315
- function isSet(value) {
316
- return value instanceof Set;
317
- }
318
-
319
523
  function isUndefined(x) {
320
524
  return x === undefined;
321
525
  }
322
526
 
323
- function isWeakMap(value) {
324
- return value instanceof WeakMap;
325
- }
326
-
327
- function isWeakSet(value) {
328
- return value instanceof WeakSet;
329
- }
330
-
331
527
  exports.argumentsTag = argumentsTag;
528
+ exports.bind = bind;
529
+ exports.bindKey = bindKey;
332
530
  exports.booleanTag = booleanTag;
531
+ exports.curry = curry;
532
+ exports.curryRight = curryRight;
333
533
  exports.eq = eq;
334
534
  exports.getTag = getTag;
335
535
  exports.isArrayBuffer = isArrayBuffer;
536
+ exports.isArrayLike = isArrayLike;
336
537
  exports.isBlob = isBlob;
337
538
  exports.isDate = isDate;
539
+ exports.isEmpty = isEmpty;
338
540
  exports.isEqual = isEqual;
339
541
  exports.isEqualWith = isEqualWith;
340
542
  exports.isFile = isFile;
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ function noop() { }
4
+
5
+ function partial(func, ...partialArgs) {
6
+ return function (...providedArgs) {
7
+ const args = [];
8
+ let startIndex = 0;
9
+ for (let i = 0; i < partialArgs.length; i++) {
10
+ const arg = partialArgs[i];
11
+ if (arg === partial.placeholder) {
12
+ args.push(providedArgs[startIndex++]);
13
+ }
14
+ else {
15
+ args.push(arg);
16
+ }
17
+ }
18
+ for (let i = startIndex; i < providedArgs.length; i++) {
19
+ args.push(providedArgs[i]);
20
+ }
21
+ return func.apply(this, args);
22
+ };
23
+ }
24
+ const partialPlaceholder = Symbol('partial.placeholder');
25
+ partial.placeholder = partialPlaceholder;
26
+
27
+ function partialRight(func, ...partialArgs) {
28
+ return function (...providedArgs) {
29
+ const placeholderLength = partialArgs.filter(arg => arg === partialRightPlaceholder).length;
30
+ const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
31
+ const args = [];
32
+ let providedIndex = 0;
33
+ for (let i = 0; i < rangeLength; i++) {
34
+ args.push(providedArgs[providedIndex++]);
35
+ }
36
+ for (let i = 0; i < partialArgs.length; i++) {
37
+ const arg = partialArgs[i];
38
+ if (arg === partialRight.placeholder) {
39
+ args.push(providedArgs[providedIndex++]);
40
+ }
41
+ else {
42
+ args.push(arg);
43
+ }
44
+ }
45
+ return func.apply(this, args);
46
+ };
47
+ }
48
+ const partialRightPlaceholder = Symbol('partialRight.placeholder');
49
+ partialRight.placeholder = partialRightPlaceholder;
50
+
51
+ exports.noop = noop;
52
+ exports.partial = partial;
53
+ exports.partialRight = partialRight;
@@ -130,52 +130,6 @@ function once(func) {
130
130
  };
131
131
  }
132
132
 
133
- function partial(func, ...partialArgs) {
134
- return function (...providedArgs) {
135
- const args = [];
136
- let startIndex = 0;
137
- for (let i = 0; i < partialArgs.length; i++) {
138
- const arg = partialArgs[i];
139
- if (arg === partial.placeholder) {
140
- args.push(providedArgs[startIndex++]);
141
- }
142
- else {
143
- args.push(arg);
144
- }
145
- }
146
- for (let i = startIndex; i < providedArgs.length; i++) {
147
- args.push(providedArgs[i]);
148
- }
149
- return func.apply(this, args);
150
- };
151
- }
152
- const partialPlaceholder = Symbol('partial.placeholder');
153
- partial.placeholder = partialPlaceholder;
154
-
155
- function partialRight(func, ...partialArgs) {
156
- return function (...providedArgs) {
157
- const placeholderLength = partialArgs.filter(arg => arg === partialRightPlaceholder).length;
158
- const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
159
- const args = [];
160
- let providedIndex = 0;
161
- for (let i = 0; i < rangeLength; i++) {
162
- args.push(providedArgs[providedIndex++]);
163
- }
164
- for (let i = 0; i < partialArgs.length; i++) {
165
- const arg = partialArgs[i];
166
- if (arg === partialRight.placeholder) {
167
- args.push(providedArgs[providedIndex++]);
168
- }
169
- else {
170
- args.push(arg);
171
- }
172
- }
173
- return func.apply(this, args);
174
- };
175
- }
176
- const partialRightPlaceholder = Symbol('partialRight.placeholder');
177
- partialRight.placeholder = partialRightPlaceholder;
178
-
179
133
  function rest(func, startIndex = func.length - 1) {
180
134
  return function (...args) {
181
135
  const rest = args.slice(startIndex);
@@ -200,7 +154,5 @@ exports.identity = identity;
200
154
  exports.memoize = memoize;
201
155
  exports.negate = negate;
202
156
  exports.once = once;
203
- exports.partial = partial;
204
- exports.partialRight = partialRight;
205
157
  exports.rest = rest;
206
158
  exports.unary = unary;
@@ -18,55 +18,6 @@ function camelCase(str) {
18
18
  return `${first.toLowerCase()}${rest.map(word => capitalize(word)).join('')}`;
19
19
  }
20
20
 
21
- function constantCase(str) {
22
- const words = getWords(str);
23
- return words.map(word => word.toUpperCase()).join('_');
24
- }
25
-
26
- const deburrMap = new Map(Object.entries({
27
- Æ: 'Ae',
28
- Ð: 'D',
29
- Ø: 'O',
30
- Þ: 'Th',
31
- ß: 'ss',
32
- æ: 'ae',
33
- ð: 'd',
34
- ø: 'o',
35
- þ: 'th',
36
- Đ: 'D',
37
- đ: 'd',
38
- Ħ: 'H',
39
- ħ: 'h',
40
- ı: 'i',
41
- IJ: 'IJ',
42
- ij: 'ij',
43
- ĸ: 'k',
44
- Ŀ: 'L',
45
- ŀ: 'l',
46
- Ł: 'L',
47
- ł: 'l',
48
- ʼn: "'n",
49
- Ŋ: 'N',
50
- ŋ: 'n',
51
- Œ: 'Oe',
52
- œ: 'oe',
53
- Ŧ: 'T',
54
- ŧ: 't',
55
- ſ: 's',
56
- }));
57
- function deburr(str) {
58
- str = str.normalize('NFD');
59
- let result = '';
60
- for (let i = 0; i < str.length; i++) {
61
- const char = str[i];
62
- if ((char >= '\u0300' && char <= '\u036f') || (char >= '\ufe20' && char <= '\ufe23')) {
63
- continue;
64
- }
65
- result += deburrMap.get(char) ?? char;
66
- }
67
- return result;
68
- }
69
-
70
21
  const htmlEscapes = {
71
22
  '&': '&amp;',
72
23
  '<': '&lt;',
@@ -78,10 +29,6 @@ function escape(str) {
78
29
  return str.replace(/[&<>"']/g, match => htmlEscapes[match]);
79
30
  }
80
31
 
81
- function escapeRegExp(str) {
82
- return str.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
83
- }
84
-
85
32
  function kebabCase(str) {
86
33
  const words = getWords(str);
87
34
  return words.map(word => word.toLowerCase()).join('-');
@@ -92,19 +39,10 @@ function lowerCase(str) {
92
39
  return words.map(word => word.toLowerCase()).join(' ');
93
40
  }
94
41
 
95
- function lowerFirst(str) {
96
- return str.substring(0, 1).toLowerCase() + str.substring(1);
97
- }
98
-
99
42
  function pad(str, length, chars = ' ') {
100
43
  return str.padStart(Math.floor((length - str.length) / 2) + str.length, chars).padEnd(length, chars);
101
44
  }
102
45
 
103
- function pascalCase(str) {
104
- const words = getWords(str);
105
- return words.map(word => capitalize(word)).join('');
106
- }
107
-
108
46
  function snakeCase(str) {
109
47
  const words = getWords(str);
110
48
  return words.map(word => word.toLowerCase()).join('_');
@@ -159,17 +97,6 @@ function trim(str, chars) {
159
97
  return trimStart(trimEnd(str, chars), chars);
160
98
  }
161
99
 
162
- const htmlUnescapes = {
163
- '&amp;': '&',
164
- '&lt;': '<',
165
- '&gt;': '>',
166
- '&quot;': '"',
167
- '&#39;': "'",
168
- };
169
- function unescape(str) {
170
- return str.replace(/&(?:amp|lt|gt|quot|#(0+)?39);/g, match => htmlUnescapes[match] || "'");
171
- }
172
-
173
100
  function upperCase(str) {
174
101
  const words = getWords(str);
175
102
  let result = '';
@@ -182,6 +109,35 @@ function upperCase(str) {
182
109
  return result;
183
110
  }
184
111
 
112
+ function constantCase(str) {
113
+ const words = getWords(str);
114
+ return words.map(word => word.toUpperCase()).join('_');
115
+ }
116
+
117
+ function escapeRegExp(str) {
118
+ return str.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
119
+ }
120
+
121
+ function lowerFirst(str) {
122
+ return str.substring(0, 1).toLowerCase() + str.substring(1);
123
+ }
124
+
125
+ function pascalCase(str) {
126
+ const words = getWords(str);
127
+ return words.map(word => capitalize(word)).join('');
128
+ }
129
+
130
+ const htmlUnescapes = {
131
+ '&amp;': '&',
132
+ '&lt;': '<',
133
+ '&gt;': '>',
134
+ '&quot;': '"',
135
+ '&#39;': "'",
136
+ };
137
+ function unescape(str) {
138
+ return str.replace(/&(?:amp|lt|gt|quot|#(0+)?39);/g, match => htmlUnescapes[match] || "'");
139
+ }
140
+
185
141
  function upperFirst(str) {
186
142
  return str.substring(0, 1).toUpperCase() + str.substring(1);
187
143
  }
@@ -189,7 +145,6 @@ function upperFirst(str) {
189
145
  exports.camelCase = camelCase;
190
146
  exports.capitalize = capitalize;
191
147
  exports.constantCase = constantCase;
192
- exports.deburr = deburr;
193
148
  exports.escape = escape;
194
149
  exports.escapeRegExp = escapeRegExp;
195
150
  exports.getWords = getWords;