es-toolkit 1.23.0 → 1.24.0-dev.764
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 +9 -0
- package/README.md +1 -1
- package/dist/_chunk/{isWeakSet-BAMm2l.js → isWeakSet-Bd6nry.js} +59 -46
- package/dist/_chunk/{range-BXlMmn.js → sumBy-BkErWJ.js} +25 -5
- package/dist/_chunk/{isObjectLike-aywuSF.js → toMerged-DDLv0D.js} +88 -86
- package/dist/_chunk/{flowRight-Dv8J0U.js → unary-BZ5Ixo.js} +27 -64
- package/dist/_chunk/{zipWith-EOU_KZ.js → zipWith-wpjySR.js} +8 -17
- package/dist/array/dropRightWhile.d.mts +2 -2
- package/dist/array/dropRightWhile.d.ts +2 -2
- package/dist/array/dropRightWhile.mjs +1 -1
- package/dist/array/dropWhile.d.mts +1 -1
- package/dist/array/dropWhile.d.ts +1 -1
- package/dist/array/index.js +1 -1
- package/dist/array/unionBy.mjs +3 -10
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/MAX_ARRAY_LENGTH.mjs +3 -0
- package/dist/compat/_internal/isIterateeCall.mjs +17 -0
- package/dist/compat/array/difference.d.mts +9 -3
- package/dist/compat/array/difference.d.ts +9 -3
- package/dist/compat/array/difference.mjs +12 -3
- package/dist/compat/array/dropRightWhile.d.mts +60 -0
- package/dist/compat/array/dropRightWhile.d.ts +60 -0
- package/dist/compat/array/dropRightWhile.mjs +27 -0
- package/dist/compat/array/every.mjs +4 -5
- package/dist/compat/array/filter.mjs +4 -5
- package/dist/compat/array/find.mjs +4 -5
- package/dist/compat/array/includes.mjs +2 -1
- package/dist/compat/array/slice.d.mts +18 -0
- package/dist/compat/array/slice.d.ts +18 -0
- package/dist/compat/array/slice.mjs +38 -0
- package/dist/compat/array/take.d.mts +25 -0
- package/dist/compat/array/take.d.ts +25 -0
- package/dist/compat/array/take.mjs +10 -0
- package/dist/compat/function/before.d.mts +26 -0
- package/dist/compat/function/before.d.ts +26 -0
- package/dist/compat/function/before.mjs +20 -0
- package/dist/compat/function/curryRight.d.mts +50 -0
- package/dist/compat/function/curryRight.d.ts +50 -0
- package/dist/compat/function/curryRight.mjs +64 -0
- package/dist/compat/index.d.mts +86 -75
- package/dist/compat/index.d.ts +86 -75
- package/dist/compat/index.js +779 -496
- package/dist/compat/index.mjs +86 -75
- package/dist/compat/object/defaults.d.mts +120 -0
- package/dist/compat/object/defaults.d.ts +120 -0
- package/dist/compat/object/defaults.mjs +21 -0
- package/dist/compat/object/invertBy.d.mts +27 -0
- package/dist/compat/object/invertBy.d.ts +27 -0
- package/dist/compat/object/invertBy.mjs +27 -0
- package/dist/compat/object/omit.d.mts +1 -1
- package/dist/compat/object/omit.d.ts +1 -1
- package/dist/compat/object/pick.d.mts +1 -1
- package/dist/compat/object/pick.d.ts +1 -1
- package/dist/compat/object/toDefaulted.d.mts +122 -0
- package/dist/compat/object/toDefaulted.d.ts +122 -0
- package/dist/compat/object/toDefaulted.mjs +9 -0
- package/dist/compat/predicate/isArrayBuffer.d.mts +20 -0
- package/dist/compat/predicate/isArrayBuffer.d.ts +20 -0
- package/dist/compat/predicate/isArrayBuffer.mjs +7 -0
- package/dist/compat/predicate/isDate.d.mts +16 -0
- package/dist/compat/predicate/isDate.d.ts +16 -0
- package/dist/compat/predicate/isDate.mjs +7 -0
- package/dist/compat/predicate/isEqualWith.d.mts +38 -0
- package/dist/compat/predicate/isEqualWith.d.ts +38 -0
- package/dist/compat/predicate/isEqualWith.mjs +23 -0
- package/dist/compat/predicate/isMap.d.mts +20 -0
- package/dist/compat/predicate/isMap.d.ts +20 -0
- package/dist/compat/predicate/isMap.mjs +7 -0
- package/dist/compat/predicate/isMatch.mjs +2 -1
- package/dist/compat/predicate/isSet.d.mts +20 -0
- package/dist/compat/predicate/isSet.d.ts +20 -0
- package/dist/compat/predicate/isSet.mjs +7 -0
- package/dist/compat/string/upperCase.mjs +0 -1
- package/dist/compat/util/constant.d.mts +16 -0
- package/dist/compat/util/constant.d.ts +16 -0
- package/dist/compat/util/constant.mjs +5 -0
- package/dist/compat/util/defaultTo.d.mts +17 -0
- package/dist/compat/util/defaultTo.d.ts +17 -0
- package/dist/compat/util/defaultTo.mjs +8 -0
- package/dist/compat/util/eq.d.mts +16 -0
- package/dist/compat/util/eq.d.ts +16 -0
- package/dist/compat/util/eq.mjs +5 -0
- package/dist/compat/util/times.d.mts +14 -0
- package/dist/compat/util/times.d.ts +14 -0
- package/dist/compat/util/times.mjs +15 -0
- package/dist/compat/util/toLength.d.mts +18 -0
- package/dist/compat/util/toLength.d.ts +18 -0
- package/dist/compat/util/toLength.mjs +12 -0
- package/dist/function/before.d.mts +2 -2
- package/dist/function/before.d.ts +2 -2
- package/dist/function/before.mjs +2 -2
- package/dist/function/index.d.mts +10 -10
- package/dist/function/index.d.ts +10 -10
- package/dist/function/index.js +65 -32
- package/dist/function/index.mjs +10 -10
- package/dist/function/once.d.mts +16 -1
- package/dist/function/once.d.ts +16 -1
- package/dist/function/once.mjs +5 -7
- package/dist/index.d.mts +43 -41
- package/dist/index.d.ts +43 -41
- package/dist/index.js +59 -57
- package/dist/index.mjs +43 -41
- package/dist/math/index.d.mts +2 -1
- package/dist/math/index.d.ts +2 -1
- package/dist/math/index.js +9 -8
- package/dist/math/index.mjs +2 -1
- package/dist/math/rangeRight.d.mts +38 -0
- package/dist/math/rangeRight.d.ts +38 -0
- package/dist/math/rangeRight.mjs +20 -0
- package/dist/object/index.d.mts +7 -7
- package/dist/object/index.d.ts +7 -7
- package/dist/object/index.js +32 -32
- package/dist/object/index.mjs +7 -7
- package/dist/object/omitBy.d.mts +1 -1
- package/dist/object/omitBy.d.ts +1 -1
- package/dist/object/omitBy.mjs +4 -3
- package/dist/object/pickBy.mjs +4 -3
- package/dist/predicate/index.d.mts +11 -10
- package/dist/predicate/index.d.ts +11 -10
- package/dist/predicate/index.js +8 -7
- package/dist/predicate/index.mjs +11 -10
- package/dist/predicate/isBlob.d.mts +19 -0
- package/dist/predicate/isBlob.d.ts +19 -0
- package/dist/predicate/isBlob.mjs +8 -0
- package/dist/predicate/isEqualWith.mjs +2 -1
- package/dist/promise/index.d.mts +1 -1
- package/dist/promise/index.d.ts +1 -1
- package/dist/promise/index.mjs +1 -1
- package/dist/string/index.d.mts +12 -12
- package/dist/string/index.d.ts +12 -12
- package/dist/string/index.js +20 -20
- package/dist/string/index.mjs +12 -12
- package/package.json +10 -6
- package/dist/_chunk/{pad-BWiShN.js → upperFirst-BUECmK.js} +84 -84
|
@@ -25,7 +25,7 @@ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T,
|
|
|
25
25
|
* @template T - The type of object.
|
|
26
26
|
* @param {T | null | undefined} obj - The object to pick keys from.
|
|
27
27
|
* @param {...any} keys
|
|
28
|
-
* @param {PropertyKey | PropertyKey[] |
|
|
28
|
+
* @param {PropertyKey | PropertyKey[] | PropertyKey[][]}} keys - An array of keys to be picked from the object. received keys goes through a flattening process before being used.
|
|
29
29
|
* @returns {Partial<T, K>} A new object with the specified keys picked.
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
3
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
4
|
+
*
|
|
5
|
+
* You can provide multiple source objects to set these default values,
|
|
6
|
+
* and they will be applied in the order they are given, from left to right.
|
|
7
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
8
|
+
*
|
|
9
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
10
|
+
*
|
|
11
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
12
|
+
*
|
|
13
|
+
* @template T - The type of the object being processed.
|
|
14
|
+
* @param {T} object - The target object.
|
|
15
|
+
* @returns {T} The cloned object.
|
|
16
|
+
*/
|
|
17
|
+
declare function toDefaulted<T extends object>(object: T): T;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
20
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
21
|
+
*
|
|
22
|
+
* You can provide multiple source objects to set these default values,
|
|
23
|
+
* and they will be applied in the order they are given, from left to right.
|
|
24
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
25
|
+
*
|
|
26
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
27
|
+
*
|
|
28
|
+
* @template T - The type of the object being processed.
|
|
29
|
+
* @template S - The type of the object that provides default values.
|
|
30
|
+
* @param {T} object - The target object that will receive default values.
|
|
31
|
+
* @param {S} source - The object that specifies the default values to apply.
|
|
32
|
+
* @returns {NonNullable<T & S>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|
33
|
+
*/
|
|
34
|
+
declare function toDefaulted<T extends object, S extends object>(object: T, source: S): NonNullable<T & S>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
37
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
38
|
+
*
|
|
39
|
+
* You can provide multiple source objects to set these default values,
|
|
40
|
+
* and they will be applied in the order they are given, from left to right.
|
|
41
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
42
|
+
*
|
|
43
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
44
|
+
*
|
|
45
|
+
* @template T - The type of the object being processed.
|
|
46
|
+
* @template S1 - The type of the first object that provides default values.
|
|
47
|
+
* @template S2 - The type of the second object that provides default values.
|
|
48
|
+
* @param {T} object - The target object that will receive default values.
|
|
49
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
50
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
51
|
+
* @returns {NonNullable<T & S1 & S2>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|
52
|
+
*/
|
|
53
|
+
declare function toDefaulted<T extends object, S1 extends object, S2 extends object>(object: T, source1: S1, source2: S2): NonNullable<T & S1 & S2>;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
56
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
57
|
+
*
|
|
58
|
+
* You can provide multiple source objects to set these default values,
|
|
59
|
+
* and they will be applied in the order they are given, from left to right.
|
|
60
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
61
|
+
*
|
|
62
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
63
|
+
*
|
|
64
|
+
* @template T - The type of the object being processed.
|
|
65
|
+
* @template S1 - The type of the first object that provides default values.
|
|
66
|
+
* @template S2 - The type of the second object that provides default values.
|
|
67
|
+
* @template S3 - The type of the third object that provides default values.
|
|
68
|
+
* @param {T} object - The target object that will receive default values.
|
|
69
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
70
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
71
|
+
* @param {S3} source3 - The third object that specifies the default values to apply.
|
|
72
|
+
* @returns {NonNullable<T & S1 & S2 & S3>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|
73
|
+
*/
|
|
74
|
+
declare function toDefaulted<T extends object, S1 extends object, S2 extends object, S3 extends object>(object: T, source1: S1, source2: S2, source3: S3): NonNullable<T & S1 & S2 & S3>;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
77
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
78
|
+
*
|
|
79
|
+
* You can provide multiple source objects to set these default values,
|
|
80
|
+
* and they will be applied in the order they are given, from left to right.
|
|
81
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
82
|
+
*
|
|
83
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
84
|
+
*
|
|
85
|
+
* @template T - The type of the object being processed.
|
|
86
|
+
* @template S1 - The type of the first object that provides default values.
|
|
87
|
+
* @template S2 - The type of the second object that provides default values.
|
|
88
|
+
* @template S3 - The type of the third object that provides default values.
|
|
89
|
+
* @template S4 - The type of the fourth object that provides default values.
|
|
90
|
+
* @param {T} object - The target object that will receive default values.
|
|
91
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
92
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
93
|
+
* @param {S3} source3 - The third object that specifies the default values to apply.
|
|
94
|
+
* @param {S4} source4 - The fourth object that specifies the default values to apply.
|
|
95
|
+
* @returns {NonNullable<T & S1 & S2 & S3 & S4>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|
96
|
+
*/
|
|
97
|
+
declare function toDefaulted<T extends object, S1 extends object, S2 extends object, S3 extends object, S4 extends object>(object: T, source1: S1, source2: S2, source3: S3, source4: S4): NonNullable<T & S1 & S2 & S3 & S4>;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
100
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
101
|
+
*
|
|
102
|
+
* You can provide multiple source objects to set these default values,
|
|
103
|
+
* and they will be applied in the order they are given, from left to right.
|
|
104
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
105
|
+
*
|
|
106
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
107
|
+
*
|
|
108
|
+
* @template T - The type of the object being processed.
|
|
109
|
+
* @template S - The type of the objects that provides default values.
|
|
110
|
+
* @param {T} object - The target object that will receive default values.
|
|
111
|
+
* @param {S[]} sources - The objects that specifies the default values to apply.
|
|
112
|
+
* @returns {object} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* toDefaulted({ a: 1 }, { a: 2, b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|
116
|
+
* toDefaulted({ a: 1, b: 2 }, { b: 3 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|
117
|
+
* toDefaulted({ a: null }, { a: 1 }); // { a: null }
|
|
118
|
+
* toDefaulted({ a: undefined }, { a: 1 }); // { a: 1 }
|
|
119
|
+
*/
|
|
120
|
+
declare function toDefaulted<T extends object, S extends object>(object: T, ...sources: S[]): object;
|
|
121
|
+
|
|
122
|
+
export { toDefaulted };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
3
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
4
|
+
*
|
|
5
|
+
* You can provide multiple source objects to set these default values,
|
|
6
|
+
* and they will be applied in the order they are given, from left to right.
|
|
7
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
8
|
+
*
|
|
9
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
10
|
+
*
|
|
11
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
12
|
+
*
|
|
13
|
+
* @template T - The type of the object being processed.
|
|
14
|
+
* @param {T} object - The target object.
|
|
15
|
+
* @returns {T} The cloned object.
|
|
16
|
+
*/
|
|
17
|
+
declare function toDefaulted<T extends object>(object: T): T;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
20
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
21
|
+
*
|
|
22
|
+
* You can provide multiple source objects to set these default values,
|
|
23
|
+
* and they will be applied in the order they are given, from left to right.
|
|
24
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
25
|
+
*
|
|
26
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
27
|
+
*
|
|
28
|
+
* @template T - The type of the object being processed.
|
|
29
|
+
* @template S - The type of the object that provides default values.
|
|
30
|
+
* @param {T} object - The target object that will receive default values.
|
|
31
|
+
* @param {S} source - The object that specifies the default values to apply.
|
|
32
|
+
* @returns {NonNullable<T & S>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|
33
|
+
*/
|
|
34
|
+
declare function toDefaulted<T extends object, S extends object>(object: T, source: S): NonNullable<T & S>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
37
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
38
|
+
*
|
|
39
|
+
* You can provide multiple source objects to set these default values,
|
|
40
|
+
* and they will be applied in the order they are given, from left to right.
|
|
41
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
42
|
+
*
|
|
43
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
44
|
+
*
|
|
45
|
+
* @template T - The type of the object being processed.
|
|
46
|
+
* @template S1 - The type of the first object that provides default values.
|
|
47
|
+
* @template S2 - The type of the second object that provides default values.
|
|
48
|
+
* @param {T} object - The target object that will receive default values.
|
|
49
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
50
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
51
|
+
* @returns {NonNullable<T & S1 & S2>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|
52
|
+
*/
|
|
53
|
+
declare function toDefaulted<T extends object, S1 extends object, S2 extends object>(object: T, source1: S1, source2: S2): NonNullable<T & S1 & S2>;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
56
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
57
|
+
*
|
|
58
|
+
* You can provide multiple source objects to set these default values,
|
|
59
|
+
* and they will be applied in the order they are given, from left to right.
|
|
60
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
61
|
+
*
|
|
62
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
63
|
+
*
|
|
64
|
+
* @template T - The type of the object being processed.
|
|
65
|
+
* @template S1 - The type of the first object that provides default values.
|
|
66
|
+
* @template S2 - The type of the second object that provides default values.
|
|
67
|
+
* @template S3 - The type of the third object that provides default values.
|
|
68
|
+
* @param {T} object - The target object that will receive default values.
|
|
69
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
70
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
71
|
+
* @param {S3} source3 - The third object that specifies the default values to apply.
|
|
72
|
+
* @returns {NonNullable<T & S1 & S2 & S3>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|
73
|
+
*/
|
|
74
|
+
declare function toDefaulted<T extends object, S1 extends object, S2 extends object, S3 extends object>(object: T, source1: S1, source2: S2, source3: S3): NonNullable<T & S1 & S2 & S3>;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
77
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
78
|
+
*
|
|
79
|
+
* You can provide multiple source objects to set these default values,
|
|
80
|
+
* and they will be applied in the order they are given, from left to right.
|
|
81
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
82
|
+
*
|
|
83
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
84
|
+
*
|
|
85
|
+
* @template T - The type of the object being processed.
|
|
86
|
+
* @template S1 - The type of the first object that provides default values.
|
|
87
|
+
* @template S2 - The type of the second object that provides default values.
|
|
88
|
+
* @template S3 - The type of the third object that provides default values.
|
|
89
|
+
* @template S4 - The type of the fourth object that provides default values.
|
|
90
|
+
* @param {T} object - The target object that will receive default values.
|
|
91
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
92
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
93
|
+
* @param {S3} source3 - The third object that specifies the default values to apply.
|
|
94
|
+
* @param {S4} source4 - The fourth object that specifies the default values to apply.
|
|
95
|
+
* @returns {NonNullable<T & S1 & S2 & S3 & S4>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|
96
|
+
*/
|
|
97
|
+
declare function toDefaulted<T extends object, S1 extends object, S2 extends object, S3 extends object, S4 extends object>(object: T, source1: S1, source2: S2, source3: S3, source4: S4): NonNullable<T & S1 & S2 & S3 & S4>;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|
100
|
+
* It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|
101
|
+
*
|
|
102
|
+
* You can provide multiple source objects to set these default values,
|
|
103
|
+
* and they will be applied in the order they are given, from left to right.
|
|
104
|
+
* Once a property has been set, any later values for that property will be ignored.
|
|
105
|
+
*
|
|
106
|
+
* Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|
107
|
+
*
|
|
108
|
+
* @template T - The type of the object being processed.
|
|
109
|
+
* @template S - The type of the objects that provides default values.
|
|
110
|
+
* @param {T} object - The target object that will receive default values.
|
|
111
|
+
* @param {S[]} sources - The objects that specifies the default values to apply.
|
|
112
|
+
* @returns {object} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* toDefaulted({ a: 1 }, { a: 2, b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|
116
|
+
* toDefaulted({ a: 1, b: 2 }, { b: 3 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|
117
|
+
* toDefaulted({ a: null }, { a: 1 }); // { a: null }
|
|
118
|
+
* toDefaulted({ a: undefined }, { a: 1 }); // { a: 1 }
|
|
119
|
+
*/
|
|
120
|
+
declare function toDefaulted<T extends object, S extends object>(object: T, ...sources: S[]): object;
|
|
121
|
+
|
|
122
|
+
export { toDefaulted };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given value is `ArrayBuffer`.
|
|
3
|
+
*
|
|
4
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `ArrayBuffer`.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value The value to check if it is a `ArrayBuffer`.
|
|
7
|
+
* @returns {value is ArrayBuffer} Returns `true` if `value` is a `ArrayBuffer`, else `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const value1 = new ArrayBuffer();
|
|
11
|
+
* const value2 = new Array();
|
|
12
|
+
* const value3 = new Map();
|
|
13
|
+
*
|
|
14
|
+
* console.log(isArrayBuffer(value1)); // true
|
|
15
|
+
* console.log(isArrayBuffer(value2)); // false
|
|
16
|
+
* console.log(isArrayBuffer(value3)); // false
|
|
17
|
+
*/
|
|
18
|
+
declare function isArrayBuffer(value?: unknown): value is ArrayBuffer;
|
|
19
|
+
|
|
20
|
+
export { isArrayBuffer };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given value is `ArrayBuffer`.
|
|
3
|
+
*
|
|
4
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `ArrayBuffer`.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value The value to check if it is a `ArrayBuffer`.
|
|
7
|
+
* @returns {value is ArrayBuffer} Returns `true` if `value` is a `ArrayBuffer`, else `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const value1 = new ArrayBuffer();
|
|
11
|
+
* const value2 = new Array();
|
|
12
|
+
* const value3 = new Map();
|
|
13
|
+
*
|
|
14
|
+
* console.log(isArrayBuffer(value1)); // true
|
|
15
|
+
* console.log(isArrayBuffer(value2)); // false
|
|
16
|
+
* console.log(isArrayBuffer(value3)); // false
|
|
17
|
+
*/
|
|
18
|
+
declare function isArrayBuffer(value?: unknown): value is ArrayBuffer;
|
|
19
|
+
|
|
20
|
+
export { isArrayBuffer };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if `value` is a Date object.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} value The value to check.
|
|
5
|
+
* @returns {value is Date} Returns `true` if `value` is a Date object, `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const value1 = new Date();
|
|
9
|
+
* const value2 = '2024-01-01';
|
|
10
|
+
*
|
|
11
|
+
* console.log(isDate(value1)); // true
|
|
12
|
+
* console.log(isDate(value2)); // false
|
|
13
|
+
*/
|
|
14
|
+
declare function isDate(value?: unknown): value is Date;
|
|
15
|
+
|
|
16
|
+
export { isDate };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if `value` is a Date object.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} value The value to check.
|
|
5
|
+
* @returns {value is Date} Returns `true` if `value` is a Date object, `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const value1 = new Date();
|
|
9
|
+
* const value2 = '2024-01-01';
|
|
10
|
+
*
|
|
11
|
+
* console.log(isDate(value1)); // true
|
|
12
|
+
* console.log(isDate(value2)); // false
|
|
13
|
+
*/
|
|
14
|
+
declare function isDate(value?: unknown): value is Date;
|
|
15
|
+
|
|
16
|
+
export { isDate };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two values for equality using a custom comparison function.
|
|
3
|
+
*
|
|
4
|
+
* The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
|
|
5
|
+
*
|
|
6
|
+
* This function also uses the custom equality function to compare values inside objects,
|
|
7
|
+
* arrays, maps, sets, and other complex structures, ensuring a deep comparison.
|
|
8
|
+
*
|
|
9
|
+
* This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
|
|
10
|
+
*
|
|
11
|
+
* The custom comparison function can take up to six parameters:
|
|
12
|
+
* - `x`: The value from the first object `a`.
|
|
13
|
+
* - `y`: The value from the second object `b`.
|
|
14
|
+
* - `property`: The property key used to get `x` and `y`.
|
|
15
|
+
* - `xParent`: The parent of the first value `x`.
|
|
16
|
+
* - `yParent`: The parent of the second value `y`.
|
|
17
|
+
* - `stack`: An internal stack (Map) to handle circular references.
|
|
18
|
+
*
|
|
19
|
+
* @param {unknown} a - The first value to compare.
|
|
20
|
+
* @param {unknown} b - The second value to compare.
|
|
21
|
+
* @param {(x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void} [areValuesEqual=noop] - A function to customize the comparison.
|
|
22
|
+
* If it returns a boolean, that result will be used. If it returns undefined,
|
|
23
|
+
* the default equality comparison will be used.
|
|
24
|
+
* @returns {boolean} `true` if the values are equal according to the customizer, otherwise `false`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const customizer = (a, b) => {
|
|
28
|
+
* if (typeof a === 'string' && typeof b === 'string') {
|
|
29
|
+
* return a.toLowerCase() === b.toLowerCase();
|
|
30
|
+
* }
|
|
31
|
+
* };
|
|
32
|
+
* isEqualWith('Hello', 'hello', customizer); // true
|
|
33
|
+
* isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
|
|
34
|
+
* isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
|
|
35
|
+
*/
|
|
36
|
+
declare function isEqualWith(a: any, b: any, areValuesEqual?: (a: any, b: any, property?: PropertyKey, aParent?: any, bParent?: any, stack?: Map<any, any>) => boolean | void): boolean;
|
|
37
|
+
|
|
38
|
+
export { isEqualWith };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two values for equality using a custom comparison function.
|
|
3
|
+
*
|
|
4
|
+
* The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
|
|
5
|
+
*
|
|
6
|
+
* This function also uses the custom equality function to compare values inside objects,
|
|
7
|
+
* arrays, maps, sets, and other complex structures, ensuring a deep comparison.
|
|
8
|
+
*
|
|
9
|
+
* This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
|
|
10
|
+
*
|
|
11
|
+
* The custom comparison function can take up to six parameters:
|
|
12
|
+
* - `x`: The value from the first object `a`.
|
|
13
|
+
* - `y`: The value from the second object `b`.
|
|
14
|
+
* - `property`: The property key used to get `x` and `y`.
|
|
15
|
+
* - `xParent`: The parent of the first value `x`.
|
|
16
|
+
* - `yParent`: The parent of the second value `y`.
|
|
17
|
+
* - `stack`: An internal stack (Map) to handle circular references.
|
|
18
|
+
*
|
|
19
|
+
* @param {unknown} a - The first value to compare.
|
|
20
|
+
* @param {unknown} b - The second value to compare.
|
|
21
|
+
* @param {(x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void} [areValuesEqual=noop] - A function to customize the comparison.
|
|
22
|
+
* If it returns a boolean, that result will be used. If it returns undefined,
|
|
23
|
+
* the default equality comparison will be used.
|
|
24
|
+
* @returns {boolean} `true` if the values are equal according to the customizer, otherwise `false`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const customizer = (a, b) => {
|
|
28
|
+
* if (typeof a === 'string' && typeof b === 'string') {
|
|
29
|
+
* return a.toLowerCase() === b.toLowerCase();
|
|
30
|
+
* }
|
|
31
|
+
* };
|
|
32
|
+
* isEqualWith('Hello', 'hello', customizer); // true
|
|
33
|
+
* isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
|
|
34
|
+
* isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
|
|
35
|
+
*/
|
|
36
|
+
declare function isEqualWith(a: any, b: any, areValuesEqual?: (a: any, b: any, property?: PropertyKey, aParent?: any, bParent?: any, stack?: Map<any, any>) => boolean | void): boolean;
|
|
37
|
+
|
|
38
|
+
export { isEqualWith };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { after } from '../../function/after.mjs';
|
|
2
|
+
import { noop } from '../../function/noop.mjs';
|
|
3
|
+
import { isEqualWith as isEqualWith$1 } from '../../predicate/isEqualWith.mjs';
|
|
4
|
+
|
|
5
|
+
function isEqualWith(a, b, areValuesEqual = noop) {
|
|
6
|
+
if (typeof areValuesEqual !== 'function') {
|
|
7
|
+
areValuesEqual = noop;
|
|
8
|
+
}
|
|
9
|
+
return isEqualWith$1(a, b, (...args) => {
|
|
10
|
+
const result = areValuesEqual(...args);
|
|
11
|
+
if (result !== undefined) {
|
|
12
|
+
return Boolean(result);
|
|
13
|
+
}
|
|
14
|
+
if (a instanceof Map && b instanceof Map) {
|
|
15
|
+
return isEqualWith(Array.from(a), Array.from(b), after(2, areValuesEqual));
|
|
16
|
+
}
|
|
17
|
+
if (a instanceof Set && b instanceof Set) {
|
|
18
|
+
return isEqualWith(Array.from(a), Array.from(b), after(2, areValuesEqual));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { isEqualWith };
|
|
@@ -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 };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isObject } from './isObject.mjs';
|
|
2
2
|
import { isPrimitive } from '../../predicate/isPrimitive.mjs';
|
|
3
|
+
import { eq } from '../util/eq.mjs';
|
|
3
4
|
|
|
4
5
|
function isMatch(target, source) {
|
|
5
6
|
if (source === target) {
|
|
@@ -48,7 +49,7 @@ function isMatch(target, source) {
|
|
|
48
49
|
}
|
|
49
50
|
default: {
|
|
50
51
|
if (!isObject(target)) {
|
|
51
|
-
return
|
|
52
|
+
return eq(target, source);
|
|
52
53
|
}
|
|
53
54
|
return !source;
|
|
54
55
|
}
|
|
@@ -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,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new function that always returns `undefined`.
|
|
3
|
+
*
|
|
4
|
+
* @returns {() => undefined} Returns the new constant function.
|
|
5
|
+
*/
|
|
6
|
+
declare function constant(): () => undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new function that always returns `value`.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of the value to return.
|
|
11
|
+
* @param {T} value - The value to return from the new function.
|
|
12
|
+
* @returns {() => T} Returns the new constant function.
|
|
13
|
+
*/
|
|
14
|
+
declare function constant<T>(value: T): () => T;
|
|
15
|
+
|
|
16
|
+
export { constant };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new function that always returns `undefined`.
|
|
3
|
+
*
|
|
4
|
+
* @returns {() => undefined} Returns the new constant function.
|
|
5
|
+
*/
|
|
6
|
+
declare function constant(): () => undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new function that always returns `value`.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of the value to return.
|
|
11
|
+
* @param {T} value - The value to return from the new function.
|
|
12
|
+
* @returns {() => T} Returns the new constant function.
|
|
13
|
+
*/
|
|
14
|
+
declare function constant<T>(value: T): () => T;
|
|
15
|
+
|
|
16
|
+
export { constant };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the default value for `null`, `undefined`, and `NaN`.
|
|
3
|
+
*
|
|
4
|
+
* @param {T | null | undefined} value - The value to check.
|
|
5
|
+
* @param {T} [defaultValue] - The default value to return if the first value is null, undefined, or NaN.
|
|
6
|
+
* @returns {T} Returns either the first value or the default value.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* defaultTo(null, 'default') // returns 'default'
|
|
10
|
+
* defaultTo(undefined, 42) // returns 42
|
|
11
|
+
* defaultTo(NaN, 0) // returns 0
|
|
12
|
+
* defaultTo('actual', 'default') // returns 'actual'
|
|
13
|
+
* defaultTo(123, 0) // returns 123
|
|
14
|
+
*/
|
|
15
|
+
declare function defaultTo<T>(value: T | null | undefined, defaultValue?: T): T;
|
|
16
|
+
|
|
17
|
+
export { defaultTo };
|