es-toolkit 1.21.0 → 1.22.0

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 (66) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/_chunk/{rest-pUyjvl.js → flowRight-BzdOZX.js} +16 -0
  3. package/dist/_chunk/{isWeakSet-1xFSnK.js → isWeakSet-clQklw.js} +10 -0
  4. package/dist/_chunk/pad-Cw2pvt.js +207 -0
  5. package/dist/_chunk/{toMerged-D-sLFv.js → toMerged-2WPeoI.js} +5 -2
  6. package/dist/_chunk/{zipWith-DEcUS4.js → zipWith-EOU_KZ.js} +1 -1
  7. package/dist/array/dropWhile.d.mts +1 -1
  8. package/dist/array/dropWhile.d.ts +1 -1
  9. package/dist/array/dropWhile.mjs +1 -1
  10. package/dist/array/index.js +1 -1
  11. package/dist/browser.global.js +1 -1
  12. package/dist/browser.global.js.map +1 -1
  13. package/dist/compat/array/dropWhile.d.mts +40 -0
  14. package/dist/compat/array/dropWhile.d.ts +40 -0
  15. package/dist/compat/array/dropWhile.mjs +27 -0
  16. package/dist/compat/array/every.d.mts +139 -0
  17. package/dist/compat/array/every.d.ts +139 -0
  18. package/dist/compat/array/every.mjs +49 -0
  19. package/dist/compat/array/filter.d.mts +118 -0
  20. package/dist/compat/array/filter.d.ts +118 -0
  21. package/dist/compat/array/filter.mjs +27 -0
  22. package/dist/compat/array/find.d.mts +1 -1
  23. package/dist/compat/array/find.d.ts +1 -1
  24. package/dist/compat/array/includes.d.mts +62 -0
  25. package/dist/compat/array/includes.d.ts +62 -0
  26. package/dist/compat/array/includes.mjs +42 -0
  27. package/dist/compat/function/flip.d.mts +20 -0
  28. package/dist/compat/function/flip.d.ts +20 -0
  29. package/dist/compat/function/flip.mjs +7 -0
  30. package/dist/compat/index.d.mts +9 -1
  31. package/dist/compat/index.d.ts +9 -1
  32. package/dist/compat/index.js +247 -97
  33. package/dist/compat/index.mjs +9 -1
  34. package/dist/compat/string/startCase.mjs +16 -2
  35. package/dist/compat/util/toInteger.d.mts +3 -0
  36. package/dist/compat/util/toInteger.d.ts +3 -0
  37. package/dist/function/flow.d.mts +132 -0
  38. package/dist/function/flow.d.ts +132 -0
  39. package/dist/function/flow.mjs +11 -0
  40. package/dist/function/flowRight.d.mts +144 -0
  41. package/dist/function/flowRight.d.ts +144 -0
  42. package/dist/function/flowRight.mjs +7 -0
  43. package/dist/function/index.d.mts +2 -0
  44. package/dist/function/index.d.ts +2 -0
  45. package/dist/function/index.js +17 -14
  46. package/dist/function/index.mjs +2 -0
  47. package/dist/function/throttle.mjs +1 -0
  48. package/dist/index.d.mts +4 -0
  49. package/dist/index.d.ts +4 -0
  50. package/dist/index.js +39 -34
  51. package/dist/index.mjs +4 -0
  52. package/dist/object/clone.mjs +4 -1
  53. package/dist/object/cloneDeep.mjs +1 -1
  54. package/dist/object/index.js +1 -1
  55. package/dist/predicate/index.d.mts +2 -0
  56. package/dist/predicate/index.d.ts +2 -0
  57. package/dist/predicate/index.js +3 -1
  58. package/dist/predicate/index.mjs +2 -0
  59. package/dist/predicate/isMap.d.mts +20 -0
  60. package/dist/predicate/isMap.d.ts +20 -0
  61. package/dist/predicate/isMap.mjs +5 -0
  62. package/dist/predicate/isSet.d.mts +20 -0
  63. package/dist/predicate/isSet.d.ts +20 -0
  64. package/dist/predicate/isSet.mjs +5 -0
  65. package/dist/string/index.js +20 -204
  66. package/package.json +2 -2
