es-toolkit 1.23.0-dev.733 → 1.23.0-dev.735

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;
@@ -116,52 +116,6 @@ function unary(func) {
116
116
  return ary(func, 1);
117
117
  }
118
118
 
119
- function partial(func, ...partialArgs) {
120
- return function (...providedArgs) {
121
- const args = [];
122
- let startIndex = 0;
123
- for (let i = 0; i < partialArgs.length; i++) {
124
- const arg = partialArgs[i];
125
- if (arg === partial.placeholder) {
126
- args.push(providedArgs[startIndex++]);
127
- }
128
- else {
129
- args.push(arg);
130
- }
131
- }
132
- for (let i = startIndex; i < providedArgs.length; i++) {
133
- args.push(providedArgs[i]);
134
- }
135
- return func.apply(this, args);
136
- };
137
- }
138
- const partialPlaceholder = Symbol('partial.placeholder');
139
- partial.placeholder = partialPlaceholder;
140
-
141
- function partialRight(func, ...partialArgs) {
142
- return function (...providedArgs) {
143
- const placeholderLength = partialArgs.filter(arg => arg === partialRightPlaceholder).length;
144
- const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
145
- const args = [];
146
- let providedIndex = 0;
147
- for (let i = 0; i < rangeLength; i++) {
148
- args.push(providedArgs[providedIndex++]);
149
- }
150
- for (let i = 0; i < partialArgs.length; i++) {
151
- const arg = partialArgs[i];
152
- if (arg === partialRight.placeholder) {
153
- args.push(providedArgs[providedIndex++]);
154
- }
155
- else {
156
- args.push(arg);
157
- }
158
- }
159
- return func.apply(this, args);
160
- };
161
- }
162
- const partialRightPlaceholder = Symbol('partialRight.placeholder');
163
- partialRight.placeholder = partialRightPlaceholder;
164
-
165
119
  function rest(func, startIndex = func.length - 1) {
166
120
  return function (...args) {
167
121
  const rest = args.slice(startIndex);
@@ -216,7 +170,5 @@ exports.flowRight = flowRight;
216
170
  exports.memoize = memoize;
217
171
  exports.negate = negate;
218
172
  exports.once = once;
219
- exports.partial = partial;
220
- exports.partialRight = partialRight;
221
173
  exports.rest = rest;
222
174
  exports.unary = unary;
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  const isPlainObject = require('./isPlainObject-DgrsU7.js');
4
- const noop = require('./noop-2IwLUk.js');
4
+ const partialRight = require('./partialRight-CRhV1h.js');
5
+ require('./deburr-BPmkoM.js');
5
6
 
6
7
  function isArrayBuffer(value) {
7
8
  return value instanceof ArrayBuffer;
@@ -49,6 +50,142 @@ const bigInt64ArrayTag = '[object BigInt64Array]';
49
50
  const float32ArrayTag = '[object Float32Array]';
50
51
  const float64ArrayTag = '[object Float64Array]';
51
52
 
53
+ function eq(value, other) {
54
+ return value === other || (Number.isNaN(value) && Number.isNaN(other));
55
+ }
56
+
57
+ function isNil(x) {
58
+ return x == null;
59
+ }
60
+
61
+ function bind(func, thisObj, ...partialArgs) {
62
+ const bound = function (...providedArgs) {
63
+ const args = [];
64
+ let startIndex = 0;
65
+ for (let i = 0; i < partialArgs.length; i++) {
66
+ const arg = partialArgs[i];
67
+ if (arg === bind.placeholder) {
68
+ args.push(providedArgs[startIndex++]);
69
+ }
70
+ else {
71
+ args.push(arg);
72
+ }
73
+ }
74
+ for (let i = startIndex; i < providedArgs.length; i++) {
75
+ args.push(providedArgs[i]);
76
+ }
77
+ if (this instanceof bound) {
78
+ return new func(...args);
79
+ }
80
+ return func.apply(thisObj, args);
81
+ };
82
+ return bound;
83
+ }
84
+ const bindPlaceholder = Symbol('bind.placeholder');
85
+ bind.placeholder = bindPlaceholder;
86
+
87
+ function bindKey(object, key, ...partialArgs) {
88
+ const bound = function (...providedArgs) {
89
+ const args = [];
90
+ let startIndex = 0;
91
+ for (let i = 0; i < partialArgs.length; i++) {
92
+ const arg = partialArgs[i];
93
+ if (arg === bindKey.placeholder) {
94
+ args.push(providedArgs[startIndex++]);
95
+ }
96
+ else {
97
+ args.push(arg);
98
+ }
99
+ }
100
+ for (let i = startIndex; i < providedArgs.length; i++) {
101
+ args.push(providedArgs[i]);
102
+ }
103
+ if (this instanceof bound) {
104
+ return new object[key](...args);
105
+ }
106
+ return object[key].apply(object, args);
107
+ };
108
+ return bound;
109
+ }
110
+ const bindKeyPlaceholder = Symbol('bindKey.placeholder');
111
+ bindKey.placeholder = bindKeyPlaceholder;
112
+
113
+ function curry(func, arity = func.length, guard) {
114
+ arity = guard ? func.length : arity;
115
+ arity = Number.parseInt(arity, 10);
116
+ if (Number.isNaN(arity) || arity < 1) {
117
+ arity = 0;
118
+ }
119
+ const wrapper = function (...partialArgs) {
120
+ const holders = partialArgs.filter(item => item === curry.placeholder);
121
+ const length = partialArgs.length - holders.length;
122
+ if (length < arity) {
123
+ return makeCurry(func, arity - length, partialArgs);
124
+ }
125
+ if (this instanceof wrapper) {
126
+ return new func(...partialArgs);
127
+ }
128
+ return func.apply(this, partialArgs);
129
+ };
130
+ wrapper.placeholder = curryPlaceholder;
131
+ return wrapper;
132
+ }
133
+ function makeCurry(func, arity, partialArgs) {
134
+ function wrapper(...providedArgs) {
135
+ const holders = providedArgs.filter(item => item === curry.placeholder);
136
+ const length = providedArgs.length - holders.length;
137
+ providedArgs = composeArgs(providedArgs, partialArgs);
138
+ if (length < arity) {
139
+ return makeCurry(func, arity - length, providedArgs);
140
+ }
141
+ if (this instanceof wrapper) {
142
+ return new func(...providedArgs);
143
+ }
144
+ return func.apply(this, providedArgs);
145
+ }
146
+ wrapper.placeholder = curryPlaceholder;
147
+ return wrapper;
148
+ }
149
+ function composeArgs(providedArgs, partialArgs) {
150
+ const args = [];
151
+ let startIndex = 0;
152
+ for (let i = 0; i < partialArgs.length; i++) {
153
+ const arg = partialArgs[i];
154
+ if (arg === curry.placeholder && startIndex < providedArgs.length) {
155
+ args.push(providedArgs[startIndex++]);
156
+ }
157
+ else {
158
+ args.push(arg);
159
+ }
160
+ }
161
+ for (let i = startIndex; i < providedArgs.length; i++) {
162
+ args.push(providedArgs[i]);
163
+ }
164
+ return args;
165
+ }
166
+ const curryPlaceholder = Symbol('curry.placeholder');
167
+ curry.placeholder = curryPlaceholder;
168
+
169
+ function isLength(value) {
170
+ return Number.isSafeInteger(value) && value >= 0;
171
+ }
172
+
173
+ function isSet(value) {
174
+ return value instanceof Set;
175
+ }
176
+
177
+ function isRegExp(value) {
178
+ return value instanceof RegExp;
179
+ }
180
+
181
+ function isWeakMap(value) {
182
+ return value instanceof WeakMap;
183
+ }
184
+
185
+ function isWeakSet(value) {
186
+ return value instanceof WeakSet;
187
+ }
188
+
52
189
  function isEqualWith(a, b, areValuesEqual) {
53
190
  return isEqualWithImpl(a, b, undefined, undefined, undefined, undefined, areValuesEqual);
54
191
  }
@@ -100,7 +237,7 @@ function areObjectsEqual(a, b, stack, areValuesEqual) {
100
237
  case numberTag: {
101
238
  const x = a.valueOf();
102
239
  const y = b.valueOf();
103
- return x === y || (Number.isNaN(x) && Number.isNaN(y));
240
+ return eq(x, y);
104
241
  }
105
242
  case booleanTag:
106
243
  case dateTag:
@@ -228,17 +365,13 @@ function areObjectsEqual(a, b, stack, areValuesEqual) {
228
365
  }
229
366
 
230
367
  function isEqual(a, b) {
231
- return isEqualWith(a, b, noop.noop);
368
+ return isEqualWith(a, b, partialRight.noop);
232
369
  }
233
370
 
234
371
  function isMap(value) {
235
372
  return value instanceof Map;
236
373
  }
237
374
 
238
- function isNil(x) {
239
- return x == null;
240
- }
241
-
242
375
  function isNotNil(x) {
243
376
  return x != null;
244
377
  }
@@ -251,18 +384,10 @@ function isUndefined(x) {
251
384
  return x === undefined;
252
385
  }
253
386
 
254
- function isLength(value) {
255
- return Number.isSafeInteger(value) && value >= 0;
256
- }
257
-
258
387
  function isFunction(value) {
259
388
  return typeof value === 'function';
260
389
  }
261
390
 
262
- function isRegExp(value) {
263
- return value instanceof RegExp;
264
- }
265
-
266
391
  function isJSONArray(value) {
267
392
  if (!Array.isArray(value)) {
268
393
  return false;
@@ -304,20 +429,12 @@ function isJSONObject(obj) {
304
429
  return true;
305
430
  }
306
431
 
307
- function isSet(value) {
308
- return value instanceof Set;
309
- }
310
-
311
- function isWeakMap(value) {
312
- return value instanceof WeakMap;
313
- }
314
-
315
- function isWeakSet(value) {
316
- return value instanceof WeakSet;
317
- }
318
-
319
432
  exports.argumentsTag = argumentsTag;
433
+ exports.bind = bind;
434
+ exports.bindKey = bindKey;
320
435
  exports.booleanTag = booleanTag;
436
+ exports.curry = curry;
437
+ exports.eq = eq;
321
438
  exports.getSymbols = getSymbols;
322
439
  exports.getTag = getTag;
323
440
  exports.isArrayBuffer = isArrayBuffer;
@@ -18,14 +18,19 @@ function camelCase(str) {
18
18
  return `${first.toLowerCase()}${rest.map(word => capitalize(word)).join('')}`;
19
19
  }
20
20
 
21
+ function kebabCase(str) {
22
+ const words = getWords(str);
23
+ return words.map(word => word.toLowerCase()).join('-');
24
+ }
25
+
21
26
  function snakeCase(str) {
22
27
  const words = getWords(str);
23
28
  return words.map(word => word.toLowerCase()).join('_');
24
29
  }
25
30
 
26
- function kebabCase(str) {
31
+ function lowerCase(str) {
27
32
  const words = getWords(str);
28
- return words.map(word => word.toLowerCase()).join('-');
33
+ return words.map(word => word.toLowerCase()).join(' ');
29
34
  }
30
35
 
31
36
  function upperCase(str) {
@@ -40,11 +45,6 @@ function upperCase(str) {
40
45
  return result;
41
46
  }
42
47
 
43
- function lowerCase(str) {
44
- const words = getWords(str);
45
- return words.map(word => word.toLowerCase()).join(' ');
46
- }
47
-
48
48
  function pascalCase(str) {
49
49
  const words = getWords(str);
50
50
  return words.map(word => capitalize(word)).join('');
@@ -112,50 +112,6 @@ function lowerFirst(str) {
112
112
  return str.substring(0, 1).toLowerCase() + str.substring(1);
113
113
  }
114
114
 
115
- const deburrMap = new Map(Object.entries({
116
- Æ: 'Ae',
117
- Ð: 'D',
118
- Ø: 'O',
119
- Þ: 'Th',
120
- ß: 'ss',
121
- æ: 'ae',
122
- ð: 'd',
123
- ø: 'o',
124
- þ: 'th',
125
- Đ: 'D',
126
- đ: 'd',
127
- Ħ: 'H',
128
- ħ: 'h',
129
- ı: 'i',
130
- IJ: 'IJ',
131
- ij: 'ij',
132
- ĸ: 'k',
133
- Ŀ: 'L',
134
- ŀ: 'l',
135
- Ł: 'L',
136
- ł: 'l',
137
- ʼn: "'n",
138
- Ŋ: 'N',
139
- ŋ: 'n',
140
- Œ: 'Oe',
141
- œ: 'oe',
142
- Ŧ: 'T',
143
- ŧ: 't',
144
- ſ: 's',
145
- }));
146
- function deburr(str) {
147
- str = str.normalize('NFD');
148
- let result = '';
149
- for (let i = 0; i < str.length; i++) {
150
- const char = str[i];
151
- if ((char >= '\u0300' && char <= '\u036f') || (char >= '\ufe20' && char <= '\ufe23')) {
152
- continue;
153
- }
154
- result += deburrMap.get(char) ?? char;
155
- }
156
- return result;
157
- }
158
-
159
115
  const htmlEscapes = {
160
116
  '&': '&amp;',
161
117
  '<': '&lt;',
@@ -189,7 +145,6 @@ function pad(str, length, chars = ' ') {
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;
@@ -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;
@@ -59,10 +59,30 @@ function range(start, end, step) {
59
59
  return result;
60
60
  }
61
61
 
62
+ function rangeRight(start, end, step) {
63
+ if (end == null) {
64
+ end = start;
65
+ start = 0;
66
+ }
67
+ if (step == null) {
68
+ step = 1;
69
+ }
70
+ if (!Number.isInteger(step) || step === 0) {
71
+ throw new Error(`The step value must be a non-zero integer.`);
72
+ }
73
+ const length = Math.max(Math.ceil((end - start) / step), 0);
74
+ const result = new Array(length);
75
+ for (let i = 0; i < length; i++) {
76
+ result[i] = start + (length - i - 1) * step;
77
+ }
78
+ return result;
79
+ }
80
+
62
81
  exports.clamp = clamp;
63
82
  exports.inRange = inRange;
64
83
  exports.mean = mean;
65
84
  exports.meanBy = meanBy;
66
85
  exports.range = range;
86
+ exports.rangeRight = rangeRight;
67
87
  exports.sum = sum;
68
88
  exports.sumBy = sumBy;