es-toolkit 1.32.0 → 1.33.0-dev.1025
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 -1
- package/dist/_chunk/{isWeakSet-DoHqUM.js → isWeakSet-TIM260.js} +14 -0
- package/dist/_chunk/{toMerged-BQTfB8.js → toMerged-CwnQF6.js} +0 -14
- package/dist/_chunk/{upperFirst-CorAVn.js → upperFirst-nA5L7X.js} +5 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/find.mjs +12 -32
- package/dist/compat/array/findLast.d.mts +130 -0
- package/dist/compat/array/findLast.d.ts +130 -0
- package/dist/compat/array/findLast.mjs +32 -0
- package/dist/compat/array/intersectionWith.d.mts +96 -0
- package/dist/compat/array/intersectionWith.d.ts +96 -0
- package/dist/compat/array/intersectionWith.mjs +43 -0
- package/dist/compat/array/pullAllBy.d.mts +64 -0
- package/dist/compat/array/pullAllBy.d.ts +64 -0
- package/dist/compat/array/pullAllBy.mjs +22 -0
- package/dist/compat/array/reduce.d.mts +109 -0
- package/dist/compat/array/reduce.d.ts +109 -0
- package/dist/compat/array/reduce.mjs +33 -0
- package/dist/compat/array/reduceRight.d.mts +109 -0
- package/dist/compat/array/reduceRight.d.ts +109 -0
- package/dist/compat/array/reduceRight.mjs +39 -0
- package/dist/compat/index.d.mts +12 -3
- package/dist/compat/index.d.ts +12 -3
- package/dist/compat/index.js +264 -63
- package/dist/compat/index.mjs +12 -3
- package/dist/compat/math/divide.d.mts +18 -0
- package/dist/compat/math/divide.d.ts +18 -0
- package/dist/compat/math/divide.mjs +23 -0
- package/dist/compat/math/maxBy.d.mts +31 -0
- package/dist/compat/math/maxBy.d.ts +31 -0
- package/dist/compat/math/maxBy.mjs +11 -0
- package/dist/compat/math/multiply.mjs +4 -3
- package/dist/compat/math/sumBy.mjs +8 -3
- package/dist/compat/object/assignIn.mjs +1 -1
- package/dist/compat/object/pickBy.d.mts +22 -0
- package/dist/compat/object/pickBy.d.ts +22 -0
- package/dist/compat/object/pickBy.mjs +23 -0
- package/dist/compat/object/values.d.mts +32 -0
- package/dist/compat/object/values.d.ts +32 -0
- package/dist/compat/object/values.mjs +5 -0
- package/dist/compat/object/valuesIn.d.mts +63 -0
- package/dist/compat/object/valuesIn.d.ts +63 -0
- package/dist/compat/object/valuesIn.mjs +13 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -4
- package/dist/index.mjs +2 -0
- package/dist/object/flattenObject.d.mts +1 -1
- package/dist/object/flattenObject.d.ts +1 -1
- package/dist/object/index.js +15 -2
- package/dist/predicate/index.d.mts +1 -0
- package/dist/predicate/index.d.ts +1 -0
- package/dist/predicate/index.js +2 -1
- package/dist/predicate/index.mjs +1 -0
- package/dist/predicate/isJSON.d.mts +31 -0
- package/dist/predicate/isJSON.d.ts +31 -0
- package/dist/predicate/isJSON.mjs +14 -0
- package/dist/string/index.d.mts +1 -0
- package/dist/string/index.d.ts +1 -0
- package/dist/string/index.js +2 -1
- package/dist/string/index.mjs +1 -0
- package/dist/string/reverseString.d.mts +16 -0
- package/dist/string/reverseString.d.ts +16 -0
- package/dist/string/reverseString.mjs +5 -0
- package/package.json +2 -1
package/dist/compat/index.mjs
CHANGED
|
@@ -5,11 +5,9 @@ export { flatMapDeep } from '../array/flatMapDeep.mjs';
|
|
|
5
5
|
export { forEachRight } from '../array/forEachRight.mjs';
|
|
6
6
|
export { groupBy } from '../array/groupBy.mjs';
|
|
7
7
|
export { initial } from '../array/initial.mjs';
|
|
8
|
-
export { intersectionWith } from '../array/intersectionWith.mjs';
|
|
9
8
|
export { isSubset } from '../array/isSubset.mjs';
|
|
10
9
|
export { isSubsetWith } from '../array/isSubsetWith.mjs';
|
|
11
10
|
export { keyBy } from '../array/keyBy.mjs';
|
|
12
|
-
export { maxBy } from '../array/maxBy.mjs';
|
|
13
11
|
export { minBy } from '../array/minBy.mjs';
|
|
14
12
|
export { partition } from '../array/partition.mjs';
|
|
15
13
|
export { pullAt } from '../array/pullAt.mjs';
|
|
@@ -49,13 +47,13 @@ export { flattenObject } from '../object/flattenObject.mjs';
|
|
|
49
47
|
export { invert } from '../object/invert.mjs';
|
|
50
48
|
export { isObjectLike } from './predicate/isObjectLike.mjs';
|
|
51
49
|
export { omitBy } from '../object/omitBy.mjs';
|
|
52
|
-
export { pickBy } from '../object/pickBy.mjs';
|
|
53
50
|
export { toMerged } from '../object/toMerged.mjs';
|
|
54
51
|
export { isBlob } from '../predicate/isBlob.mjs';
|
|
55
52
|
export { isEqual } from '../predicate/isEqual.mjs';
|
|
56
53
|
export { eq } from './util/eq.mjs';
|
|
57
54
|
export { isFile } from '../predicate/isFile.mjs';
|
|
58
55
|
export { isFunction } from '../predicate/isFunction.mjs';
|
|
56
|
+
export { isJSON } from '../predicate/isJSON.mjs';
|
|
59
57
|
export { isJSONArray, isJSONObject, isJSONValue } from '../predicate/isJSONValue.mjs';
|
|
60
58
|
export { isLength } from '../predicate/isLength.mjs';
|
|
61
59
|
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
@@ -70,6 +68,7 @@ export { capitalize } from '../string/capitalize.mjs';
|
|
|
70
68
|
export { constantCase } from '../string/constantCase.mjs';
|
|
71
69
|
import '../string/deburr.mjs';
|
|
72
70
|
export { pascalCase } from '../string/pascalCase.mjs';
|
|
71
|
+
export { reverseString } from '../string/reverseString.mjs';
|
|
73
72
|
export { invariant } from '../util/invariant.mjs';
|
|
74
73
|
export { castArray } from './array/castArray.mjs';
|
|
75
74
|
export { chunk } from './array/chunk.mjs';
|
|
@@ -87,6 +86,7 @@ export { fill } from './array/fill.mjs';
|
|
|
87
86
|
export { filter } from './array/filter.mjs';
|
|
88
87
|
export { find } from './array/find.mjs';
|
|
89
88
|
export { findIndex } from './array/findIndex.mjs';
|
|
89
|
+
export { findLast } from './array/findLast.mjs';
|
|
90
90
|
export { findLastIndex } from './array/findLastIndex.mjs';
|
|
91
91
|
export { flatten } from './array/flatten.mjs';
|
|
92
92
|
export { flattenDeep } from './array/flattenDeep.mjs';
|
|
@@ -97,6 +97,7 @@ export { includes } from './array/includes.mjs';
|
|
|
97
97
|
export { indexOf } from './array/indexOf.mjs';
|
|
98
98
|
export { intersection } from './array/intersection.mjs';
|
|
99
99
|
export { intersectionBy } from './array/intersectionBy.mjs';
|
|
100
|
+
export { intersectionWith } from './array/intersectionWith.mjs';
|
|
100
101
|
export { join } from './array/join.mjs';
|
|
101
102
|
export { last } from './array/last.mjs';
|
|
102
103
|
export { lastIndexOf } from './array/lastIndexOf.mjs';
|
|
@@ -105,6 +106,9 @@ export { nth } from './array/nth.mjs';
|
|
|
105
106
|
export { orderBy } from './array/orderBy.mjs';
|
|
106
107
|
export { pull } from './array/pull.mjs';
|
|
107
108
|
export { pullAll } from './array/pullAll.mjs';
|
|
109
|
+
export { pullAllBy } from './array/pullAllBy.mjs';
|
|
110
|
+
export { reduce } from './array/reduce.mjs';
|
|
111
|
+
export { reduceRight } from './array/reduceRight.mjs';
|
|
108
112
|
export { remove } from './array/remove.mjs';
|
|
109
113
|
export { reverse } from './array/reverse.mjs';
|
|
110
114
|
export { sample } from './array/sample.mjs';
|
|
@@ -148,9 +152,11 @@ export { throttle } from './function/throttle.mjs';
|
|
|
148
152
|
export { add } from './math/add.mjs';
|
|
149
153
|
export { ceil } from './math/ceil.mjs';
|
|
150
154
|
export { clamp } from './math/clamp.mjs';
|
|
155
|
+
export { divide } from './math/divide.mjs';
|
|
151
156
|
export { floor } from './math/floor.mjs';
|
|
152
157
|
export { inRange } from './math/inRange.mjs';
|
|
153
158
|
export { max } from './math/max.mjs';
|
|
159
|
+
export { maxBy } from './math/maxBy.mjs';
|
|
154
160
|
export { min } from './math/min.mjs';
|
|
155
161
|
export { multiply } from './math/multiply.mjs';
|
|
156
162
|
export { parseInt } from './math/parseInt.mjs';
|
|
@@ -178,11 +184,14 @@ export { merge } from './object/merge.mjs';
|
|
|
178
184
|
export { mergeWith } from './object/mergeWith.mjs';
|
|
179
185
|
export { omit } from './object/omit.mjs';
|
|
180
186
|
export { pick } from './object/pick.mjs';
|
|
187
|
+
export { pickBy } from './object/pickBy.mjs';
|
|
181
188
|
export { property } from './object/property.mjs';
|
|
182
189
|
export { propertyOf } from './object/propertyOf.mjs';
|
|
183
190
|
export { set } from './object/set.mjs';
|
|
184
191
|
export { toDefaulted } from './object/toDefaulted.mjs';
|
|
185
192
|
export { unset } from './object/unset.mjs';
|
|
193
|
+
export { values } from './object/values.mjs';
|
|
194
|
+
export { valuesIn } from './object/valuesIn.mjs';
|
|
186
195
|
export { conforms } from './predicate/conforms.mjs';
|
|
187
196
|
export { conformsTo } from './predicate/conformsTo.mjs';
|
|
188
197
|
export { isArguments } from './predicate/isArguments.mjs';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Divide two numbers.
|
|
3
|
+
*
|
|
4
|
+
* If either of the numbers is `NaN`, the function returns `NaN`.
|
|
5
|
+
*
|
|
6
|
+
* @param {number} value The first number in a division.
|
|
7
|
+
* @param {number} other The second number in a division.
|
|
8
|
+
* @returns {number} The quotient of value and other.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* divide(6, 3); // => 2
|
|
12
|
+
* divide(2, NaN); // => NaN
|
|
13
|
+
* divide(NaN, 3); // => NaN
|
|
14
|
+
* divide(NaN, NaN); // => NaN
|
|
15
|
+
*/
|
|
16
|
+
declare function divide(value: number, other: number): number;
|
|
17
|
+
|
|
18
|
+
export { divide };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Divide two numbers.
|
|
3
|
+
*
|
|
4
|
+
* If either of the numbers is `NaN`, the function returns `NaN`.
|
|
5
|
+
*
|
|
6
|
+
* @param {number} value The first number in a division.
|
|
7
|
+
* @param {number} other The second number in a division.
|
|
8
|
+
* @returns {number} The quotient of value and other.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* divide(6, 3); // => 2
|
|
12
|
+
* divide(2, NaN); // => NaN
|
|
13
|
+
* divide(NaN, 3); // => NaN
|
|
14
|
+
* divide(NaN, NaN); // => NaN
|
|
15
|
+
*/
|
|
16
|
+
declare function divide(value: number, other: number): number;
|
|
17
|
+
|
|
18
|
+
export { divide };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { toNumber } from '../util/toNumber.mjs';
|
|
2
|
+
import { toString } from '../util/toString.mjs';
|
|
3
|
+
|
|
4
|
+
function divide(value, other) {
|
|
5
|
+
console.log(value, other);
|
|
6
|
+
if (value === undefined && other === undefined) {
|
|
7
|
+
return 1;
|
|
8
|
+
}
|
|
9
|
+
if (value === undefined || other === undefined) {
|
|
10
|
+
return value ?? other;
|
|
11
|
+
}
|
|
12
|
+
if (typeof value === 'string' || typeof other === 'string') {
|
|
13
|
+
value = toString(value);
|
|
14
|
+
other = toString(other);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
value = toNumber(value);
|
|
18
|
+
other = toNumber(other);
|
|
19
|
+
}
|
|
20
|
+
return value / other;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { divide };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the element in an array that has the maximum value when applying
|
|
3
|
+
* the `iteratee` to each element.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of elements in the array.
|
|
6
|
+
* @param {T[]} items The array of elements to search.
|
|
7
|
+
* @param {((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>} iteratee
|
|
8
|
+
* The criteria used to determine the maximum value.
|
|
9
|
+
* - If a **function** is provided, it extracts a numeric value from each element.
|
|
10
|
+
* - If a **string** is provided, it is treated as a key to extract values from the objects.
|
|
11
|
+
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
|
|
12
|
+
* - If an **object** is provided, it matches elements that contain the specified properties.
|
|
13
|
+
* @returns {T | undefined} The element with the maximum value as determined by the `iteratee`.
|
|
14
|
+
* @example
|
|
15
|
+
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
|
|
16
|
+
* maxBy([], x => x.a); // Returns: undefined
|
|
17
|
+
* maxBy(
|
|
18
|
+
* [
|
|
19
|
+
* { name: 'john', age: 30 },
|
|
20
|
+
* { name: 'jane', age: 28 },
|
|
21
|
+
* { name: 'joe', age: 26 },
|
|
22
|
+
* ],
|
|
23
|
+
* x => x.age
|
|
24
|
+
* ); // Returns: { name: 'john', age: 30 }
|
|
25
|
+
* maxBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 2 }
|
|
26
|
+
* maxBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 1 }
|
|
27
|
+
* maxBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 1 }
|
|
28
|
+
*/
|
|
29
|
+
declare function maxBy<T>(items: ArrayLike<T> | null | undefined, iteratee: ((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>): T | undefined;
|
|
30
|
+
|
|
31
|
+
export { maxBy };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the element in an array that has the maximum value when applying
|
|
3
|
+
* the `iteratee` to each element.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of elements in the array.
|
|
6
|
+
* @param {T[]} items The array of elements to search.
|
|
7
|
+
* @param {((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>} iteratee
|
|
8
|
+
* The criteria used to determine the maximum value.
|
|
9
|
+
* - If a **function** is provided, it extracts a numeric value from each element.
|
|
10
|
+
* - If a **string** is provided, it is treated as a key to extract values from the objects.
|
|
11
|
+
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
|
|
12
|
+
* - If an **object** is provided, it matches elements that contain the specified properties.
|
|
13
|
+
* @returns {T | undefined} The element with the maximum value as determined by the `iteratee`.
|
|
14
|
+
* @example
|
|
15
|
+
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
|
|
16
|
+
* maxBy([], x => x.a); // Returns: undefined
|
|
17
|
+
* maxBy(
|
|
18
|
+
* [
|
|
19
|
+
* { name: 'john', age: 30 },
|
|
20
|
+
* { name: 'jane', age: 28 },
|
|
21
|
+
* { name: 'joe', age: 26 },
|
|
22
|
+
* ],
|
|
23
|
+
* x => x.age
|
|
24
|
+
* ); // Returns: { name: 'john', age: 30 }
|
|
25
|
+
* maxBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 2 }
|
|
26
|
+
* maxBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 1 }
|
|
27
|
+
* maxBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 1 }
|
|
28
|
+
*/
|
|
29
|
+
declare function maxBy<T>(items: ArrayLike<T> | null | undefined, iteratee: ((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>): T | undefined;
|
|
30
|
+
|
|
31
|
+
export { maxBy };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { maxBy as maxBy$1 } from '../../array/maxBy.mjs';
|
|
2
|
+
import { iteratee } from '../util/iteratee.mjs';
|
|
3
|
+
|
|
4
|
+
function maxBy(items, iteratee$1) {
|
|
5
|
+
if (items == null) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return maxBy$1(Array.from(items), iteratee(iteratee$1));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { maxBy };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toNumber } from '../util/toNumber.mjs';
|
|
1
2
|
import { toString } from '../util/toString.mjs';
|
|
2
3
|
|
|
3
4
|
function multiply(value, other) {
|
|
@@ -5,15 +6,15 @@ function multiply(value, other) {
|
|
|
5
6
|
return 1;
|
|
6
7
|
}
|
|
7
8
|
if (value === undefined || other === undefined) {
|
|
8
|
-
return value
|
|
9
|
+
return value ?? other;
|
|
9
10
|
}
|
|
10
11
|
if (typeof value === 'string' || typeof other === 'string') {
|
|
11
12
|
value = toString(value);
|
|
12
13
|
other = toString(other);
|
|
13
14
|
}
|
|
14
15
|
else {
|
|
15
|
-
value =
|
|
16
|
-
other =
|
|
16
|
+
value = toNumber(value);
|
|
17
|
+
other = toNumber(other);
|
|
17
18
|
}
|
|
18
19
|
return value * other;
|
|
19
20
|
}
|
|
@@ -7,11 +7,16 @@ function sumBy(array, iteratee$1) {
|
|
|
7
7
|
if (iteratee$1 != null) {
|
|
8
8
|
iteratee$1 = iteratee(iteratee$1);
|
|
9
9
|
}
|
|
10
|
-
let result =
|
|
11
|
-
for (let i =
|
|
10
|
+
let result = undefined;
|
|
11
|
+
for (let i = 0; i < array.length; i++) {
|
|
12
12
|
const current = iteratee$1 ? iteratee$1(array[i]) : array[i];
|
|
13
13
|
if (current !== undefined) {
|
|
14
|
-
result
|
|
14
|
+
if (result === undefined) {
|
|
15
|
+
result = current;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
result += current;
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
}
|
|
17
22
|
return result;
|
|
@@ -11,7 +11,7 @@ function assignInImpl(object, source) {
|
|
|
11
11
|
const keys = keysIn(source);
|
|
12
12
|
for (let i = 0; i < keys.length; i++) {
|
|
13
13
|
const key = keys[i];
|
|
14
|
-
if (!eq(object[key], source[key])) {
|
|
14
|
+
if (!(key in object) || !eq(object[key], source[key])) {
|
|
15
15
|
object[key] = source[key];
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object composed of the properties that satisfy the predicate function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and a predicate function, and returns a new object that
|
|
5
|
+
* includes only the properties for which the predicate function returns true.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of object.
|
|
8
|
+
* @param {T} obj - The object to pick properties from.
|
|
9
|
+
* @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines
|
|
10
|
+
* whether a property should be picked. It takes the property's key and value as arguments and returns `true`
|
|
11
|
+
* if the property should be picked, and `false` otherwise.
|
|
12
|
+
* @returns {Partial<T>} A new object with the properties that satisfy the predicate function.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const obj = { a: 1, b: 'pick', c: 3 };
|
|
16
|
+
* const shouldPick = (value) => typeof value === 'string';
|
|
17
|
+
* const result = pickBy(obj, shouldPick);
|
|
18
|
+
* // result will be { b: 'pick' }
|
|
19
|
+
*/
|
|
20
|
+
declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick?: (value: T[keyof T], key: keyof T, obj: T) => boolean): Partial<T>;
|
|
21
|
+
|
|
22
|
+
export { pickBy };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object composed of the properties that satisfy the predicate function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and a predicate function, and returns a new object that
|
|
5
|
+
* includes only the properties for which the predicate function returns true.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of object.
|
|
8
|
+
* @param {T} obj - The object to pick properties from.
|
|
9
|
+
* @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines
|
|
10
|
+
* whether a property should be picked. It takes the property's key and value as arguments and returns `true`
|
|
11
|
+
* if the property should be picked, and `false` otherwise.
|
|
12
|
+
* @returns {Partial<T>} A new object with the properties that satisfy the predicate function.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const obj = { a: 1, b: 'pick', c: 3 };
|
|
16
|
+
* const shouldPick = (value) => typeof value === 'string';
|
|
17
|
+
* const result = pickBy(obj, shouldPick);
|
|
18
|
+
* // result will be { b: 'pick' }
|
|
19
|
+
*/
|
|
20
|
+
declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick?: (value: T[keyof T], key: keyof T, obj: T) => boolean): Partial<T>;
|
|
21
|
+
|
|
22
|
+
export { pickBy };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { range } from '../../math/range.mjs';
|
|
2
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
|
+
|
|
4
|
+
function pickBy(obj, shouldPick) {
|
|
5
|
+
if (obj == null) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
const result = {};
|
|
9
|
+
if (shouldPick == null) {
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
const keys = isArrayLike(obj) ? range(0, obj.length) : Object.keys(obj);
|
|
13
|
+
for (let i = 0; i < keys.length; i++) {
|
|
14
|
+
const key = keys[i].toString();
|
|
15
|
+
const value = obj[key];
|
|
16
|
+
if (shouldPick(value, key, obj)) {
|
|
17
|
+
result[key] = value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { pickBy };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an array of the own enumerable property values of `object`.
|
|
3
|
+
*
|
|
4
|
+
* @param {Record<PropertyKey, T> | null | undefined} object The object to query.
|
|
5
|
+
* @returns {T[]} Returns an array of property values.
|
|
6
|
+
* @example
|
|
7
|
+
* const object = { a: 1, b: 2 };
|
|
8
|
+
* values(object); // => [1, 2]
|
|
9
|
+
*/
|
|
10
|
+
declare function values<T>(object: Record<PropertyKey, T> | null | undefined): T[];
|
|
11
|
+
/**
|
|
12
|
+
* Creates an array of the values of an array or array-like object.
|
|
13
|
+
*
|
|
14
|
+
* @param {ArrayLike<T>} arr The array or array-like object to query.
|
|
15
|
+
* @returns {T[]} Returns an array of values.
|
|
16
|
+
* @example
|
|
17
|
+
* const array = ['a', 'b'];
|
|
18
|
+
* values(arrayLike); // => ['a', 'b']
|
|
19
|
+
*/
|
|
20
|
+
declare function values<T>(arr: ArrayLike<T>): T[];
|
|
21
|
+
/**
|
|
22
|
+
* Creates an array of the own enumerable property values of `object`.
|
|
23
|
+
*
|
|
24
|
+
* @param {T | null | undefined} object The object to query.
|
|
25
|
+
* @returns {Array<T[keyof T]>} Returns an array of property values.
|
|
26
|
+
* @example
|
|
27
|
+
* const obj = { x: 1, y: 2, z: 3 };
|
|
28
|
+
* values(obj); // => [1, 2, 3]
|
|
29
|
+
*/
|
|
30
|
+
declare function values<T extends object>(object: T | null | undefined): Array<T[keyof T]>;
|
|
31
|
+
|
|
32
|
+
export { values };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an array of the own enumerable property values of `object`.
|
|
3
|
+
*
|
|
4
|
+
* @param {Record<PropertyKey, T> | null | undefined} object The object to query.
|
|
5
|
+
* @returns {T[]} Returns an array of property values.
|
|
6
|
+
* @example
|
|
7
|
+
* const object = { a: 1, b: 2 };
|
|
8
|
+
* values(object); // => [1, 2]
|
|
9
|
+
*/
|
|
10
|
+
declare function values<T>(object: Record<PropertyKey, T> | null | undefined): T[];
|
|
11
|
+
/**
|
|
12
|
+
* Creates an array of the values of an array or array-like object.
|
|
13
|
+
*
|
|
14
|
+
* @param {ArrayLike<T>} arr The array or array-like object to query.
|
|
15
|
+
* @returns {T[]} Returns an array of values.
|
|
16
|
+
* @example
|
|
17
|
+
* const array = ['a', 'b'];
|
|
18
|
+
* values(arrayLike); // => ['a', 'b']
|
|
19
|
+
*/
|
|
20
|
+
declare function values<T>(arr: ArrayLike<T>): T[];
|
|
21
|
+
/**
|
|
22
|
+
* Creates an array of the own enumerable property values of `object`.
|
|
23
|
+
*
|
|
24
|
+
* @param {T | null | undefined} object The object to query.
|
|
25
|
+
* @returns {Array<T[keyof T]>} Returns an array of property values.
|
|
26
|
+
* @example
|
|
27
|
+
* const obj = { x: 1, y: 2, z: 3 };
|
|
28
|
+
* values(obj); // => [1, 2, 3]
|
|
29
|
+
*/
|
|
30
|
+
declare function values<T extends object>(object: T | null | undefined): Array<T[keyof T]>;
|
|
31
|
+
|
|
32
|
+
export { values };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the values from an object, including those inherited from its prototype.
|
|
3
|
+
*
|
|
4
|
+
* - If the value is not an object, it is converted to an object.
|
|
5
|
+
* - Array-like objects are treated like arrays.
|
|
6
|
+
* - Sparse arrays with some missing indices are treated like dense arrays.
|
|
7
|
+
* - If the value is `null` or `undefined`, an empty array is returned.
|
|
8
|
+
* - When handling prototype objects, the `constructor` property is excluded from the results.
|
|
9
|
+
*
|
|
10
|
+
* @param {Record<PropertyKey, T> | null | undefined} object The object to query.
|
|
11
|
+
* @returns {T[]} Returns an array of property values.
|
|
12
|
+
* @example
|
|
13
|
+
* const object = { a: 1, b: 2 };
|
|
14
|
+
* valuesIn(object); // => [1, 2]
|
|
15
|
+
*
|
|
16
|
+
* const arr = [1, 2, 3];
|
|
17
|
+
* valuesIn(arr); // => [1, 2, 3]
|
|
18
|
+
*
|
|
19
|
+
* function Foo() {
|
|
20
|
+
* this.a = 1;
|
|
21
|
+
* }
|
|
22
|
+
* Foo.prototype.b = 2;
|
|
23
|
+
* const foo = new Foo();
|
|
24
|
+
* valuesIn(foo); // => [1] (includes inherited properties)
|
|
25
|
+
*
|
|
26
|
+
* const objWithLength = { 0: 'a', 1: 'b', length: 2 };
|
|
27
|
+
* valuesIn(objWithLength); // => ['a', 'b', 2]
|
|
28
|
+
*/
|
|
29
|
+
declare function valuesIn<T>(object: Record<PropertyKey, T> | null | undefined): T[];
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves the values from an object, including those inherited from its prototype.
|
|
32
|
+
*
|
|
33
|
+
* - If the value is not an object, it is converted to an object.
|
|
34
|
+
* - Array-like objects are treated like arrays.
|
|
35
|
+
* - Sparse arrays with some missing indices are treated like dense arrays.
|
|
36
|
+
* - If the value is `null` or `undefined`, an empty array is returned.
|
|
37
|
+
* - When handling prototype objects, the `constructor` property is excluded from the results.
|
|
38
|
+
*
|
|
39
|
+
* @param {ArrayLike<T>} arr The array or array-like object to query.
|
|
40
|
+
* @returns {T[]} Returns an array of values.
|
|
41
|
+
* @example
|
|
42
|
+
* const arrayLike = { 0: 'a', 1: 'b', length: 2 };
|
|
43
|
+
* valuesIn(arrayLike); // => ['a', 'b']
|
|
44
|
+
*/
|
|
45
|
+
declare function valuesIn<T>(arr: ArrayLike<T>): T[];
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the values from an object, including those inherited from its prototype.
|
|
48
|
+
*
|
|
49
|
+
* - If the value is not an object, it is converted to an object.
|
|
50
|
+
* - Array-like objects are treated like arrays.
|
|
51
|
+
* - Sparse arrays with some missing indices are treated like dense arrays.
|
|
52
|
+
* - If the value is `null` or `undefined`, an empty array is returned.
|
|
53
|
+
* - When handling prototype objects, the `constructor` property is excluded from the results.
|
|
54
|
+
*
|
|
55
|
+
* @param {T | null | undefined} object The object to query.
|
|
56
|
+
* @returns {Array<T[keyof T]>} Returns an array of property values.
|
|
57
|
+
* @example
|
|
58
|
+
* const obj = { x: 1, y: 2, z: 3 };
|
|
59
|
+
* valuesIn(obj); // => [1, 2, 3]
|
|
60
|
+
*/
|
|
61
|
+
declare function valuesIn<T extends object>(object: T | null | undefined): Array<T[keyof T]>;
|
|
62
|
+
|
|
63
|
+
export { valuesIn };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the values from an object, including those inherited from its prototype.
|
|
3
|
+
*
|
|
4
|
+
* - If the value is not an object, it is converted to an object.
|
|
5
|
+
* - Array-like objects are treated like arrays.
|
|
6
|
+
* - Sparse arrays with some missing indices are treated like dense arrays.
|
|
7
|
+
* - If the value is `null` or `undefined`, an empty array is returned.
|
|
8
|
+
* - When handling prototype objects, the `constructor` property is excluded from the results.
|
|
9
|
+
*
|
|
10
|
+
* @param {Record<PropertyKey, T> | null | undefined} object The object to query.
|
|
11
|
+
* @returns {T[]} Returns an array of property values.
|
|
12
|
+
* @example
|
|
13
|
+
* const object = { a: 1, b: 2 };
|
|
14
|
+
* valuesIn(object); // => [1, 2]
|
|
15
|
+
*
|
|
16
|
+
* const arr = [1, 2, 3];
|
|
17
|
+
* valuesIn(arr); // => [1, 2, 3]
|
|
18
|
+
*
|
|
19
|
+
* function Foo() {
|
|
20
|
+
* this.a = 1;
|
|
21
|
+
* }
|
|
22
|
+
* Foo.prototype.b = 2;
|
|
23
|
+
* const foo = new Foo();
|
|
24
|
+
* valuesIn(foo); // => [1] (includes inherited properties)
|
|
25
|
+
*
|
|
26
|
+
* const objWithLength = { 0: 'a', 1: 'b', length: 2 };
|
|
27
|
+
* valuesIn(objWithLength); // => ['a', 'b', 2]
|
|
28
|
+
*/
|
|
29
|
+
declare function valuesIn<T>(object: Record<PropertyKey, T> | null | undefined): T[];
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves the values from an object, including those inherited from its prototype.
|
|
32
|
+
*
|
|
33
|
+
* - If the value is not an object, it is converted to an object.
|
|
34
|
+
* - Array-like objects are treated like arrays.
|
|
35
|
+
* - Sparse arrays with some missing indices are treated like dense arrays.
|
|
36
|
+
* - If the value is `null` or `undefined`, an empty array is returned.
|
|
37
|
+
* - When handling prototype objects, the `constructor` property is excluded from the results.
|
|
38
|
+
*
|
|
39
|
+
* @param {ArrayLike<T>} arr The array or array-like object to query.
|
|
40
|
+
* @returns {T[]} Returns an array of values.
|
|
41
|
+
* @example
|
|
42
|
+
* const arrayLike = { 0: 'a', 1: 'b', length: 2 };
|
|
43
|
+
* valuesIn(arrayLike); // => ['a', 'b']
|
|
44
|
+
*/
|
|
45
|
+
declare function valuesIn<T>(arr: ArrayLike<T>): T[];
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the values from an object, including those inherited from its prototype.
|
|
48
|
+
*
|
|
49
|
+
* - If the value is not an object, it is converted to an object.
|
|
50
|
+
* - Array-like objects are treated like arrays.
|
|
51
|
+
* - Sparse arrays with some missing indices are treated like dense arrays.
|
|
52
|
+
* - If the value is `null` or `undefined`, an empty array is returned.
|
|
53
|
+
* - When handling prototype objects, the `constructor` property is excluded from the results.
|
|
54
|
+
*
|
|
55
|
+
* @param {T | null | undefined} object The object to query.
|
|
56
|
+
* @returns {Array<T[keyof T]>} Returns an array of property values.
|
|
57
|
+
* @example
|
|
58
|
+
* const obj = { x: 1, y: 2, z: 3 };
|
|
59
|
+
* valuesIn(obj); // => [1, 2, 3]
|
|
60
|
+
*/
|
|
61
|
+
declare function valuesIn<T extends object>(object: T | null | undefined): Array<T[keyof T]>;
|
|
62
|
+
|
|
63
|
+
export { valuesIn };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { keysIn } from './keysIn.mjs';
|
|
2
|
+
|
|
3
|
+
function valuesIn(object) {
|
|
4
|
+
const keys = keysIn(object);
|
|
5
|
+
const result = new Array(keys.length);
|
|
6
|
+
for (let i = 0; i < keys.length; i++) {
|
|
7
|
+
const key = keys[i];
|
|
8
|
+
result[i] = object[key];
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { valuesIn };
|
package/dist/index.d.mts
CHANGED
|
@@ -119,6 +119,7 @@ export { isEqualWith } from './predicate/isEqualWith.mjs';
|
|
|
119
119
|
export { isError } from './predicate/isError.mjs';
|
|
120
120
|
export { isFile } from './predicate/isFile.mjs';
|
|
121
121
|
export { isFunction } from './predicate/isFunction.mjs';
|
|
122
|
+
export { isJSON } from './predicate/isJSON.mjs';
|
|
122
123
|
export { isJSONArray, isJSONObject, isJSONValue } from './predicate/isJSONValue.mjs';
|
|
123
124
|
export { isLength } from './predicate/isLength.mjs';
|
|
124
125
|
export { isMap } from './predicate/isMap.mjs';
|
|
@@ -152,6 +153,7 @@ export { lowerCase } from './string/lowerCase.mjs';
|
|
|
152
153
|
export { lowerFirst } from './string/lowerFirst.mjs';
|
|
153
154
|
export { pad } from './string/pad.mjs';
|
|
154
155
|
export { pascalCase } from './string/pascalCase.mjs';
|
|
156
|
+
export { reverseString } from './string/reverseString.mjs';
|
|
155
157
|
export { snakeCase } from './string/snakeCase.mjs';
|
|
156
158
|
export { startCase } from './string/startCase.mjs';
|
|
157
159
|
export { trim } from './string/trim.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -119,6 +119,7 @@ export { isEqualWith } from './predicate/isEqualWith.js';
|
|
|
119
119
|
export { isError } from './predicate/isError.js';
|
|
120
120
|
export { isFile } from './predicate/isFile.js';
|
|
121
121
|
export { isFunction } from './predicate/isFunction.js';
|
|
122
|
+
export { isJSON } from './predicate/isJSON.js';
|
|
122
123
|
export { isJSONArray, isJSONObject, isJSONValue } from './predicate/isJSONValue.js';
|
|
123
124
|
export { isLength } from './predicate/isLength.js';
|
|
124
125
|
export { isMap } from './predicate/isMap.js';
|
|
@@ -152,6 +153,7 @@ export { lowerCase } from './string/lowerCase.js';
|
|
|
152
153
|
export { lowerFirst } from './string/lowerFirst.js';
|
|
153
154
|
export { pad } from './string/pad.js';
|
|
154
155
|
export { pascalCase } from './string/pascalCase.js';
|
|
156
|
+
export { reverseString } from './string/reverseString.js';
|
|
155
157
|
export { snakeCase } from './string/snakeCase.js';
|
|
156
158
|
export { startCase } from './string/startCase.js';
|
|
157
159
|
export { trim } from './string/trim.js';
|
package/dist/index.js
CHANGED
|
@@ -12,14 +12,14 @@ const noop = require('./_chunk/noop-2IwLUk.js');
|
|
|
12
12
|
const range = require('./_chunk/range-HnEIT7.js');
|
|
13
13
|
const randomInt = require('./_chunk/randomInt-CF7bZK.js');
|
|
14
14
|
const math_index = require('./math/index.js');
|
|
15
|
-
const toMerged = require('./_chunk/toMerged-
|
|
15
|
+
const toMerged = require('./_chunk/toMerged-CwnQF6.js');
|
|
16
16
|
const object_index = require('./object/index.js');
|
|
17
|
-
const isWeakSet = require('./_chunk/isWeakSet-
|
|
17
|
+
const isWeakSet = require('./_chunk/isWeakSet-TIM260.js');
|
|
18
18
|
const predicate_index = require('./predicate/index.js');
|
|
19
19
|
const isPlainObject = require('./_chunk/isPlainObject-Xaozpc.js');
|
|
20
20
|
const delay = require('./_chunk/delay-_VMfFa.js');
|
|
21
21
|
const promise_index = require('./promise/index.js');
|
|
22
|
-
const upperFirst = require('./_chunk/upperFirst-
|
|
22
|
+
const upperFirst = require('./_chunk/upperFirst-nA5L7X.js');
|
|
23
23
|
const string_index = require('./string/index.js');
|
|
24
24
|
const util_index = require('./util/index.js');
|
|
25
25
|
|
|
@@ -131,11 +131,11 @@ exports.mapKeys = toMerged.mapKeys;
|
|
|
131
131
|
exports.mapValues = toMerged.mapValues;
|
|
132
132
|
exports.merge = toMerged.merge;
|
|
133
133
|
exports.omitBy = toMerged.omitBy;
|
|
134
|
-
exports.pickBy = toMerged.pickBy;
|
|
135
134
|
exports.toMerged = toMerged.toMerged;
|
|
136
135
|
exports.mergeWith = object_index.mergeWith;
|
|
137
136
|
exports.omit = object_index.omit;
|
|
138
137
|
exports.pick = object_index.pick;
|
|
138
|
+
exports.pickBy = object_index.pickBy;
|
|
139
139
|
exports.isArrayBuffer = isWeakSet.isArrayBuffer;
|
|
140
140
|
exports.isBlob = isWeakSet.isBlob;
|
|
141
141
|
exports.isBuffer = isWeakSet.isBuffer;
|
|
@@ -144,6 +144,7 @@ exports.isEqual = isWeakSet.isEqual;
|
|
|
144
144
|
exports.isEqualWith = isWeakSet.isEqualWith;
|
|
145
145
|
exports.isFile = isWeakSet.isFile;
|
|
146
146
|
exports.isFunction = isWeakSet.isFunction;
|
|
147
|
+
exports.isJSON = isWeakSet.isJSON;
|
|
147
148
|
exports.isJSONArray = isWeakSet.isJSONArray;
|
|
148
149
|
exports.isJSONObject = isWeakSet.isJSONObject;
|
|
149
150
|
exports.isJSONValue = isWeakSet.isJSONValue;
|
|
@@ -181,6 +182,7 @@ exports.lowerCase = upperFirst.lowerCase;
|
|
|
181
182
|
exports.lowerFirst = upperFirst.lowerFirst;
|
|
182
183
|
exports.pad = upperFirst.pad;
|
|
183
184
|
exports.pascalCase = upperFirst.pascalCase;
|
|
185
|
+
exports.reverseString = upperFirst.reverseString;
|
|
184
186
|
exports.snakeCase = upperFirst.snakeCase;
|
|
185
187
|
exports.trim = upperFirst.trim;
|
|
186
188
|
exports.trimEnd = upperFirst.trimEnd;
|