es-toolkit 1.37.0 → 1.37.1-dev.1244
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/CHANGELOG.md +6 -0
- package/dist/_chunk/{toSnakeCaseKeys-kqZCyq.js → isPlainObject-DINLyA.js} +0 -98
- package/dist/_chunk/{isWeakSet-C2NpfO.js → isWeakSet-403Sh5.js} +0 -92
- package/dist/_chunk/{range-HnEIT7.js → range-DSpBDL.js} +0 -21
- package/dist/_chunk/{unary-EIEhcF.js → unary-DzPndU.js} +0 -39
- package/dist/_chunk/{upperFirst-DbrFSz.js → upperFirst-C7IztG.js} +0 -17
- package/dist/_chunk/{zip-DDfXXG.js → zip-CIqPLd.js} +0 -78
- package/dist/array/index.js +79 -12
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/initial.d.mts +16 -0
- package/dist/compat/array/initial.d.ts +16 -0
- package/dist/compat/array/initial.mjs +11 -0
- package/dist/compat/array/keyBy.d.mts +48 -0
- package/dist/compat/array/keyBy.d.ts +48 -0
- package/dist/compat/array/keyBy.mjs +21 -0
- package/dist/compat/array/shuffle.d.mts +22 -0
- package/dist/compat/array/shuffle.d.ts +22 -0
- package/dist/compat/array/shuffle.mjs +24 -0
- package/dist/compat/array/xorBy.d.mts +108 -0
- package/dist/compat/array/xorBy.d.ts +108 -0
- package/dist/compat/array/xorBy.mjs +23 -0
- package/dist/compat/array/xorWith.d.mts +89 -0
- package/dist/compat/array/xorWith.d.ts +89 -0
- package/dist/compat/array/xorWith.mjs +21 -0
- package/dist/compat/compat.d.mts +19 -54
- package/dist/compat/compat.d.ts +19 -54
- package/dist/compat/compat.mjs +22 -59
- package/dist/compat/function/wrap.d.mts +27 -0
- package/dist/compat/function/wrap.d.ts +27 -0
- package/dist/compat/function/wrap.mjs +11 -0
- package/dist/compat/index.d.mts +19 -54
- package/dist/compat/index.d.ts +19 -54
- package/dist/compat/index.js +172 -180
- package/dist/compat/index.mjs +22 -59
- package/dist/function/index.js +39 -3
- package/dist/index.js +56 -57
- package/dist/math/index.js +22 -3
- package/dist/object/index.js +108 -14
- package/dist/predicate/index.js +93 -11
- package/dist/string/index.js +18 -4
- package/dist/util/index.js +19 -4
- package/package.json +1 -1
- package/dist/_chunk/invariant-BfGFfr.js +0 -21
package/dist/object/index.js
CHANGED
|
@@ -2,7 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const isPlainObject = require('../_chunk/isPlainObject-DINLyA.js');
|
|
6
|
+
const isPlainObject$1 = require('../_chunk/isPlainObject-Xaozpc.js');
|
|
7
|
+
const snakeCase = require('../_chunk/snakeCase-BwvoPi.js');
|
|
8
|
+
|
|
9
|
+
function flattenObject(object, { delimiter = '.' } = {}) {
|
|
10
|
+
return flattenObjectImpl(object, '', delimiter);
|
|
11
|
+
}
|
|
12
|
+
function flattenObjectImpl(object, prefix = '', delimiter = '.') {
|
|
13
|
+
const result = {};
|
|
14
|
+
const keys = Object.keys(object);
|
|
15
|
+
for (let i = 0; i < keys.length; i++) {
|
|
16
|
+
const key = keys[i];
|
|
17
|
+
const value = object[key];
|
|
18
|
+
const prefixedKey = prefix ? `${prefix}${delimiter}${key}` : key;
|
|
19
|
+
if (isPlainObject$1.isPlainObject(value) && Object.keys(value).length > 0) {
|
|
20
|
+
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter));
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter));
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
result[prefixedKey] = value;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function merge(target, source) {
|
|
33
|
+
const sourceKeys = Object.keys(source);
|
|
34
|
+
for (let i = 0; i < sourceKeys.length; i++) {
|
|
35
|
+
const key = sourceKeys[i];
|
|
36
|
+
const sourceValue = source[key];
|
|
37
|
+
const targetValue = target[key];
|
|
38
|
+
if (Array.isArray(sourceValue)) {
|
|
39
|
+
if (Array.isArray(targetValue)) {
|
|
40
|
+
target[key] = merge(targetValue, sourceValue);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
target[key] = merge([], sourceValue);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (isPlainObject$1.isPlainObject(sourceValue)) {
|
|
47
|
+
if (isPlainObject$1.isPlainObject(targetValue)) {
|
|
48
|
+
target[key] = merge(targetValue, sourceValue);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
target[key] = merge({}, sourceValue);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if (targetValue === undefined || sourceValue !== undefined) {
|
|
55
|
+
target[key] = sourceValue;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return target;
|
|
59
|
+
}
|
|
6
60
|
|
|
7
61
|
function mergeWith(target, source, merge) {
|
|
8
62
|
const sourceKeys = Object.keys(source);
|
|
@@ -17,7 +71,7 @@ function mergeWith(target, source, merge) {
|
|
|
17
71
|
else if (Array.isArray(sourceValue)) {
|
|
18
72
|
target[key] = mergeWith(targetValue ?? [], sourceValue, merge);
|
|
19
73
|
}
|
|
20
|
-
else if (
|
|
74
|
+
else if (isPlainObject.isObjectLike(targetValue) && isPlainObject.isObjectLike(sourceValue)) {
|
|
21
75
|
target[key] = mergeWith(targetValue ?? {}, sourceValue, merge);
|
|
22
76
|
}
|
|
23
77
|
else if (targetValue === undefined || sourceValue !== undefined) {
|
|
@@ -73,20 +127,60 @@ function pickBy(obj, shouldPick) {
|
|
|
73
127
|
return result;
|
|
74
128
|
}
|
|
75
129
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
130
|
+
function toCamelCaseKeys(obj) {
|
|
131
|
+
if (isPlainObject.isArray(obj)) {
|
|
132
|
+
return obj.map(item => toCamelCaseKeys(item));
|
|
133
|
+
}
|
|
134
|
+
if (isPlainObject$1.isPlainObject(obj)) {
|
|
135
|
+
const result = {};
|
|
136
|
+
const keys = Object.keys(obj);
|
|
137
|
+
for (let i = 0; i < keys.length; i++) {
|
|
138
|
+
const key = keys[i];
|
|
139
|
+
const camelKey = snakeCase.camelCase(key);
|
|
140
|
+
const camelCaseKeys = toCamelCaseKeys(obj[key]);
|
|
141
|
+
result[camelKey] = camelCaseKeys;
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
return obj;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function toMerged(target, source) {
|
|
149
|
+
return merge(isPlainObject.cloneDeep(target), source);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function toSnakeCaseKeys(obj) {
|
|
153
|
+
if (isPlainObject.isArray(obj)) {
|
|
154
|
+
return obj.map(item => toSnakeCaseKeys(item));
|
|
155
|
+
}
|
|
156
|
+
if (isPlainObject.isPlainObject(obj)) {
|
|
157
|
+
const result = {};
|
|
158
|
+
const keys = Object.keys(obj);
|
|
159
|
+
for (let i = 0; i < keys.length; i++) {
|
|
160
|
+
const key = keys[i];
|
|
161
|
+
const snakeKey = snakeCase.snakeCase(key);
|
|
162
|
+
const snakeCaseKeys = toSnakeCaseKeys(obj[key]);
|
|
163
|
+
result[snakeKey] = snakeCaseKeys;
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
return obj;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
exports.clone = isPlainObject.clone;
|
|
171
|
+
exports.cloneDeep = isPlainObject.cloneDeep;
|
|
172
|
+
exports.cloneDeepWith = isPlainObject.cloneDeepWith;
|
|
173
|
+
exports.findKey = isPlainObject.findKey;
|
|
174
|
+
exports.invert = isPlainObject.invert;
|
|
175
|
+
exports.mapKeys = isPlainObject.mapKeys;
|
|
176
|
+
exports.mapValues = isPlainObject.mapValues;
|
|
177
|
+
exports.flattenObject = flattenObject;
|
|
178
|
+
exports.merge = merge;
|
|
88
179
|
exports.mergeWith = mergeWith;
|
|
89
180
|
exports.omit = omit;
|
|
90
181
|
exports.omitBy = omitBy;
|
|
91
182
|
exports.pick = pick;
|
|
92
183
|
exports.pickBy = pickBy;
|
|
184
|
+
exports.toCamelCaseKeys = toCamelCaseKeys;
|
|
185
|
+
exports.toMerged = toMerged;
|
|
186
|
+
exports.toSnakeCaseKeys = toSnakeCaseKeys;
|
package/dist/predicate/index.js
CHANGED
|
@@ -2,41 +2,113 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const isWeakSet = require('../_chunk/isWeakSet-
|
|
5
|
+
const isWeakSet = require('../_chunk/isWeakSet-403Sh5.js');
|
|
6
6
|
const isPlainObject = require('../_chunk/isPlainObject-Xaozpc.js');
|
|
7
7
|
|
|
8
|
+
function isBlob(x) {
|
|
9
|
+
if (typeof Blob === 'undefined') {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return x instanceof Blob;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
function isBoolean(x) {
|
|
9
16
|
return typeof x === 'boolean';
|
|
10
17
|
}
|
|
11
18
|
|
|
19
|
+
function isBrowser() {
|
|
20
|
+
return typeof window !== 'undefined' && window?.document != null;
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
function isError(value) {
|
|
13
24
|
return value instanceof Error;
|
|
14
25
|
}
|
|
15
26
|
|
|
27
|
+
function isFile(x) {
|
|
28
|
+
if (typeof File === 'undefined') {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return isBlob(x) && x instanceof File;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isJSON(value) {
|
|
35
|
+
if (typeof value !== 'string') {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
JSON.parse(value);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isJSONValue(value) {
|
|
48
|
+
switch (typeof value) {
|
|
49
|
+
case 'object': {
|
|
50
|
+
return value === null || isJSONArray(value) || isJSONObject(value);
|
|
51
|
+
}
|
|
52
|
+
case 'string':
|
|
53
|
+
case 'number':
|
|
54
|
+
case 'boolean': {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
default: {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function isJSONArray(value) {
|
|
63
|
+
if (!Array.isArray(value)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return value.every(item => isJSONValue(item));
|
|
67
|
+
}
|
|
68
|
+
function isJSONObject(obj) {
|
|
69
|
+
if (!isPlainObject.isPlainObject(obj)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const keys = Reflect.ownKeys(obj);
|
|
73
|
+
for (let i = 0; i < keys.length; i++) {
|
|
74
|
+
const key = keys[i];
|
|
75
|
+
const value = obj[key];
|
|
76
|
+
if (typeof key !== 'string') {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (!isJSONValue(value)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function isNode() {
|
|
87
|
+
return typeof process !== 'undefined' && process?.versions?.node != null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isNotNil(x) {
|
|
91
|
+
return x != null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function isPromise(value) {
|
|
95
|
+
return value instanceof Promise;
|
|
96
|
+
}
|
|
97
|
+
|
|
16
98
|
function isString(value) {
|
|
17
99
|
return typeof value === 'string';
|
|
18
100
|
}
|
|
19
101
|
|
|
20
102
|
exports.isArrayBuffer = isWeakSet.isArrayBuffer;
|
|
21
|
-
exports.isBlob = isWeakSet.isBlob;
|
|
22
|
-
exports.isBrowser = isWeakSet.isBrowser;
|
|
23
103
|
exports.isBuffer = isWeakSet.isBuffer;
|
|
24
104
|
exports.isDate = isWeakSet.isDate;
|
|
25
105
|
exports.isEqual = isWeakSet.isEqual;
|
|
26
106
|
exports.isEqualWith = isWeakSet.isEqualWith;
|
|
27
|
-
exports.isFile = isWeakSet.isFile;
|
|
28
107
|
exports.isFunction = isWeakSet.isFunction;
|
|
29
|
-
exports.isJSON = isWeakSet.isJSON;
|
|
30
|
-
exports.isJSONArray = isWeakSet.isJSONArray;
|
|
31
|
-
exports.isJSONObject = isWeakSet.isJSONObject;
|
|
32
|
-
exports.isJSONValue = isWeakSet.isJSONValue;
|
|
33
108
|
exports.isLength = isWeakSet.isLength;
|
|
34
109
|
exports.isMap = isWeakSet.isMap;
|
|
35
110
|
exports.isNil = isWeakSet.isNil;
|
|
36
|
-
exports.isNode = isWeakSet.isNode;
|
|
37
|
-
exports.isNotNil = isWeakSet.isNotNil;
|
|
38
111
|
exports.isNull = isWeakSet.isNull;
|
|
39
|
-
exports.isPromise = isWeakSet.isPromise;
|
|
40
112
|
exports.isRegExp = isWeakSet.isRegExp;
|
|
41
113
|
exports.isSet = isWeakSet.isSet;
|
|
42
114
|
exports.isSymbol = isWeakSet.isSymbol;
|
|
@@ -46,6 +118,16 @@ exports.isWeakSet = isWeakSet.isWeakSet;
|
|
|
46
118
|
exports.isPlainObject = isPlainObject.isPlainObject;
|
|
47
119
|
exports.isPrimitive = isPlainObject.isPrimitive;
|
|
48
120
|
exports.isTypedArray = isPlainObject.isTypedArray;
|
|
121
|
+
exports.isBlob = isBlob;
|
|
49
122
|
exports.isBoolean = isBoolean;
|
|
123
|
+
exports.isBrowser = isBrowser;
|
|
50
124
|
exports.isError = isError;
|
|
125
|
+
exports.isFile = isFile;
|
|
126
|
+
exports.isJSON = isJSON;
|
|
127
|
+
exports.isJSONArray = isJSONArray;
|
|
128
|
+
exports.isJSONObject = isJSONObject;
|
|
129
|
+
exports.isJSONValue = isJSONValue;
|
|
130
|
+
exports.isNode = isNode;
|
|
131
|
+
exports.isNotNil = isNotNil;
|
|
132
|
+
exports.isPromise = isPromise;
|
|
51
133
|
exports.isString = isString;
|
package/dist/string/index.js
CHANGED
|
@@ -3,7 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
5
|
const snakeCase = require('../_chunk/snakeCase-BwvoPi.js');
|
|
6
|
-
const upperFirst = require('../_chunk/upperFirst-
|
|
6
|
+
const upperFirst = require('../_chunk/upperFirst-C7IztG.js');
|
|
7
|
+
|
|
8
|
+
function constantCase(str) {
|
|
9
|
+
const words = snakeCase.words(str);
|
|
10
|
+
return words.map(word => word.toUpperCase()).join('_');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function pascalCase(str) {
|
|
14
|
+
const words = snakeCase.words(str);
|
|
15
|
+
return words.map(word => snakeCase.capitalize(word)).join('');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function reverseString(value) {
|
|
19
|
+
return [...value].reverse().join('');
|
|
20
|
+
}
|
|
7
21
|
|
|
8
22
|
function startCase(str) {
|
|
9
23
|
const words = snakeCase.words(str.trim());
|
|
@@ -22,7 +36,6 @@ exports.camelCase = snakeCase.camelCase;
|
|
|
22
36
|
exports.capitalize = snakeCase.capitalize;
|
|
23
37
|
exports.snakeCase = snakeCase.snakeCase;
|
|
24
38
|
exports.words = snakeCase.words;
|
|
25
|
-
exports.constantCase = upperFirst.constantCase;
|
|
26
39
|
exports.deburr = upperFirst.deburr;
|
|
27
40
|
exports.escape = upperFirst.escape;
|
|
28
41
|
exports.escapeRegExp = upperFirst.escapeRegExp;
|
|
@@ -30,12 +43,13 @@ exports.kebabCase = upperFirst.kebabCase;
|
|
|
30
43
|
exports.lowerCase = upperFirst.lowerCase;
|
|
31
44
|
exports.lowerFirst = upperFirst.lowerFirst;
|
|
32
45
|
exports.pad = upperFirst.pad;
|
|
33
|
-
exports.pascalCase = upperFirst.pascalCase;
|
|
34
|
-
exports.reverseString = upperFirst.reverseString;
|
|
35
46
|
exports.trim = upperFirst.trim;
|
|
36
47
|
exports.trimEnd = upperFirst.trimEnd;
|
|
37
48
|
exports.trimStart = upperFirst.trimStart;
|
|
38
49
|
exports.unescape = upperFirst.unescape;
|
|
39
50
|
exports.upperCase = upperFirst.upperCase;
|
|
40
51
|
exports.upperFirst = upperFirst.upperFirst;
|
|
52
|
+
exports.constantCase = constantCase;
|
|
53
|
+
exports.pascalCase = pascalCase;
|
|
54
|
+
exports.reverseString = reverseString;
|
|
41
55
|
exports.startCase = startCase;
|
package/dist/util/index.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const invariant = require('../_chunk/invariant-BfGFfr.js');
|
|
6
|
-
|
|
7
5
|
function attempt(func) {
|
|
8
6
|
try {
|
|
9
7
|
return [null, func()];
|
|
@@ -13,6 +11,23 @@ function attempt(func) {
|
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
async function attemptAsync(func) {
|
|
15
|
+
try {
|
|
16
|
+
const result = await func();
|
|
17
|
+
return [null, result];
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
return [error, null];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function invariant(condition, message) {
|
|
25
|
+
if (condition) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
throw new Error(message);
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
exports.attempt = attempt;
|
|
32
|
+
exports.attemptAsync = attemptAsync;
|
|
33
|
+
exports.invariant = invariant;
|
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.37.
|
|
4
|
+
"version": "1.37.1-dev.1244+cb3278e8",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
async function attemptAsync(func) {
|
|
4
|
-
try {
|
|
5
|
-
const result = await func();
|
|
6
|
-
return [null, result];
|
|
7
|
-
}
|
|
8
|
-
catch (error) {
|
|
9
|
-
return [error, null];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function invariant(condition, message) {
|
|
14
|
-
if (condition) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
throw new Error(message);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.attemptAsync = attemptAsync;
|
|
21
|
-
exports.invariant = invariant;
|