es-toolkit 1.23.0-dev.734 → 1.23.0-dev.736

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);
@@ -173,26 +127,6 @@ function rest(func, startIndex = func.length - 1) {
173
127
  };
174
128
  }
175
129
 
176
- function curryRight(func) {
177
- if (func.length === 0 || func.length === 1) {
178
- return func;
179
- }
180
- return function (arg) {
181
- return makeCurryRight(func, func.length, [arg]);
182
- };
183
- }
184
- function makeCurryRight(origin, argsLength, args) {
185
- if (args.length === argsLength) {
186
- return origin(...args);
187
- }
188
- else {
189
- const next = function (arg) {
190
- return makeCurryRight(origin, argsLength, [arg, ...args]);
191
- };
192
- return next;
193
- }
194
- }
195
-
196
130
  function flow(...funcs) {
197
131
  return function (...args) {
198
132
  let result = funcs.length ? funcs[0].apply(this, args) : args[0];
@@ -209,14 +143,11 @@ function flowRight(...funcs) {
209
143
 
210
144
  exports.after = after;
211
145
  exports.ary = ary;
212
- exports.curryRight = curryRight;
213
146
  exports.debounce = debounce;
214
147
  exports.flow = flow;
215
148
  exports.flowRight = flowRight;
216
149
  exports.memoize = memoize;
217
150
  exports.negate = negate;
218
151
  exports.once = once;
219
- exports.partial = partial;
220
- exports.partialRight = partialRight;
221
152
  exports.rest = rest;
222
153
  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,205 @@ 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$1(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$1(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 curryRight(func, arity = func.length, guard) {
170
+ arity = guard ? func.length : arity;
171
+ arity = Number.parseInt(arity, 10);
172
+ if (Number.isNaN(arity) || arity < 1) {
173
+ arity = 0;
174
+ }
175
+ const wrapper = function (...partialArgs) {
176
+ const holders = partialArgs.filter(item => item === curryRight.placeholder);
177
+ const length = partialArgs.length - holders.length;
178
+ if (length < arity) {
179
+ return makeCurryRight(func, arity - length, partialArgs);
180
+ }
181
+ if (this instanceof wrapper) {
182
+ return new func(...partialArgs);
183
+ }
184
+ return func.apply(this, partialArgs);
185
+ };
186
+ wrapper.placeholder = curryRightPlaceholder;
187
+ return wrapper;
188
+ }
189
+ function makeCurryRight(func, arity, partialArgs) {
190
+ function wrapper(...providedArgs) {
191
+ const holders = providedArgs.filter(item => item === curryRight.placeholder);
192
+ const length = providedArgs.length - holders.length;
193
+ providedArgs = composeArgs(providedArgs, partialArgs);
194
+ if (length < arity) {
195
+ return makeCurryRight(func, arity - length, providedArgs);
196
+ }
197
+ if (this instanceof wrapper) {
198
+ return new func(...providedArgs);
199
+ }
200
+ return func.apply(this, providedArgs);
201
+ }
202
+ wrapper.placeholder = curryRightPlaceholder;
203
+ return wrapper;
204
+ }
205
+ function composeArgs(providedArgs, partialArgs) {
206
+ const placeholderLength = partialArgs.filter(arg => arg === curryRight.placeholder).length;
207
+ const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
208
+ const args = [];
209
+ let providedIndex = 0;
210
+ for (let i = 0; i < rangeLength; i++) {
211
+ args.push(providedArgs[providedIndex++]);
212
+ }
213
+ for (let i = 0; i < partialArgs.length; i++) {
214
+ const arg = partialArgs[i];
215
+ if (arg === curryRight.placeholder) {
216
+ if (providedIndex < providedArgs.length) {
217
+ args.push(providedArgs[providedIndex++]);
218
+ }
219
+ else {
220
+ args.push(arg);
221
+ }
222
+ }
223
+ else {
224
+ args.push(arg);
225
+ }
226
+ }
227
+ return args;
228
+ }
229
+ const curryRightPlaceholder = Symbol('curryRight.placeholder');
230
+ curryRight.placeholder = curryRightPlaceholder;
231
+
232
+ function isLength(value) {
233
+ return Number.isSafeInteger(value) && value >= 0;
234
+ }
235
+
236
+ function isSet(value) {
237
+ return value instanceof Set;
238
+ }
239
+
240
+ function isRegExp(value) {
241
+ return value instanceof RegExp;
242
+ }
243
+
244
+ function isWeakMap(value) {
245
+ return value instanceof WeakMap;
246
+ }
247
+
248
+ function isWeakSet(value) {
249
+ return value instanceof WeakSet;
250
+ }
251
+
52
252
  function isEqualWith(a, b, areValuesEqual) {
53
253
  return isEqualWithImpl(a, b, undefined, undefined, undefined, undefined, areValuesEqual);
54
254
  }
@@ -100,7 +300,7 @@ function areObjectsEqual(a, b, stack, areValuesEqual) {
100
300
  case numberTag: {
101
301
  const x = a.valueOf();
102
302
  const y = b.valueOf();
103
- return x === y || (Number.isNaN(x) && Number.isNaN(y));
303
+ return eq(x, y);
104
304
  }
105
305
  case booleanTag:
106
306
  case dateTag:
@@ -228,17 +428,13 @@ function areObjectsEqual(a, b, stack, areValuesEqual) {
228
428
  }
229
429
 
230
430
  function isEqual(a, b) {
231
- return isEqualWith(a, b, noop.noop);
431
+ return isEqualWith(a, b, partialRight.noop);
232
432
  }
233
433
 
234
434
  function isMap(value) {
235
435
  return value instanceof Map;
236
436
  }
237
437
 
238
- function isNil(x) {
239
- return x == null;
240
- }
241
-
242
438
  function isNotNil(x) {
243
439
  return x != null;
244
440
  }
@@ -251,18 +447,10 @@ function isUndefined(x) {
251
447
  return x === undefined;
252
448
  }
253
449
 
254
- function isLength(value) {
255
- return Number.isSafeInteger(value) && value >= 0;
256
- }
257
-
258
450
  function isFunction(value) {
259
451
  return typeof value === 'function';
260
452
  }
261
453
 
262
- function isRegExp(value) {
263
- return value instanceof RegExp;
264
- }
265
-
266
454
  function isJSONArray(value) {
267
455
  if (!Array.isArray(value)) {
268
456
  return false;
@@ -304,20 +492,13 @@ function isJSONObject(obj) {
304
492
  return true;
305
493
  }
306
494
 
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
495
  exports.argumentsTag = argumentsTag;
496
+ exports.bind = bind;
497
+ exports.bindKey = bindKey;
320
498
  exports.booleanTag = booleanTag;
499
+ exports.curry = curry;
500
+ exports.curryRight = curryRight;
501
+ exports.eq = eq;
321
502
  exports.getSymbols = getSymbols;
322
503
  exports.getTag = getTag;
323
504
  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;