es-toolkit 1.18.0 → 1.19.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.
- package/CHANGELOG.md +11 -0
- package/dist/_chunk/{rest-CXt9w3.js → curry-BmwJrK.js} +21 -0
- package/dist/_chunk/{isWeakSet-CogETi.js → isWeakSet-E_VMwB.js} +9 -3
- package/dist/_chunk/range-BXlMmn.js +68 -0
- package/dist/_chunk/{toMerged-DN1PPP.js → toMerged-Bzkqyz.js} +28 -46
- package/dist/_chunk/{zipWith-CYaH1Y.js → zipWith-B-5AMf.js} +1 -1
- package/dist/array/forEachRight.d.mts +23 -0
- package/dist/array/forEachRight.d.ts +23 -0
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/index.js +1 -1
- package/dist/array/orderBy.d.mts +1 -1
- package/dist/array/orderBy.d.ts +1 -1
- package/dist/array/sortBy.d.mts +1 -1
- package/dist/array/sortBy.d.ts +1 -1
- package/dist/array/unzip.d.mts +1 -1
- package/dist/array/unzip.d.ts +1 -1
- package/dist/array/zipObject.d.mts +1 -1
- package/dist/array/zipObject.d.ts +1 -1
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/decimalAdjust.mjs +19 -0
- package/dist/compat/_internal/isDeepKey.mjs +1 -3
- package/dist/compat/_internal/normalizeForCase.mjs +5 -4
- package/dist/compat/_internal/toKey.mjs +2 -7
- package/dist/compat/array/flatten.d.mts +1 -1
- package/dist/compat/array/flatten.d.ts +1 -1
- package/dist/compat/array/flattenDepth.d.mts +1 -1
- package/dist/compat/array/flattenDepth.d.ts +1 -1
- package/dist/compat/array/indexOf.d.mts +1 -1
- package/dist/compat/array/indexOf.d.ts +1 -1
- package/dist/compat/array/orderBy.d.mts +1 -1
- package/dist/compat/array/orderBy.d.ts +1 -1
- package/dist/compat/array/orderBy.mjs +1 -1
- package/dist/compat/array/size.d.mts +1 -1
- package/dist/compat/array/size.d.ts +1 -1
- package/dist/compat/array/sortBy.d.mts +1 -1
- package/dist/compat/array/sortBy.d.ts +1 -1
- package/dist/compat/array/zipObjectDeep.d.mts +1 -1
- package/dist/compat/array/zipObjectDeep.d.ts +1 -1
- package/dist/compat/index.d.mts +20 -7
- package/dist/compat/index.d.ts +20 -7
- package/dist/compat/index.js +459 -137
- package/dist/compat/index.mjs +20 -7
- package/dist/compat/math/ceil.d.mts +15 -0
- package/dist/compat/math/ceil.d.ts +15 -0
- package/dist/compat/math/ceil.mjs +7 -0
- package/dist/compat/math/floor.d.mts +15 -0
- package/dist/compat/math/floor.d.ts +15 -0
- package/dist/compat/math/floor.mjs +7 -0
- package/dist/compat/math/round.d.mts +15 -0
- package/dist/compat/math/round.d.ts +15 -0
- package/dist/compat/math/round.mjs +7 -0
- package/dist/compat/object/fromPairs.d.mts +2 -2
- package/dist/compat/object/fromPairs.d.ts +2 -2
- package/dist/compat/object/get.d.mts +12 -12
- package/dist/compat/object/get.d.ts +12 -12
- package/dist/compat/object/get.mjs +54 -17
- package/dist/compat/object/has.mjs +1 -1
- package/dist/compat/object/mergeWith.mjs +14 -2
- package/dist/compat/object/omit.d.mts +34 -0
- package/dist/compat/object/omit.d.ts +34 -0
- package/dist/compat/object/omit.mjs +33 -0
- package/dist/compat/object/pick.d.mts +47 -0
- package/dist/compat/object/pick.d.ts +47 -0
- package/dist/compat/object/pick.mjs +38 -0
- package/dist/compat/object/set.mjs +1 -1
- package/dist/compat/object/unset.d.mts +20 -0
- package/dist/compat/object/unset.d.ts +20 -0
- package/dist/compat/object/unset.mjs +68 -0
- package/dist/compat/predicate/isInteger.d.mts +17 -0
- package/dist/compat/predicate/isInteger.d.ts +17 -0
- package/dist/compat/predicate/isInteger.mjs +5 -0
- package/dist/compat/predicate/isMatch.mjs +44 -4
- package/dist/compat/predicate/isNil.mjs +5 -0
- package/dist/compat/predicate/isObject.d.mts +4 -4
- package/dist/compat/predicate/isObject.d.ts +4 -4
- package/dist/compat/predicate/isSafeInteger.d.mts +20 -0
- package/dist/compat/predicate/isSafeInteger.d.ts +20 -0
- package/dist/compat/predicate/isSafeInteger.mjs +5 -0
- package/dist/compat/predicate/matchesProperty.mjs +12 -1
- package/dist/compat/string/kebabCase.d.mts +17 -0
- package/dist/compat/string/kebabCase.d.ts +17 -0
- package/dist/compat/string/kebabCase.mjs +9 -0
- package/dist/compat/string/lowerCase.d.mts +17 -0
- package/dist/compat/string/lowerCase.d.ts +17 -0
- package/dist/compat/string/lowerCase.mjs +8 -0
- package/dist/compat/string/snakeCase.d.mts +17 -0
- package/dist/compat/string/snakeCase.d.ts +17 -0
- package/dist/compat/string/snakeCase.mjs +8 -0
- package/dist/compat/string/startCase.d.mts +16 -0
- package/dist/compat/string/startCase.d.ts +16 -0
- package/dist/compat/string/startCase.mjs +8 -0
- package/dist/compat/string/trim.d.mts +16 -0
- package/dist/compat/string/trim.d.ts +16 -0
- package/dist/compat/string/trim.mjs +25 -0
- package/dist/compat/string/trimEnd.d.mts +17 -0
- package/dist/compat/string/trimEnd.d.ts +17 -0
- package/dist/compat/string/trimEnd.mjs +25 -0
- package/dist/compat/string/trimStart.d.mts +17 -0
- package/dist/compat/string/trimStart.d.ts +17 -0
- package/dist/compat/string/trimStart.mjs +25 -0
- package/dist/compat/util/toPath.d.mts +20 -0
- package/dist/compat/util/toPath.d.ts +20 -0
- package/dist/compat/util/toPath.mjs +37 -0
- package/dist/compat/util/toString.d.mts +19 -0
- package/dist/compat/util/toString.d.ts +19 -0
- package/dist/compat/util/toString.mjs +15 -0
- package/dist/function/curry.d.mts +127 -0
- package/dist/function/curry.d.ts +127 -0
- package/dist/function/curry.mjs +21 -0
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +15 -14
- package/dist/function/index.mjs +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +40 -33
- package/dist/index.mjs +6 -0
- package/dist/math/index.js +8 -66
- package/dist/object/clone.mjs +28 -25
- package/dist/object/index.js +19 -3
- package/dist/object/pick.d.mts +1 -1
- package/dist/object/pick.d.ts +1 -1
- package/dist/predicate/index.d.mts +1 -0
- package/dist/predicate/index.d.ts +1 -0
- package/dist/predicate/index.js +6 -5
- package/dist/predicate/index.mjs +1 -0
- package/dist/predicate/isDate.d.mts +16 -0
- package/dist/predicate/isDate.d.ts +16 -0
- package/dist/predicate/isDate.mjs +5 -0
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/string/capitalize.d.mts +1 -0
- package/dist/string/capitalize.d.ts +1 -0
- package/dist/string/index.d.mts +4 -0
- package/dist/string/index.d.ts +4 -0
- package/dist/string/index.js +65 -0
- package/dist/string/index.mjs +4 -0
- package/dist/string/startCase.d.mts +1 -1
- package/dist/string/startCase.d.ts +1 -1
- package/dist/string/trim.d.mts +15 -0
- package/dist/string/trim.d.ts +15 -0
- package/dist/string/trim.mjs +11 -0
- package/dist/string/trimEnd.d.mts +16 -0
- package/dist/string/trimEnd.d.ts +16 -0
- package/dist/string/trimEnd.mjs +22 -0
- package/dist/string/trimStart.d.mts +16 -0
- package/dist/string/trimStart.d.ts +16 -0
- package/dist/string/trimStart.mjs +22 -0
- package/dist/string/upperCase.d.mts +17 -0
- package/dist/string/upperCase.d.ts +17 -0
- package/dist/string/upperCase.mjs +15 -0
- package/package.json +1 -1
- package/dist/compat/_internal/isArrayMatch.mjs +0 -24
- package/dist/compat/_internal/isMapMatch.mjs +0 -18
- package/dist/compat/_internal/isSetMatch.mjs +0 -13
- package/dist/compat/_internal/toPath.mjs +0 -40
- package/dist/_chunk/{isTypedArray-Dsrnb1.js → isPlainObject-BIekvL.js} +8 -8
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object with specified keys omitted.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
5
|
+
* excludes the properties corresponding to the specified keys.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of object.
|
|
8
|
+
* @template K - The type of keys in object.
|
|
9
|
+
* @param {T} obj - The object to omit keys from.
|
|
10
|
+
* @param {K[]} keys - An array of keys to be omitted from the object.
|
|
11
|
+
* @returns {Omit<T, K>} A new object with the specified keys omitted.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = omit(obj, ['b', 'c']);
|
|
16
|
+
* // result will be { a: 1 }
|
|
17
|
+
*/
|
|
18
|
+
declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new object with specified keys omitted.
|
|
21
|
+
*
|
|
22
|
+
* This function takes an object and a variable number of keys, and returns a new object that
|
|
23
|
+
* excludes the properties corresponding to the specified keys.
|
|
24
|
+
*
|
|
25
|
+
* Deep keys can be specified for keys.
|
|
26
|
+
*
|
|
27
|
+
* @template T - The type of object.
|
|
28
|
+
* @param {T} obj - The object to omit keys from.
|
|
29
|
+
* @param {...(PropertyKey | PropertyKey[] | PropertyKey[][]} keys - A variable number of keys to be omitted from the object.
|
|
30
|
+
* @returns {Partial<T>} A new object with the specified keys omitted.
|
|
31
|
+
*/
|
|
32
|
+
declare function omit<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | ReadonlyArray<readonly PropertyKey[]>>): Partial<T>;
|
|
33
|
+
|
|
34
|
+
export { omit };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cloneDeep } from '../../object/cloneDeep.mjs';
|
|
2
|
+
import { unset } from './unset.mjs';
|
|
3
|
+
|
|
4
|
+
function omit(obj, ...keysArr) {
|
|
5
|
+
if (obj == null) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
const result = cloneDeep(obj);
|
|
9
|
+
for (let i = 0; i < keysArr.length; i++) {
|
|
10
|
+
let keys = keysArr[i];
|
|
11
|
+
switch (typeof keys) {
|
|
12
|
+
case 'object': {
|
|
13
|
+
if (!Array.isArray(keys)) {
|
|
14
|
+
keys = Array.from(keys);
|
|
15
|
+
}
|
|
16
|
+
for (let j = 0; j < keys.length; j++) {
|
|
17
|
+
const key = keys[j];
|
|
18
|
+
unset(result, key);
|
|
19
|
+
}
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
case 'string':
|
|
23
|
+
case 'symbol':
|
|
24
|
+
case 'number': {
|
|
25
|
+
unset(result, keys);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { omit };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object composed of the picked object properties.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
5
|
+
* includes only the properties corresponding to the specified keys.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of object.
|
|
8
|
+
* @template K - The type of keys in object.
|
|
9
|
+
* @param {T} obj - The object to pick keys from.
|
|
10
|
+
* @param {K[]} keys - An array of keys to be picked from the object.
|
|
11
|
+
* @returns {Pick<T, K>} A new object with the specified keys picked.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = pick(obj, ['a', 'c']);
|
|
16
|
+
* // result will be { a: 1, c: 3 }
|
|
17
|
+
*/
|
|
18
|
+
declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new object composed of the picked object properties.
|
|
21
|
+
*
|
|
22
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
23
|
+
* includes only the properties corresponding to the specified keys.
|
|
24
|
+
*
|
|
25
|
+
* @template T - The type of object.
|
|
26
|
+
* @param {T | null | undefined} obj - The object to pick keys from.
|
|
27
|
+
* @param {...any} keys
|
|
28
|
+
* @param {PropertyKey | PropertyKey[] | ProperyKey[][]}} keys - An array of keys to be picked from the object. received keysgoes through a flattening process before being used.
|
|
29
|
+
* @returns {Partial<T, K>} A new object with the specified keys picked.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
33
|
+
* const result = pick(obj, ['a', 'c']);
|
|
34
|
+
* // result will be { a: 1, c: 3 }
|
|
35
|
+
*
|
|
36
|
+
* // each path can be passed individually as an argument
|
|
37
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
38
|
+
* const result = pick(obj, 'a', 'c');
|
|
39
|
+
*
|
|
40
|
+
* // pick a key over a path
|
|
41
|
+
* const obj = { 'a.b': 1, a: { b: 2 } };
|
|
42
|
+
* const result = pick(obj, 'a.b');
|
|
43
|
+
* // result will be { 'a.b': 1 }
|
|
44
|
+
*/
|
|
45
|
+
declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | ReadonlyArray<readonly PropertyKey[]>>): Partial<T>;
|
|
46
|
+
|
|
47
|
+
export { pick };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object composed of the picked object properties.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
5
|
+
* includes only the properties corresponding to the specified keys.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of object.
|
|
8
|
+
* @template K - The type of keys in object.
|
|
9
|
+
* @param {T} obj - The object to pick keys from.
|
|
10
|
+
* @param {K[]} keys - An array of keys to be picked from the object.
|
|
11
|
+
* @returns {Pick<T, K>} A new object with the specified keys picked.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = pick(obj, ['a', 'c']);
|
|
16
|
+
* // result will be { a: 1, c: 3 }
|
|
17
|
+
*/
|
|
18
|
+
declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new object composed of the picked object properties.
|
|
21
|
+
*
|
|
22
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
23
|
+
* includes only the properties corresponding to the specified keys.
|
|
24
|
+
*
|
|
25
|
+
* @template T - The type of object.
|
|
26
|
+
* @param {T | null | undefined} obj - The object to pick keys from.
|
|
27
|
+
* @param {...any} keys
|
|
28
|
+
* @param {PropertyKey | PropertyKey[] | ProperyKey[][]}} keys - An array of keys to be picked from the object. received keysgoes through a flattening process before being used.
|
|
29
|
+
* @returns {Partial<T, K>} A new object with the specified keys picked.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
33
|
+
* const result = pick(obj, ['a', 'c']);
|
|
34
|
+
* // result will be { a: 1, c: 3 }
|
|
35
|
+
*
|
|
36
|
+
* // each path can be passed individually as an argument
|
|
37
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
38
|
+
* const result = pick(obj, 'a', 'c');
|
|
39
|
+
*
|
|
40
|
+
* // pick a key over a path
|
|
41
|
+
* const obj = { 'a.b': 1, a: { b: 2 } };
|
|
42
|
+
* const result = pick(obj, 'a.b');
|
|
43
|
+
* // result will be { 'a.b': 1 }
|
|
44
|
+
*/
|
|
45
|
+
declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | ReadonlyArray<readonly PropertyKey[]>>): Partial<T>;
|
|
46
|
+
|
|
47
|
+
export { pick };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isNil } from '../predicate/isNil.mjs';
|
|
2
|
+
import { get } from './get.mjs';
|
|
3
|
+
import { set } from './set.mjs';
|
|
4
|
+
|
|
5
|
+
function pick(obj, ...keysArr) {
|
|
6
|
+
if (isNil(obj)) {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
const result = {};
|
|
10
|
+
for (let keys of keysArr) {
|
|
11
|
+
switch (typeof keys) {
|
|
12
|
+
case 'object': {
|
|
13
|
+
if (!Array.isArray(keys)) {
|
|
14
|
+
keys = Array.from(keys);
|
|
15
|
+
}
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
case 'string':
|
|
19
|
+
case 'symbol':
|
|
20
|
+
case 'number': {
|
|
21
|
+
keys = [keys];
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (const key of keys) {
|
|
26
|
+
const value = get(obj, key);
|
|
27
|
+
if (typeof key === 'string' && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
28
|
+
result[key] = value;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
set(result, key, value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { pick };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isIndex } from '../_internal/isIndex.mjs';
|
|
2
|
-
import { toPath } from '../
|
|
2
|
+
import { toPath } from '../util/toPath.mjs';
|
|
3
3
|
|
|
4
4
|
function set(obj, path, value) {
|
|
5
5
|
const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes the property at the given path of the object.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} obj - The object to modify.
|
|
5
|
+
* @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to unset.
|
|
6
|
+
* @returns {boolean} - Returns true if the property is deleted, else false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const obj = { a: { b: { c: 42 } } };
|
|
10
|
+
* unset(obj, 'a.b.c'); // true
|
|
11
|
+
* console.log(obj); // { a: { b: {} } }
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: { b: { c: 42 } } };
|
|
15
|
+
* unset(obj, ['a', 'b', 'c']); // true
|
|
16
|
+
* console.log(obj); // { a: { b: {} } }
|
|
17
|
+
*/
|
|
18
|
+
declare function unset(obj: any, path: PropertyKey | readonly PropertyKey[]): boolean;
|
|
19
|
+
|
|
20
|
+
export { unset };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes the property at the given path of the object.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} obj - The object to modify.
|
|
5
|
+
* @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to unset.
|
|
6
|
+
* @returns {boolean} - Returns true if the property is deleted, else false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const obj = { a: { b: { c: 42 } } };
|
|
10
|
+
* unset(obj, 'a.b.c'); // true
|
|
11
|
+
* console.log(obj); // { a: { b: {} } }
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: { b: { c: 42 } } };
|
|
15
|
+
* unset(obj, ['a', 'b', 'c']); // true
|
|
16
|
+
* console.log(obj); // { a: { b: {} } }
|
|
17
|
+
*/
|
|
18
|
+
declare function unset(obj: any, path: PropertyKey | readonly PropertyKey[]): boolean;
|
|
19
|
+
|
|
20
|
+
export { unset };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isDeepKey } from '../_internal/isDeepKey.mjs';
|
|
2
|
+
import { toKey } from '../_internal/toKey.mjs';
|
|
3
|
+
import { toPath } from '../util/toPath.mjs';
|
|
4
|
+
import { get } from './get.mjs';
|
|
5
|
+
|
|
6
|
+
function unset(obj, path) {
|
|
7
|
+
if (obj == null) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
switch (typeof path) {
|
|
11
|
+
case 'symbol':
|
|
12
|
+
case 'number':
|
|
13
|
+
case 'object': {
|
|
14
|
+
if (Array.isArray(path)) {
|
|
15
|
+
return unsetWithPath(obj, path);
|
|
16
|
+
}
|
|
17
|
+
if (typeof path === 'number') {
|
|
18
|
+
path = toKey(path);
|
|
19
|
+
}
|
|
20
|
+
else if (typeof path === 'object') {
|
|
21
|
+
if (Object.is(path?.valueOf(), -0)) {
|
|
22
|
+
path = '-0';
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
path = String(path);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (obj?.[path] === undefined) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
delete obj[path];
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
case 'string': {
|
|
40
|
+
if (obj?.[path] === undefined && isDeepKey(path)) {
|
|
41
|
+
return unsetWithPath(obj, toPath(path));
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
delete obj[path];
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function unsetWithPath(obj, path) {
|
|
54
|
+
const parent = get(obj, path.slice(0, -1), obj);
|
|
55
|
+
const lastKey = path[path.length - 1];
|
|
56
|
+
if (parent?.[lastKey] === undefined) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
delete parent[lastKey];
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { unset };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if `value` is an integer.
|
|
3
|
+
*
|
|
4
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value - The value to check
|
|
7
|
+
* @returns {boolean} `true` if `value` is integer, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* isInteger(3); // Returns: true
|
|
11
|
+
* isInteger(Infinity); // Returns: false
|
|
12
|
+
* isInteger('3'); // Returns: false
|
|
13
|
+
* isInteger([]); // Returns: false
|
|
14
|
+
*/
|
|
15
|
+
declare function isInteger(value?: unknown): value is number;
|
|
16
|
+
|
|
17
|
+
export { isInteger };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if `value` is an integer.
|
|
3
|
+
*
|
|
4
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value - The value to check
|
|
7
|
+
* @returns {boolean} `true` if `value` is integer, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* isInteger(3); // Returns: true
|
|
11
|
+
* isInteger(Infinity); // Returns: false
|
|
12
|
+
* isInteger('3'); // Returns: false
|
|
13
|
+
* isInteger([]); // Returns: false
|
|
14
|
+
*/
|
|
15
|
+
declare function isInteger(value?: unknown): value is number;
|
|
16
|
+
|
|
17
|
+
export { isInteger };
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { isPrimitive } from '../../predicate/isPrimitive.mjs';
|
|
2
|
-
import { isArrayMatch } from '../_internal/isArrayMatch.mjs';
|
|
3
|
-
import { isMapMatch } from '../_internal/isMapMatch.mjs';
|
|
4
|
-
import { isSetMatch } from '../_internal/isSetMatch.mjs';
|
|
5
2
|
|
|
6
3
|
function isMatch(target, source) {
|
|
7
4
|
if (source === target) {
|
|
@@ -53,5 +50,48 @@ function isMatch(target, source) {
|
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
52
|
}
|
|
53
|
+
function isMapMatch(target, source) {
|
|
54
|
+
if (source.size === 0) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (!(target instanceof Map)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
for (const [key, value] of source.entries()) {
|
|
61
|
+
if (!isMatch(target.get(key), value)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
function isArrayMatch(target, source) {
|
|
68
|
+
if (source.length === 0) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (!Array.isArray(target)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const countedIndex = new Set();
|
|
75
|
+
for (let i = 0; i < source.length; i++) {
|
|
76
|
+
const sourceItem = source[i];
|
|
77
|
+
const index = target.findIndex((targetItem, index) => {
|
|
78
|
+
return isMatch(targetItem, sourceItem) && !countedIndex.has(index);
|
|
79
|
+
});
|
|
80
|
+
if (index === -1) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
countedIndex.add(index);
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
function isSetMatch(target, source) {
|
|
88
|
+
if (source.size === 0) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
if (!(target instanceof Set)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return isArrayMatch([...target], [...source]);
|
|
95
|
+
}
|
|
56
96
|
|
|
57
|
-
export { isMatch };
|
|
97
|
+
export { isArrayMatch, isMapMatch, isMatch, isSetMatch };
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
* const value3 = () => {};
|
|
17
17
|
* const value4 = null;
|
|
18
18
|
*
|
|
19
|
-
* console.log(
|
|
20
|
-
* console.log(
|
|
21
|
-
* console.log(
|
|
22
|
-
* console.log(
|
|
19
|
+
* console.log(isObject(value1)); // true
|
|
20
|
+
* console.log(isObject(value2)); // true
|
|
21
|
+
* console.log(isObject(value3)); // true
|
|
22
|
+
* console.log(isObject(value4)); // false
|
|
23
23
|
*/
|
|
24
24
|
declare function isObject(value: unknown): value is object;
|
|
25
25
|
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
* const value3 = () => {};
|
|
17
17
|
* const value4 = null;
|
|
18
18
|
*
|
|
19
|
-
* console.log(
|
|
20
|
-
* console.log(
|
|
21
|
-
* console.log(
|
|
22
|
-
* console.log(
|
|
19
|
+
* console.log(isObject(value1)); // true
|
|
20
|
+
* console.log(isObject(value2)); // true
|
|
21
|
+
* console.log(isObject(value3)); // true
|
|
22
|
+
* console.log(isObject(value4)); // false
|
|
23
23
|
*/
|
|
24
24
|
declare function isObject(value: unknown): value is object;
|
|
25
25
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if `value` is a safe integer (between -(2^53 – 1) and (2^53 – 1), inclusive).
|
|
3
|
+
*
|
|
4
|
+
* A safe integer is an integer that can be precisely represented as a `number` in JavaScript,
|
|
5
|
+
* without any other integer being rounded to it.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} value - The value to check
|
|
10
|
+
* @returns {boolean} `true` if `value` is an integer and between the safe values, otherwise `false`
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* isSafeInteger(3); // Returns: true
|
|
14
|
+
* isSafeInteger(Number.MIN_SAFE_INTEGER - 1); // Returns: false
|
|
15
|
+
* isSafeInteger(1n); // Returns: false
|
|
16
|
+
* isSafeInteger('1'); // Returns: false
|
|
17
|
+
*/
|
|
18
|
+
declare function isSafeInteger(value?: unknown): value is number;
|
|
19
|
+
|
|
20
|
+
export { isSafeInteger };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if `value` is a safe integer (between -(2^53 – 1) and (2^53 – 1), inclusive).
|
|
3
|
+
*
|
|
4
|
+
* A safe integer is an integer that can be precisely represented as a `number` in JavaScript,
|
|
5
|
+
* without any other integer being rounded to it.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} value - The value to check
|
|
10
|
+
* @returns {boolean} `true` if `value` is an integer and between the safe values, otherwise `false`
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* isSafeInteger(3); // Returns: true
|
|
14
|
+
* isSafeInteger(Number.MIN_SAFE_INTEGER - 1); // Returns: false
|
|
15
|
+
* isSafeInteger(1n); // Returns: false
|
|
16
|
+
* isSafeInteger('1'); // Returns: false
|
|
17
|
+
*/
|
|
18
|
+
declare function isSafeInteger(value?: unknown): value is number;
|
|
19
|
+
|
|
20
|
+
export { isSafeInteger };
|
|
@@ -5,7 +5,18 @@ import { has } from '../object/has.mjs';
|
|
|
5
5
|
import { isMatch } from './isMatch.mjs';
|
|
6
6
|
|
|
7
7
|
function matchesProperty(property, source) {
|
|
8
|
-
|
|
8
|
+
switch (typeof property) {
|
|
9
|
+
case 'object': {
|
|
10
|
+
if (Object.is(property?.valueOf(), -0)) {
|
|
11
|
+
property = '-0';
|
|
12
|
+
}
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
case 'number': {
|
|
16
|
+
property = toKey(property);
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
9
20
|
source = cloneDeep(source);
|
|
10
21
|
return function (target) {
|
|
11
22
|
const result = get(target, property);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to kebab case.
|
|
3
|
+
*
|
|
4
|
+
* Kebab case is the naming convention in which each word is written in lowercase and separated by a dash (-) character.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} str - The string that is to be changed to kebab case.
|
|
7
|
+
* @returns {string} - The converted string to kebab case.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const convertedStr1 = kebabCase('camelCase') // returns 'camel-case'
|
|
11
|
+
* const convertedStr2 = kebabCase('some whitespace') // returns 'some-whitespace'
|
|
12
|
+
* const convertedStr3 = kebabCase('hyphen-text') // returns 'hyphen-text'
|
|
13
|
+
* const convertedStr4 = kebabCase('HTTPRequest') // returns 'http-request'
|
|
14
|
+
*/
|
|
15
|
+
declare function kebabCase(str: string | object): string;
|
|
16
|
+
|
|
17
|
+
export { kebabCase };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to kebab case.
|
|
3
|
+
*
|
|
4
|
+
* Kebab case is the naming convention in which each word is written in lowercase and separated by a dash (-) character.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} str - The string that is to be changed to kebab case.
|
|
7
|
+
* @returns {string} - The converted string to kebab case.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const convertedStr1 = kebabCase('camelCase') // returns 'camel-case'
|
|
11
|
+
* const convertedStr2 = kebabCase('some whitespace') // returns 'some-whitespace'
|
|
12
|
+
* const convertedStr3 = kebabCase('hyphen-text') // returns 'hyphen-text'
|
|
13
|
+
* const convertedStr4 = kebabCase('HTTPRequest') // returns 'http-request'
|
|
14
|
+
*/
|
|
15
|
+
declare function kebabCase(str: string | object): string;
|
|
16
|
+
|
|
17
|
+
export { kebabCase };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { kebabCase as kebabCase$1 } from '../../string/kebabCase.mjs';
|
|
2
|
+
import '../../string/deburr.mjs';
|
|
3
|
+
import { normalizeForCase } from '../_internal/normalizeForCase.mjs';
|
|
4
|
+
|
|
5
|
+
function kebabCase(str) {
|
|
6
|
+
return kebabCase$1(normalizeForCase(str));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { kebabCase };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to lower case.
|
|
3
|
+
*
|
|
4
|
+
* Lower case is the naming convention in which each word is written in lowercase and separated by an space ( ) character.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} str - The string that is to be changed to lower case.
|
|
7
|
+
* @returns {string} - The converted string to lower case.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const convertedStr1 = lowerCase('camelCase') // returns 'camel case'
|
|
11
|
+
* const convertedStr2 = lowerCase('some whitespace') // returns 'some whitespace'
|
|
12
|
+
* const convertedStr3 = lowerCase('hyphen-text') // returns 'hyphen text'
|
|
13
|
+
* const convertedStr4 = lowerCase('HTTPRequest') // returns 'http request'
|
|
14
|
+
*/
|
|
15
|
+
declare function lowerCase(str: string | object): string;
|
|
16
|
+
|
|
17
|
+
export { lowerCase };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to lower case.
|
|
3
|
+
*
|
|
4
|
+
* Lower case is the naming convention in which each word is written in lowercase and separated by an space ( ) character.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} str - The string that is to be changed to lower case.
|
|
7
|
+
* @returns {string} - The converted string to lower case.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const convertedStr1 = lowerCase('camelCase') // returns 'camel case'
|
|
11
|
+
* const convertedStr2 = lowerCase('some whitespace') // returns 'some whitespace'
|
|
12
|
+
* const convertedStr3 = lowerCase('hyphen-text') // returns 'hyphen text'
|
|
13
|
+
* const convertedStr4 = lowerCase('HTTPRequest') // returns 'http request'
|
|
14
|
+
*/
|
|
15
|
+
declare function lowerCase(str: string | object): string;
|
|
16
|
+
|
|
17
|
+
export { lowerCase };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to snake case.
|
|
3
|
+
*
|
|
4
|
+
* Snake case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} str - The string that is to be changed to snake case.
|
|
7
|
+
* @returns {string} - The converted string to snake case.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const convertedStr1 = snakeCase('camelCase') // returns 'camel_case'
|
|
11
|
+
* const convertedStr2 = snakeCase('some whitespace') // returns 'some_whitespace'
|
|
12
|
+
* const convertedStr3 = snakeCase('hyphen-text') // returns 'hyphen_text'
|
|
13
|
+
* const convertedStr4 = snakeCase('HTTPRequest') // returns 'http_request'
|
|
14
|
+
*/
|
|
15
|
+
declare function snakeCase(str: string | object): string;
|
|
16
|
+
|
|
17
|
+
export { snakeCase };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to snake case.
|
|
3
|
+
*
|
|
4
|
+
* Snake case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} str - The string that is to be changed to snake case.
|
|
7
|
+
* @returns {string} - The converted string to snake case.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const convertedStr1 = snakeCase('camelCase') // returns 'camel_case'
|
|
11
|
+
* const convertedStr2 = snakeCase('some whitespace') // returns 'some_whitespace'
|
|
12
|
+
* const convertedStr3 = snakeCase('hyphen-text') // returns 'hyphen_text'
|
|
13
|
+
* const convertedStr4 = snakeCase('HTTPRequest') // returns 'http_request'
|
|
14
|
+
*/
|
|
15
|
+
declare function snakeCase(str: string | object): string;
|
|
16
|
+
|
|
17
|
+
export { snakeCase };
|