es-toolkit 1.29.0-dev.921 → 1.29.0-dev.922
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/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.d.mts +1 -1
- package/dist/compat/index.d.ts +1 -1
- package/dist/compat/index.js +24 -1
- package/dist/compat/index.mjs +1 -1
- package/dist/compat/object/findKey.d.mts +58 -0
- package/dist/compat/object/findKey.d.ts +58 -0
- package/dist/compat/object/findKey.mjs +30 -0
- package/package.json +1 -1
package/dist/compat/index.d.mts
CHANGED
|
@@ -48,7 +48,6 @@ export { randomInt } from '../math/randomInt.mjs';
|
|
|
48
48
|
export { range } from '../math/range.mjs';
|
|
49
49
|
export { rangeRight } from '../math/rangeRight.mjs';
|
|
50
50
|
export { clone } from '../object/clone.mjs';
|
|
51
|
-
export { findKey } from '../object/findKey.mjs';
|
|
52
51
|
export { flattenObject } from '../object/flattenObject.mjs';
|
|
53
52
|
export { invert } from '../object/invert.mjs';
|
|
54
53
|
export { omitBy } from '../object/omitBy.mjs';
|
|
@@ -154,6 +153,7 @@ export { assignIn, assignIn as extend } from './object/assignIn.mjs';
|
|
|
154
153
|
export { cloneDeep } from './object/cloneDeep.mjs';
|
|
155
154
|
export { cloneDeepWith } from './object/cloneDeepWith.mjs';
|
|
156
155
|
export { defaults } from './object/defaults.mjs';
|
|
156
|
+
export { findKey } from './object/findKey.mjs';
|
|
157
157
|
export { fromPairs } from './object/fromPairs.mjs';
|
|
158
158
|
export { get } from './object/get.mjs';
|
|
159
159
|
export { has } from './object/has.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -48,7 +48,6 @@ export { randomInt } from '../math/randomInt.js';
|
|
|
48
48
|
export { range } from '../math/range.js';
|
|
49
49
|
export { rangeRight } from '../math/rangeRight.js';
|
|
50
50
|
export { clone } from '../object/clone.js';
|
|
51
|
-
export { findKey } from '../object/findKey.js';
|
|
52
51
|
export { flattenObject } from '../object/flattenObject.js';
|
|
53
52
|
export { invert } from '../object/invert.js';
|
|
54
53
|
export { omitBy } from '../object/omitBy.js';
|
|
@@ -154,6 +153,7 @@ export { assignIn, assignIn as extend } from './object/assignIn.js';
|
|
|
154
153
|
export { cloneDeep } from './object/cloneDeep.js';
|
|
155
154
|
export { cloneDeepWith } from './object/cloneDeepWith.js';
|
|
156
155
|
export { defaults } from './object/defaults.js';
|
|
156
|
+
export { findKey } from './object/findKey.js';
|
|
157
157
|
export { fromPairs } from './object/fromPairs.js';
|
|
158
158
|
export { get } from './object/get.js';
|
|
159
159
|
export { has } from './object/has.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -1961,6 +1961,29 @@ function defaults(object, ...sources) {
|
|
|
1961
1961
|
return object;
|
|
1962
1962
|
}
|
|
1963
1963
|
|
|
1964
|
+
function findKey(obj, predicate) {
|
|
1965
|
+
if (!isObject(obj)) {
|
|
1966
|
+
return undefined;
|
|
1967
|
+
}
|
|
1968
|
+
return findKeyImpl(obj, predicate);
|
|
1969
|
+
}
|
|
1970
|
+
function findKeyImpl(obj, predicate) {
|
|
1971
|
+
if (typeof predicate === 'function') {
|
|
1972
|
+
return toMerged.findKey(obj, predicate);
|
|
1973
|
+
}
|
|
1974
|
+
if (typeof predicate === 'object') {
|
|
1975
|
+
if (Array.isArray(predicate)) {
|
|
1976
|
+
const key = predicate[0];
|
|
1977
|
+
const value = predicate[1];
|
|
1978
|
+
return toMerged.findKey(obj, matchesProperty(key, value));
|
|
1979
|
+
}
|
|
1980
|
+
return toMerged.findKey(obj, matches(predicate));
|
|
1981
|
+
}
|
|
1982
|
+
if (typeof predicate === 'string') {
|
|
1983
|
+
return toMerged.findKey(obj, property(predicate));
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1964
1987
|
function fromPairs(pairs) {
|
|
1965
1988
|
if (!isArrayLike(pairs) && !(pairs instanceof Map)) {
|
|
1966
1989
|
return {};
|
|
@@ -2765,7 +2788,6 @@ exports.range = rangeRight.range;
|
|
|
2765
2788
|
exports.rangeRight = rangeRight.rangeRight;
|
|
2766
2789
|
exports.randomInt = randomInt.randomInt;
|
|
2767
2790
|
exports.clone = toMerged.clone;
|
|
2768
|
-
exports.findKey = toMerged.findKey;
|
|
2769
2791
|
exports.flattenObject = toMerged.flattenObject;
|
|
2770
2792
|
exports.invert = toMerged.invert;
|
|
2771
2793
|
exports.isObjectLike = toMerged.isObjectLike;
|
|
@@ -2835,6 +2857,7 @@ exports.fill = fill;
|
|
|
2835
2857
|
exports.filter = filter;
|
|
2836
2858
|
exports.find = find;
|
|
2837
2859
|
exports.findIndex = findIndex;
|
|
2860
|
+
exports.findKey = findKey;
|
|
2838
2861
|
exports.findLastIndex = findLastIndex;
|
|
2839
2862
|
exports.first = head;
|
|
2840
2863
|
exports.flatten = flatten;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -48,7 +48,6 @@ export { range } from '../math/range.mjs';
|
|
|
48
48
|
export { rangeRight } from '../math/rangeRight.mjs';
|
|
49
49
|
export { clone } from '../object/clone.mjs';
|
|
50
50
|
export { isPrimitive } from '../predicate/isPrimitive.mjs';
|
|
51
|
-
export { findKey } from '../object/findKey.mjs';
|
|
52
51
|
export { flattenObject } from '../object/flattenObject.mjs';
|
|
53
52
|
export { invert } from '../object/invert.mjs';
|
|
54
53
|
export { isObjectLike } from './predicate/isObjectLike.mjs';
|
|
@@ -155,6 +154,7 @@ export { assignIn, assignIn as extend } from './object/assignIn.mjs';
|
|
|
155
154
|
export { cloneDeep } from './object/cloneDeep.mjs';
|
|
156
155
|
export { cloneDeepWith } from './object/cloneDeepWith.mjs';
|
|
157
156
|
export { defaults } from './object/defaults.mjs';
|
|
157
|
+
export { findKey } from './object/findKey.mjs';
|
|
158
158
|
export { fromPairs } from './object/fromPairs.mjs';
|
|
159
159
|
export { get } from './object/get.mjs';
|
|
160
160
|
export { has } from './object/has.mjs';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the key of the first element predicate returns truthy for.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the object.
|
|
5
|
+
* @param {T | null | undefined} obj - The object to inspect.
|
|
6
|
+
* @param {(value: T[keyof T], key: keyof T, obj: T) => boolean} conditionToFind - The function invoked per iteration.
|
|
7
|
+
* @returns {keyof T | undefined} Returns the key of the matched element, else `undefined`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const users = { 'barney': { 'age': 36 }, 'fred': { 'age': 40 } };
|
|
11
|
+
* const result = findKey(users, o => o.age < 40);
|
|
12
|
+
* // => 'barney'
|
|
13
|
+
*/
|
|
14
|
+
declare function findKey<T extends Record<any, any>>(obj: T | null | undefined, conditionToFind: (value: T[keyof T], key: keyof T, obj: T) => boolean): keyof T | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Finds the key of the first element that matches the given object.
|
|
17
|
+
*
|
|
18
|
+
* @template T - The type of the object.
|
|
19
|
+
* @param {T | null | undefined} obj - The object to inspect.
|
|
20
|
+
* @param {Partail<T[keyof T]>} objectToFind - The object to match.
|
|
21
|
+
* @returns {keyof T | undefined} Returns the key of the matched element, else `undefined`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const users = { 'barney': { 'age': 36 }, 'fred': { 'age': 40 } };
|
|
25
|
+
* const result = findKey(users, { 'age': 36 });
|
|
26
|
+
* // => 'barney'
|
|
27
|
+
*/
|
|
28
|
+
declare function findKey<T extends Record<any, any>>(obj: T | null | undefined, objectToFind: Partial<T[keyof T]>): keyof T | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Finds the key of the first element that matches the given property and value.
|
|
31
|
+
*
|
|
32
|
+
* @template T - The type of the object.
|
|
33
|
+
* @param {T | null | undefined} obj - The object to inspect.
|
|
34
|
+
* @param {[keyof T[keyof T], any]} propertyToFind - The property and value to match.
|
|
35
|
+
* @returns {keyof T | undefined} Returns the key of the matched element, else `undefined`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const users = { 'barney': { 'age': 36 }, 'fred': { 'age': 40 } };
|
|
39
|
+
* const result = findKey(users, ['age', 36]);
|
|
40
|
+
* // => 'barney'
|
|
41
|
+
*/
|
|
42
|
+
declare function findKey<T extends Record<any, any>>(obj: T | null | undefined, propertyToFind: [keyof T[keyof T], any]): keyof T | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Finds the key of the first element that has a truthy value for the given property.
|
|
45
|
+
*
|
|
46
|
+
* @template T - The type of the object.
|
|
47
|
+
* @param {T | null | undefined} obj - The object to inspect.
|
|
48
|
+
* @param {keyof T[keyof T]} propertyToFind - The property to check.
|
|
49
|
+
* @returns {keyof T | undefined} Returns the key of the matched element, else `undefined`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const users = { 'barney': { 'active': true }, 'fred': { 'active': false } };
|
|
53
|
+
* const result = findKey(users, 'active');
|
|
54
|
+
* // => 'barney'
|
|
55
|
+
*/
|
|
56
|
+
declare function findKey<T extends Record<any, any>>(obj: T | null | undefined, propertyToFind: keyof T[keyof T]): keyof T | undefined;
|
|
57
|
+
|
|
58
|
+
export { findKey };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the key of the first element predicate returns truthy for.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the object.
|
|
5
|
+
* @param {T | null | undefined} obj - The object to inspect.
|
|
6
|
+
* @param {(value: T[keyof T], key: keyof T, obj: T) => boolean} conditionToFind - The function invoked per iteration.
|
|
7
|
+
* @returns {keyof T | undefined} Returns the key of the matched element, else `undefined`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const users = { 'barney': { 'age': 36 }, 'fred': { 'age': 40 } };
|
|
11
|
+
* const result = findKey(users, o => o.age < 40);
|
|
12
|
+
* // => 'barney'
|
|
13
|
+
*/
|
|
14
|
+
declare function findKey<T extends Record<any, any>>(obj: T | null | undefined, conditionToFind: (value: T[keyof T], key: keyof T, obj: T) => boolean): keyof T | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Finds the key of the first element that matches the given object.
|
|
17
|
+
*
|
|
18
|
+
* @template T - The type of the object.
|
|
19
|
+
* @param {T | null | undefined} obj - The object to inspect.
|
|
20
|
+
* @param {Partail<T[keyof T]>} objectToFind - The object to match.
|
|
21
|
+
* @returns {keyof T | undefined} Returns the key of the matched element, else `undefined`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const users = { 'barney': { 'age': 36 }, 'fred': { 'age': 40 } };
|
|
25
|
+
* const result = findKey(users, { 'age': 36 });
|
|
26
|
+
* // => 'barney'
|
|
27
|
+
*/
|
|
28
|
+
declare function findKey<T extends Record<any, any>>(obj: T | null | undefined, objectToFind: Partial<T[keyof T]>): keyof T | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Finds the key of the first element that matches the given property and value.
|
|
31
|
+
*
|
|
32
|
+
* @template T - The type of the object.
|
|
33
|
+
* @param {T | null | undefined} obj - The object to inspect.
|
|
34
|
+
* @param {[keyof T[keyof T], any]} propertyToFind - The property and value to match.
|
|
35
|
+
* @returns {keyof T | undefined} Returns the key of the matched element, else `undefined`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const users = { 'barney': { 'age': 36 }, 'fred': { 'age': 40 } };
|
|
39
|
+
* const result = findKey(users, ['age', 36]);
|
|
40
|
+
* // => 'barney'
|
|
41
|
+
*/
|
|
42
|
+
declare function findKey<T extends Record<any, any>>(obj: T | null | undefined, propertyToFind: [keyof T[keyof T], any]): keyof T | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Finds the key of the first element that has a truthy value for the given property.
|
|
45
|
+
*
|
|
46
|
+
* @template T - The type of the object.
|
|
47
|
+
* @param {T | null | undefined} obj - The object to inspect.
|
|
48
|
+
* @param {keyof T[keyof T]} propertyToFind - The property to check.
|
|
49
|
+
* @returns {keyof T | undefined} Returns the key of the matched element, else `undefined`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const users = { 'barney': { 'active': true }, 'fred': { 'active': false } };
|
|
53
|
+
* const result = findKey(users, 'active');
|
|
54
|
+
* // => 'barney'
|
|
55
|
+
*/
|
|
56
|
+
declare function findKey<T extends Record<any, any>>(obj: T | null | undefined, propertyToFind: keyof T[keyof T]): keyof T | undefined;
|
|
57
|
+
|
|
58
|
+
export { findKey };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { property } from './property.mjs';
|
|
2
|
+
import { findKey as findKey$1 } from '../../object/findKey.mjs';
|
|
3
|
+
import { isObject } from '../predicate/isObject.mjs';
|
|
4
|
+
import { matches } from '../predicate/matches.mjs';
|
|
5
|
+
import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|
6
|
+
|
|
7
|
+
function findKey(obj, predicate) {
|
|
8
|
+
if (!isObject(obj)) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
return findKeyImpl(obj, predicate);
|
|
12
|
+
}
|
|
13
|
+
function findKeyImpl(obj, predicate) {
|
|
14
|
+
if (typeof predicate === 'function') {
|
|
15
|
+
return findKey$1(obj, predicate);
|
|
16
|
+
}
|
|
17
|
+
if (typeof predicate === 'object') {
|
|
18
|
+
if (Array.isArray(predicate)) {
|
|
19
|
+
const key = predicate[0];
|
|
20
|
+
const value = predicate[1];
|
|
21
|
+
return findKey$1(obj, matchesProperty(key, value));
|
|
22
|
+
}
|
|
23
|
+
return findKey$1(obj, matches(predicate));
|
|
24
|
+
}
|
|
25
|
+
if (typeof predicate === 'string') {
|
|
26
|
+
return findKey$1(obj, property(predicate));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { findKey };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
3
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
4
|
-
"version": "1.29.0-dev.
|
|
4
|
+
"version": "1.29.0-dev.922+917aff01",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|