package/dist/index.d.mts CHANGED
@@ -71,6 +71,8 @@ export { partialRight } from './function/partialRight.mjs';
71
71
  export { rest } from './function/rest.mjs';
72
72
  export { curry } from './function/curry.mjs';
73
73
  export { spread } from './function/spread.mjs';
74
+ export { flow } from './function/flow.mjs';
75
+ export { flowRight } from './function/flowRight.mjs';
74
76
  export { clamp } from './math/clamp.mjs';
75
77
  export { inRange } from './math/inRange.mjs';
76
78
  export { mean } from './math/mean.mjs';
@@ -97,6 +99,7 @@ export { mergeWith } from './object/mergeWith.mjs';
97
99
  export { isDate } from './predicate/isDate.mjs';
98
100
  export { isEqual } from './predicate/isEqual.mjs';
99
101
  export { isError } from './predicate/isError.mjs';
102
+ export { isMap } from './predicate/isMap.mjs';
100
103
  export { isNil } from './predicate/isNil.mjs';
101
104
  export { isNotNil } from './predicate/isNotNil.mjs';
102
105
  export { isNull } from './predicate/isNull.mjs';
@@ -110,6 +113,7 @@ export { isRegExp } from './predicate/isRegExp.mjs';
110
113
  export { isBoolean } from './predicate/isBoolean.mjs';
111
114
  export { isSymbol } from './predicate/isSymbol.mjs';
112
115
  export { isString } from './predicate/isString.mjs';
116
+ export { isSet } from './predicate/isSet.mjs';
113
117
  export { isWeakMap } from './predicate/isWeakMap.mjs';
114
118
  export { isWeakSet } from './predicate/isWeakSet.mjs';
115
119
  export { delay } from './promise/delay.mjs';
package/dist/index.d.ts CHANGED
@@ -71,6 +71,8 @@ export { partialRight } from './function/partialRight.js';
71
71
  export { rest } from './function/rest.js';
72
72
  export { curry } from './function/curry.js';
73
73
  export { spread } from './function/spread.js';
74
+ export { flow } from './function/flow.js';
75
+ export { flowRight } from './function/flowRight.js';
74
76
  export { clamp } from './math/clamp.js';
75
77
  export { inRange } from './math/inRange.js';
76
78
  export { mean } from './math/mean.js';
@@ -97,6 +99,7 @@ export { mergeWith } from './object/mergeWith.js';
97
99
  export { isDate } from './predicate/isDate.js';
98
100
  export { isEqual } from './predicate/isEqual.js';
99
101
  export { isError } from './predicate/isError.js';
102
+ export { isMap } from './predicate/isMap.js';
100
103
  export { isNil } from './predicate/isNil.js';
101
104
  export { isNotNil } from './predicate/isNotNil.js';
102
105
  export { isNull } from './predicate/isNull.js';
@@ -110,6 +113,7 @@ export { isRegExp } from './predicate/isRegExp.js';
110
113
  export { isBoolean } from './predicate/isBoolean.js';
111
114
  export { isSymbol } from './predicate/isSymbol.js';
112
115
  export { isString } from './predicate/isString.js';
116
+ export { isSet } from './predicate/isSet.js';
113
117
  export { isWeakMap } from './predicate/isWeakMap.js';
114
118
  export { isWeakSet } from './predicate/isWeakSet.js';
115
119
  export { delay } from './promise/delay.js';
package/dist/index.js CHANGED
@@ -2,19 +2,20 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const zipWith = require('./_chunk/zipWith-DEcUS4.js');
5
+ const zipWith = require('./_chunk/zipWith-EOU_KZ.js');
6
6
  const array_index = require('./array/index.js');
7
7
  const promise_index = require('./_chunk/index-BGZDR9.js');
8
- const rest = require('./_chunk/rest-pUyjvl.js');
8
+ const flowRight = require('./_chunk/flowRight-BzdOZX.js');
9
9
  const function_index = require('./function/index.js');
10
10
  const range = require('./_chunk/range-BXlMmn.js');
11
11
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
12
12
  const math_index = require('./math/index.js');
13
13
  const object_index = require('./object/index.js');
14
- const toMerged = require('./_chunk/toMerged-D-sLFv.js');
15
- const isWeakSet = require('./_chunk/isWeakSet-1xFSnK.js');
14
+ const toMerged = require('./_chunk/toMerged-2WPeoI.js');
15
+ const isWeakSet = require('./_chunk/isWeakSet-clQklw.js');
16
16
  const predicate_index = require('./predicate/index.js');
17
17
  const isPlainObject = require('./_chunk/isPlainObject-BIekvL.js');
18
+ const pad = require('./_chunk/pad-Cw2pvt.js');
18
19
  const string_index = require('./string/index.js');
19
20
 
20
21
 
@@ -80,18 +81,20 @@ exports.TimeoutError = promise_index.TimeoutError;
80
81
  exports.delay = promise_index.delay;
81
82
  exports.timeout = promise_index.timeout;
82
83
  exports.withTimeout = promise_index.withTimeout;
83
- exports.after = rest.after;
84
- exports.ary = rest.ary;
85
- exports.before = rest.before;
86
- exports.debounce = rest.debounce;
87
- exports.memoize = rest.memoize;
88
- exports.negate = rest.negate;
89
- exports.noop = rest.noop;
90
- exports.once = rest.once;
91
- exports.partial = rest.partial;
92
- exports.partialRight = rest.partialRight;
93
- exports.rest = rest.rest;
94
- exports.unary = rest.unary;
84
+ exports.after = flowRight.after;
85
+ exports.ary = flowRight.ary;
86
+ exports.before = flowRight.before;
87
+ exports.debounce = flowRight.debounce;
88
+ exports.flow = flowRight.flow;
89
+ exports.flowRight = flowRight.flowRight;
90
+ exports.memoize = flowRight.memoize;
91
+ exports.negate = flowRight.negate;
92
+ exports.noop = flowRight.noop;
93
+ exports.once = flowRight.once;
94
+ exports.partial = flowRight.partial;
95
+ exports.partialRight = flowRight.partialRight;
96
+ exports.rest = flowRight.rest;
97
+ exports.unary = flowRight.unary;
95
98
  exports.curry = function_index.curry;
96
99
  exports.spread = function_index.spread;
97
100
  exports.throttle = function_index.throttle;
@@ -122,10 +125,12 @@ exports.isDate = isWeakSet.isDate;
122
125
  exports.isEqual = isWeakSet.isEqual;
123
126
  exports.isFunction = isWeakSet.isFunction;
124
127
  exports.isLength = isWeakSet.isLength;
128
+ exports.isMap = isWeakSet.isMap;
125
129
  exports.isNil = isWeakSet.isNil;
126
130
  exports.isNotNil = isWeakSet.isNotNil;
127
131
  exports.isNull = isWeakSet.isNull;
128
132
  exports.isRegExp = isWeakSet.isRegExp;
133
+ exports.isSet = isWeakSet.isSet;
129
134
  exports.isUndefined = isWeakSet.isUndefined;
130
135
  exports.isWeakMap = isWeakSet.isWeakMap;
131
136
  exports.isWeakSet = isWeakSet.isWeakSet;
@@ -136,22 +141,22 @@ exports.isSymbol = predicate_index.isSymbol;
136
141
  exports.isPlainObject = isPlainObject.isPlainObject;
137
142
  exports.isPrimitive = isPlainObject.isPrimitive;
138
143
  exports.isTypedArray = isPlainObject.isTypedArray;
139
- exports.camelCase = string_index.camelCase;
140
- exports.capitalize = string_index.capitalize;
141
- exports.constantCase = string_index.constantCase;
142
- exports.deburr = string_index.deburr;
143
- exports.escape = string_index.escape;
144
- exports.escapeRegExp = string_index.escapeRegExp;
145
- exports.kebabCase = string_index.kebabCase;
146
- exports.lowerCase = string_index.lowerCase;
147
- exports.lowerFirst = string_index.lowerFirst;
148
- exports.pad = string_index.pad;
149
- exports.pascalCase = string_index.pascalCase;
150
- exports.snakeCase = string_index.snakeCase;
144
+ exports.camelCase = pad.camelCase;
145
+ exports.capitalize = pad.capitalize;
146
+ exports.constantCase = pad.constantCase;
147
+ exports.deburr = pad.deburr;
148
+ exports.escape = pad.escape;
149
+ exports.escapeRegExp = pad.escapeRegExp;
150
+ exports.kebabCase = pad.kebabCase;
151
+ exports.lowerCase = pad.lowerCase;
152
+ exports.lowerFirst = pad.lowerFirst;
153
+ exports.pad = pad.pad;
154
+ exports.pascalCase = pad.pascalCase;
155
+ exports.snakeCase = pad.snakeCase;
156
+ exports.trim = pad.trim;
157
+ exports.trimEnd = pad.trimEnd;
158
+ exports.trimStart = pad.trimStart;
159
+ exports.unescape = pad.unescape;
160
+ exports.upperCase = pad.upperCase;
161
+ exports.upperFirst = pad.upperFirst;
151
162
  exports.startCase = string_index.startCase;
152
- exports.trim = string_index.trim;
153
- exports.trimEnd = string_index.trimEnd;
154
- exports.trimStart = string_index.trimStart;
155
- exports.unescape = string_index.unescape;
156
- exports.upperCase = string_index.upperCase;
157
- exports.upperFirst = string_index.upperFirst;
package/dist/index.mjs CHANGED
@@ -71,6 +71,8 @@ export { partialRight } from './function/partialRight.mjs';
71
71
  export { rest } from './function/rest.mjs';
72
72
  export { curry } from './function/curry.mjs';
73
73
  export { spread } from './function/spread.mjs';
74
+ export { flow } from './function/flow.mjs';
75
+ export { flowRight } from './function/flowRight.mjs';
74
76
  export { clamp } from './math/clamp.mjs';
75
77
  export { inRange } from './math/inRange.mjs';
76
78
  export { mean } from './math/mean.mjs';
@@ -97,6 +99,7 @@ export { mergeWith } from './object/mergeWith.mjs';
97
99
  export { isDate } from './predicate/isDate.mjs';
98
100
  export { isEqual } from './predicate/isEqual.mjs';
99
101
  export { isError } from './predicate/isError.mjs';
102
+ export { isMap } from './predicate/isMap.mjs';
100
103
  export { isNil } from './predicate/isNil.mjs';
101
104
  export { isNotNil } from './predicate/isNotNil.mjs';
102
105
  export { isNull } from './predicate/isNull.mjs';
@@ -110,6 +113,7 @@ export { isRegExp } from './predicate/isRegExp.mjs';
110
113
  export { isBoolean } from './predicate/isBoolean.mjs';
111
114
  export { isSymbol } from './predicate/isSymbol.mjs';
112
115
  export { isString } from './predicate/isString.mjs';
116
+ export { isSet } from './predicate/isSet.mjs';
113
117
  export { isWeakMap } from './predicate/isWeakMap.mjs';
114
118
  export { isWeakSet } from './predicate/isWeakSet.mjs';
115
119
  export { delay } from './promise/delay.mjs';
@@ -5,7 +5,10 @@ function clone(obj) {
5
5
  if (isPrimitive(obj)) {
6
6
  return obj;
7
7
  }
8
- if (Array.isArray(obj) || isTypedArray(obj) || obj instanceof ArrayBuffer || obj instanceof SharedArrayBuffer) {
8
+ if (Array.isArray(obj) ||
9
+ isTypedArray(obj) ||
10
+ obj instanceof ArrayBuffer ||
11
+ (typeof SharedArrayBuffer !== 'undefined' && obj instanceof SharedArrayBuffer)) {
9
12
  return obj.slice(0);
10
13
  }
11
14
  const prototype = Object.getPrototypeOf(obj);
@@ -64,7 +64,7 @@ function cloneDeepImpl(obj, stack = new Map()) {
64
64
  return obj.slice(0);
65
65
  }
66
66
  if (obj instanceof DataView) {
67
- const result = new DataView(obj.buffer.slice(0));
67
+ const result = new DataView(obj.buffer.slice(0), obj.byteOffset, obj.byteLength);
68
68
  stack.set(obj, result);
69
69
  copyProperties(result, obj, stack);
70
70
  return result;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const toMerged = require('../_chunk/toMerged-D-sLFv.js');
5
+ const toMerged = require('../_chunk/toMerged-2WPeoI.js');
6
6
 
7
7
  function omit(obj, keys) {
8
8
  const result = { ...obj };
@@ -1,6 +1,7 @@
1
1
  export { isDate } from './isDate.mjs';
2
2
  export { isEqual } from './isEqual.mjs';
3
3
  export { isError } from './isError.mjs';
4
+ export { isMap } from './isMap.mjs';
4
5
  export { isNil } from './isNil.mjs';
5
6
  export { isNotNil } from './isNotNil.mjs';
6
7
  export { isNull } from './isNull.mjs';
@@ -14,5 +15,6 @@ export { isRegExp } from './isRegExp.mjs';
14
15
  export { isBoolean } from './isBoolean.mjs';
15
16
  export { isSymbol } from './isSymbol.mjs';
16
17
  export { isString } from './isString.mjs';
18
+ export { isSet } from './isSet.mjs';
17
19
  export { isWeakMap } from './isWeakMap.mjs';
18
20
  export { isWeakSet } from './isWeakSet.mjs';
@@ -1,6 +1,7 @@
1
1
  export { isDate } from './isDate.js';
2
2
  export { isEqual } from './isEqual.js';
3
3
  export { isError } from './isError.js';
4
+ export { isMap } from './isMap.js';
4
5
  export { isNil } from './isNil.js';
5
6
  export { isNotNil } from './isNotNil.js';
6
7
  export { isNull } from './isNull.js';
@@ -14,5 +15,6 @@ export { isRegExp } from './isRegExp.js';
14
15
  export { isBoolean } from './isBoolean.js';
15
16
  export { isSymbol } from './isSymbol.js';
16
17
  export { isString } from './isString.js';
18
+ export { isSet } from './isSet.js';
17
19
  export { isWeakMap } from './isWeakMap.js';
18
20
  export { isWeakSet } from './isWeakSet.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const isWeakSet = require('../_chunk/isWeakSet-1xFSnK.js');
5
+ const isWeakSet = require('../_chunk/isWeakSet-clQklw.js');
6
6
  const isPlainObject = require('../_chunk/isPlainObject-BIekvL.js');
7
7
 
8
8
  function isError(value) {
@@ -25,10 +25,12 @@ exports.isDate = isWeakSet.isDate;
25
25
  exports.isEqual = isWeakSet.isEqual;
26
26
  exports.isFunction = isWeakSet.isFunction;
27
27
  exports.isLength = isWeakSet.isLength;
28
+ exports.isMap = isWeakSet.isMap;
28
29
  exports.isNil = isWeakSet.isNil;
29
30
  exports.isNotNil = isWeakSet.isNotNil;
30
31
  exports.isNull = isWeakSet.isNull;
31
32
  exports.isRegExp = isWeakSet.isRegExp;
33
+ exports.isSet = isWeakSet.isSet;
32
34
  exports.isUndefined = isWeakSet.isUndefined;
33
35
  exports.isWeakMap = isWeakSet.isWeakMap;
34
36
  exports.isWeakSet = isWeakSet.isWeakSet;
@@ -1,6 +1,7 @@
1
1
  export { isDate } from './isDate.mjs';
2
2
  export { isEqual } from './isEqual.mjs';
3
3
  export { isError } from './isError.mjs';
4
+ export { isMap } from './isMap.mjs';
4
5
  export { isNil } from './isNil.mjs';
5
6
  export { isNotNil } from './isNotNil.mjs';
6
7
  export { isNull } from './isNull.mjs';
@@ -14,5 +15,6 @@ export { isRegExp } from './isRegExp.mjs';
14
15
  export { isBoolean } from './isBoolean.mjs';
15
16
  export { isSymbol } from './isSymbol.mjs';
16
17
  export { isString } from './isString.mjs';
18
+ export { isSet } from './isSet.mjs';
17
19
  export { isWeakMap } from './isWeakMap.mjs';
18
20
  export { isWeakSet } from './isWeakSet.mjs';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks if a given value is `Map`.
3
+ *
4
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Map`.
5
+ *
6
+ * @param {unknown} value The value to check if it is a `Map`.
7
+ * @returns {value is Map<any, any>} Returns `true` if `value` is a `Map`, else `false`.
8
+ *
9
+ * @example
10
+ * const value1 = new Map();
11
+ * const value2 = new Set();
12
+ * const value3 = new WeakMap();
13
+ *
14
+ * console.log(isMap(value1)); // true
15
+ * console.log(isMap(value2)); // false
16
+ * console.log(isMap(value3)); // false
17
+ */
18
+ declare function isMap(value: unknown): value is Map<any, any>;
19
+
20
+ export { isMap };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks if a given value is `Map`.
3
+ *
4
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Map`.
5
+ *
6
+ * @param {unknown} value The value to check if it is a `Map`.
7
+ * @returns {value is Map<any, any>} Returns `true` if `value` is a `Map`, else `false`.
8
+ *
9
+ * @example
10
+ * const value1 = new Map();
11
+ * const value2 = new Set();
12
+ * const value3 = new WeakMap();
13
+ *
14
+ * console.log(isMap(value1)); // true
15
+ * console.log(isMap(value2)); // false
16
+ * console.log(isMap(value3)); // false
17
+ */
18
+ declare function isMap(value: unknown): value is Map<any, any>;
19
+
20
+ export { isMap };
@@ -0,0 +1,5 @@
1
+ function isMap(value) {
2
+ return value instanceof Map;
3
+ }
4
+
5
+ export { isMap };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks if a given value is `Set`.
3
+ *
4
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Set`.
5
+ *
6
+ * @param {unknown} value The value to check if it is a `Set`.
7
+ * @returns {value is Set<any>} Returns `true` if `value` is a `Set`, else `false`.
8
+ *
9
+ * @example
10
+ * const value1 = new Set();
11
+ * const value2 = new Map();
12
+ * const value3 = new WeakSet();
13
+ *
14
+ * console.log(isSet(value1)); // true
15
+ * console.log(isSet(value2)); // false
16
+ * console.log(isSet(value3)); // false
17
+ */
18
+ declare function isSet(value: unknown): value is Set<any>;
19
+
20
+ export { isSet };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks if a given value is `Set`.
3
+ *
4
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Set`.
5
+ *
6
+ * @param {unknown} value The value to check if it is a `Set`.
7
+ * @returns {value is Set<any>} Returns `true` if `value` is a `Set`, else `false`.
8
+ *
9
+ * @example
10
+ * const value1 = new Set();
11
+ * const value2 = new Map();
12
+ * const value3 = new WeakSet();
13
+ *
14
+ * console.log(isSet(value1)); // true
15
+ * console.log(isSet(value2)); // false
16
+ * console.log(isSet(value3)); // false
17
+ */
18
+ declare function isSet(value: unknown): value is Set<any>;
19
+
20
+ export { isSet };
@@ -0,0 +1,5 @@
1
+ function isSet(value) {
2
+ return value instanceof Set;
3
+ }
4
+
5
+ export { isSet };
@@ -2,53 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- function capitalize(str) {
6
- return (str.charAt(0).toUpperCase() + str.slice(1).toLowerCase());
7
- }
8
-
9
- const CASE_SPLIT_PATTERN = /[A-Z]?[a-z]+|[0-9]+|[A-Z]+(?![a-z])|\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{L}+/gu;
10
- function getWords(str) {
11
- return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);
12
- }
13
-
14
- function camelCase(str) {
15
- const words = getWords(str);
16
- if (words.length === 0) {
17
- return '';
18
- }
19
- const [first, ...rest] = words;
20
- return `${first.toLowerCase()}${rest.map(word => capitalize(word)).join('')}`;
21
- }
22
-
23
- function snakeCase(str) {
24
- const words = getWords(str);
25
- return words.map(word => word.toLowerCase()).join('_');
26
- }
27
-
28
- function kebabCase(str) {
29
- const words = getWords(str);
30
- return words.map(word => word.toLowerCase()).join('-');
31
- }
32
-
33
- function upperCase(str) {
34
- const words = getWords(str);
35
- let result = '';
36
- for (let i = 0; i < words.length; i++) {
37
- result += words[i].toUpperCase();
38
- if (i < words.length - 1) {
39
- result += ' ';
40
- }
41
- }
42
- return result;
43
- }
44
-
45
- function lowerCase(str) {
46
- const words = getWords(str);
47
- return words.map(word => word.toLowerCase()).join(' ');
48
- }
5
+ const pad = require('../_chunk/pad-Cw2pvt.js');
49
6
 
50
7
  function startCase(str) {
51
- const words = getWords(str.trim());
8
+ const words = pad.getWords(str.trim());
52
9
  let result = '';
53
10
  for (let i = 0; i < words.length; i++) {
54
11
  const word = words[i];
@@ -60,163 +17,22 @@ function startCase(str) {
60
17
  return result;
61
18
  }
62
19
 
63
- function pascalCase(str) {
64
- const words = getWords(str);
65
- return words.map(word => capitalize(word)).join('');
66
- }
67
-
68
- function constantCase(str) {
69
- const words = getWords(str);
70
- return words.map(word => word.toUpperCase()).join('_');
71
- }
72
-
73
- function trimStart(str, chars) {
74
- if (chars === undefined) {
75
- return str.trimStart();
76
- }
77
- let startIndex = 0;
78
- switch (typeof chars) {
79
- case 'string': {
80
- while (startIndex < str.length && str[startIndex] === chars) {
81
- startIndex++;
82
- }
83
- break;
84
- }
85
- case 'object': {
86
- while (startIndex < str.length && chars.includes(str[startIndex])) {
87
- startIndex++;
88
- }
89
- }
90
- }
91
- return str.substring(startIndex);
92
- }
93
-
94
- function trimEnd(str, chars) {
95
- if (chars === undefined) {
96
- return str.trimEnd();
97
- }
98
- let endIndex = str.length;
99
- switch (typeof chars) {
100
- case 'string': {
101
- while (endIndex > 0 && str[endIndex - 1] === chars) {
102
- endIndex--;
103
- }
104
- break;
105
- }
106
- case 'object': {
107
- while (endIndex > 0 && chars.includes(str[endIndex - 1])) {
108
- endIndex--;
109
- }
110
- }
111
- }
112
- return str.substring(0, endIndex);
113
- }
114
-
115
- function trim(str, chars) {
116
- if (chars === undefined) {
117
- return str.trim();
118
- }
119
- return trimStart(trimEnd(str, chars), chars);
120
- }
121
-
122
- function upperFirst(str) {
123
- return str.substring(0, 1).toUpperCase() + str.substring(1);
124
- }
125
-
126
- function lowerFirst(str) {
127
- return str.substring(0, 1).toLowerCase() + str.substring(1);
128
- }
129
-
130
- const deburrMap = new Map(Object.entries({
131
- Æ: 'Ae',
132
- Ð: 'D',
133
- Ø: 'O',
134
- Þ: 'Th',
135
- ß: 'ss',
136
- æ: 'ae',
137
- ð: 'd',
138
- ø: 'o',
139
- þ: 'th',
140
- Đ: 'D',
141
- đ: 'd',
142
- Ħ: 'H',
143
- ħ: 'h',
144
- ı: 'i',
145
- IJ: 'IJ',
146
- ij: 'ij',
147
- ĸ: 'k',
148
- Ŀ: 'L',
149
- ŀ: 'l',
150
- Ł: 'L',
151
- ł: 'l',
152
- ʼn: "'n",
153
- Ŋ: 'N',
154
- ŋ: 'n',
155
- Œ: 'Oe',
156
- œ: 'oe',
157
- Ŧ: 'T',
158
- ŧ: 't',
159
- ſ: 's',
160
- }));
161
- function deburr(str) {
162
- str = str.normalize('NFD');
163
- let result = '';
164
- for (let i = 0; i < str.length; i++) {
165
- const char = str[i];
166
- if ((char >= '\u0300' && char <= '\u036f') || (char >= '\ufe20' && char <= '\ufe23')) {
167
- continue;
168
- }
169
- result += deburrMap.get(char) ?? char;
170
- }
171
- return result;
172
- }
173
-
174
- const htmlEscapes = {
175
- '&': '&amp;',
176
- '<': '&lt;',
177
- '>': '&gt;',
178
- '"': '&quot;',
179
- "'": '&#39;',
180
- };
181
- function escape(str) {
182
- return str.replace(/[&<>"']/g, match => htmlEscapes[match]);
183
- }
184
-
185
- function escapeRegExp(str) {
186
- return str.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
187
- }
188
-
189
- const htmlUnescapes = {
190
- '&amp;': '&',
191
- '&lt;': '<',
192
- '&gt;': '>',
193
- '&quot;': '"',
194
- '&#39;': "'",
195
- };
196
- function unescape(str) {
197
- return str.replace(/&(?:amp|lt|gt|quot|#(0+)?39);/g, match => htmlUnescapes[match] || "'");
198
- }
199
-
200
- function pad(str, length, chars = ' ') {
201
- return str.padStart(Math.floor((length - str.length) / 2) + str.length, chars).padEnd(length, chars);
202
- }
203
-
204
- exports.camelCase = camelCase;
205
- exports.capitalize = capitalize;
206
- exports.constantCase = constantCase;
207
- exports.deburr = deburr;
208
- exports.escape = escape;
209
- exports.escapeRegExp = escapeRegExp;
210
- exports.kebabCase = kebabCase;
211
- exports.lowerCase = lowerCase;
212
- exports.lowerFirst = lowerFirst;
213
- exports.pad = pad;
214
- exports.pascalCase = pascalCase;
215
- exports.snakeCase = snakeCase;
20
+ exports.camelCase = pad.camelCase;
21
+ exports.capitalize = pad.capitalize;
22
+ exports.constantCase = pad.constantCase;
23
+ exports.deburr = pad.deburr;
24
+ exports.escape = pad.escape;
25
+ exports.escapeRegExp = pad.escapeRegExp;
26
+ exports.kebabCase = pad.kebabCase;
27
+ exports.lowerCase = pad.lowerCase;
28
+ exports.lowerFirst = pad.lowerFirst;
29
+ exports.pad = pad.pad;
30
+ exports.pascalCase = pad.pascalCase;
31
+ exports.snakeCase = pad.snakeCase;
32
+ exports.trim = pad.trim;
33
+ exports.trimEnd = pad.trimEnd;
34
+ exports.trimStart = pad.trimStart;
35
+ exports.unescape = pad.unescape;
36
+ exports.upperCase = pad.upperCase;
37
+ exports.upperFirst = pad.upperFirst;
216
38
  exports.startCase = startCase;
217
- exports.trim = trim;
218
- exports.trimEnd = trimEnd;
219
- exports.trimStart = trimStart;
220
- exports.unescape = unescape;
221
- exports.upperCase = upperCase;
222
- exports.upperFirst = upperFirst;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.21.0",
4
+ "version": "1.22.0",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
@@ -247,7 +247,7 @@
247
247
  "scripts": {
248
248
  "prepack": "yarn build",
249
249
  "build": "rollup -c rollup.config.mjs && ./.scripts/postbuild.sh",
250
- "test": "vitest run --coverage --typecheck",
250
+ "test": "vitest --coverage --typecheck",
251
251
  "bench": "vitest bench",
252
252
  "lint": "eslint --config eslint.config.mjs",
253
253
  "format": "prettier --write .",