es-toolkit 1.35.0-dev.1198 → 1.35.0-dev.1200
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 +3 -0
- package/dist/compat/index.d.ts +3 -0
- package/dist/compat/index.js +49 -0
- package/dist/compat/index.mjs +3 -0
- package/dist/compat/object/forIn.d.mts +58 -0
- package/dist/compat/object/forIn.d.ts +58 -0
- package/dist/compat/object/forIn.mjs +16 -0
- package/dist/compat/object/forInRight.d.mts +58 -0
- package/dist/compat/object/forInRight.d.ts +58 -0
- package/dist/compat/object/forInRight.mjs +21 -0
- package/dist/compat/object/forOwnRight.d.mts +54 -0
- package/dist/compat/object/forOwnRight.d.ts +54 -0
- package/dist/compat/object/forOwnRight.mjs +19 -0
- package/package.json +1 -1
package/dist/compat/index.d.mts
CHANGED
|
@@ -184,7 +184,10 @@ export { cloneDeepWith } from './object/cloneDeepWith.mjs';
|
|
|
184
184
|
export { create } from './object/create.mjs';
|
|
185
185
|
export { defaults } from './object/defaults.mjs';
|
|
186
186
|
export { findKey } from './object/findKey.mjs';
|
|
187
|
+
export { forIn } from './object/forIn.mjs';
|
|
188
|
+
export { forInRight } from './object/forInRight.mjs';
|
|
187
189
|
export { forOwn } from './object/forOwn.mjs';
|
|
190
|
+
export { forOwnRight } from './object/forOwnRight.mjs';
|
|
188
191
|
export { fromPairs } from './object/fromPairs.mjs';
|
|
189
192
|
export { functions } from './object/functions.mjs';
|
|
190
193
|
export { functionsIn } from './object/functionsIn.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -184,7 +184,10 @@ export { cloneDeepWith } from './object/cloneDeepWith.js';
|
|
|
184
184
|
export { create } from './object/create.js';
|
|
185
185
|
export { defaults } from './object/defaults.js';
|
|
186
186
|
export { findKey } from './object/findKey.js';
|
|
187
|
+
export { forIn } from './object/forIn.js';
|
|
188
|
+
export { forInRight } from './object/forInRight.js';
|
|
187
189
|
export { forOwn } from './object/forOwn.js';
|
|
190
|
+
export { forOwnRight } from './object/forOwnRight.js';
|
|
188
191
|
export { fromPairs } from './object/fromPairs.js';
|
|
189
192
|
export { functions } from './object/functions.js';
|
|
190
193
|
export { functionsIn } from './object/functionsIn.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -2679,6 +2679,37 @@ function findKeyImpl(obj, predicate) {
|
|
|
2679
2679
|
}
|
|
2680
2680
|
}
|
|
2681
2681
|
|
|
2682
|
+
function forIn(object, iteratee = unary.identity) {
|
|
2683
|
+
if (object == null) {
|
|
2684
|
+
return object;
|
|
2685
|
+
}
|
|
2686
|
+
for (const key in object) {
|
|
2687
|
+
const result = iteratee(object[key], key, object);
|
|
2688
|
+
if (result === false) {
|
|
2689
|
+
break;
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
return object;
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
function forInRight(object, iteratee = unary.identity) {
|
|
2696
|
+
if (object == null) {
|
|
2697
|
+
return object;
|
|
2698
|
+
}
|
|
2699
|
+
const keys = [];
|
|
2700
|
+
for (const key in object) {
|
|
2701
|
+
keys.push(key);
|
|
2702
|
+
}
|
|
2703
|
+
for (let i = keys.length - 1; i >= 0; i--) {
|
|
2704
|
+
const key = keys[i];
|
|
2705
|
+
const result = iteratee(object[key], key, object);
|
|
2706
|
+
if (result === false) {
|
|
2707
|
+
break;
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
return object;
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2682
2713
|
function forOwn(object, iteratee = unary.identity) {
|
|
2683
2714
|
if (object == null) {
|
|
2684
2715
|
return object;
|
|
@@ -2694,6 +2725,21 @@ function forOwn(object, iteratee = unary.identity) {
|
|
|
2694
2725
|
return object;
|
|
2695
2726
|
}
|
|
2696
2727
|
|
|
2728
|
+
function forOwnRight(object, iteratee = unary.identity) {
|
|
2729
|
+
if (object == null) {
|
|
2730
|
+
return object;
|
|
2731
|
+
}
|
|
2732
|
+
const iterable = Object(object);
|
|
2733
|
+
const keys$1 = keys(object);
|
|
2734
|
+
for (let i = keys$1.length - 1; i >= 0; --i) {
|
|
2735
|
+
const key = keys$1[i];
|
|
2736
|
+
if (iteratee(iterable[key], key, iterable) === false) {
|
|
2737
|
+
break;
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
return object;
|
|
2741
|
+
}
|
|
2742
|
+
|
|
2697
2743
|
function fromPairs(pairs) {
|
|
2698
2744
|
if (!isArrayLike(pairs) && !(pairs instanceof Map)) {
|
|
2699
2745
|
return {};
|
|
@@ -3842,7 +3888,10 @@ exports.floor = floor;
|
|
|
3842
3888
|
exports.flow = flow;
|
|
3843
3889
|
exports.flowRight = flowRight;
|
|
3844
3890
|
exports.forEach = forEach;
|
|
3891
|
+
exports.forIn = forIn;
|
|
3892
|
+
exports.forInRight = forInRight;
|
|
3845
3893
|
exports.forOwn = forOwn;
|
|
3894
|
+
exports.forOwnRight = forOwnRight;
|
|
3846
3895
|
exports.fromPairs = fromPairs;
|
|
3847
3896
|
exports.functions = functions;
|
|
3848
3897
|
exports.functionsIn = functionsIn;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -186,7 +186,10 @@ export { cloneDeepWith } from './object/cloneDeepWith.mjs';
|
|
|
186
186
|
export { create } from './object/create.mjs';
|
|
187
187
|
export { defaults } from './object/defaults.mjs';
|
|
188
188
|
export { findKey } from './object/findKey.mjs';
|
|
189
|
+
export { forIn } from './object/forIn.mjs';
|
|
190
|
+
export { forInRight } from './object/forInRight.mjs';
|
|
189
191
|
export { forOwn } from './object/forOwn.mjs';
|
|
192
|
+
export { forOwnRight } from './object/forOwnRight.mjs';
|
|
190
193
|
export { fromPairs } from './object/fromPairs.mjs';
|
|
191
194
|
export { functions } from './object/functions.mjs';
|
|
192
195
|
export { functionsIn } from './object/functionsIn.mjs';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates over an object and invokes the `iteratee` function for each property.
|
|
3
|
+
*
|
|
4
|
+
* Iterates over string keyed properties including inherited properties.
|
|
5
|
+
*
|
|
6
|
+
* The iteration is terminated early if the `iteratee` function returns `false`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of the object
|
|
9
|
+
* @param {T} object - The object to iterate over
|
|
10
|
+
* @param {(value: T[keyof T], key: string, obj: T) => any} iteratee - The function invoked per iteration
|
|
11
|
+
* @returns {T} Returns the object
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Iterate over all properties including inherited ones
|
|
15
|
+
* const obj = { a: 1, b: 2 };
|
|
16
|
+
* forIn(obj, (value, key) => {
|
|
17
|
+
* console.log(key, value);
|
|
18
|
+
* });
|
|
19
|
+
* // Output: 'a' 1, 'b' 2
|
|
20
|
+
*
|
|
21
|
+
* // Early termination
|
|
22
|
+
* forIn(obj, (value, key) => {
|
|
23
|
+
* console.log(key, value);
|
|
24
|
+
* return key !== 'a'; // stop after 'a'
|
|
25
|
+
* });
|
|
26
|
+
* // Output: 'a' 1
|
|
27
|
+
*/
|
|
28
|
+
declare function forIn<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
|
|
29
|
+
/**
|
|
30
|
+
* Iterates over an object and invokes the `iteratee` function for each property.
|
|
31
|
+
*
|
|
32
|
+
* Iterates over string keyed properties including inherited properties.
|
|
33
|
+
*
|
|
34
|
+
* The iteration is terminated early if the `iteratee` function returns `false`.
|
|
35
|
+
*
|
|
36
|
+
* @template T - The type of the object
|
|
37
|
+
* @param {T | null | undefined} object - The object to iterate over
|
|
38
|
+
* @param {(value: T[keyof T], key: string, obj: T) => any} iteratee - The function invoked per iteration
|
|
39
|
+
* @returns {T | null | undefined} Returns the object
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Iterate over all properties including inherited ones
|
|
43
|
+
* const obj = { a: 1, b: 2 };
|
|
44
|
+
* forIn(obj, (value, key) => {
|
|
45
|
+
* console.log(key, value);
|
|
46
|
+
* });
|
|
47
|
+
* // Output: 'a' 1, 'b' 2
|
|
48
|
+
*
|
|
49
|
+
* // Early termination
|
|
50
|
+
* forIn(obj, (value, key) => {
|
|
51
|
+
* console.log(key, value);
|
|
52
|
+
* return key !== 'a'; // stop after 'a'
|
|
53
|
+
* });
|
|
54
|
+
* // Output: 'a' 1
|
|
55
|
+
*/
|
|
56
|
+
declare function forIn<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
|
|
57
|
+
|
|
58
|
+
export { forIn };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates over an object and invokes the `iteratee` function for each property.
|
|
3
|
+
*
|
|
4
|
+
* Iterates over string keyed properties including inherited properties.
|
|
5
|
+
*
|
|
6
|
+
* The iteration is terminated early if the `iteratee` function returns `false`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of the object
|
|
9
|
+
* @param {T} object - The object to iterate over
|
|
10
|
+
* @param {(value: T[keyof T], key: string, obj: T) => any} iteratee - The function invoked per iteration
|
|
11
|
+
* @returns {T} Returns the object
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Iterate over all properties including inherited ones
|
|
15
|
+
* const obj = { a: 1, b: 2 };
|
|
16
|
+
* forIn(obj, (value, key) => {
|
|
17
|
+
* console.log(key, value);
|
|
18
|
+
* });
|
|
19
|
+
* // Output: 'a' 1, 'b' 2
|
|
20
|
+
*
|
|
21
|
+
* // Early termination
|
|
22
|
+
* forIn(obj, (value, key) => {
|
|
23
|
+
* console.log(key, value);
|
|
24
|
+
* return key !== 'a'; // stop after 'a'
|
|
25
|
+
* });
|
|
26
|
+
* // Output: 'a' 1
|
|
27
|
+
*/
|
|
28
|
+
declare function forIn<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
|
|
29
|
+
/**
|
|
30
|
+
* Iterates over an object and invokes the `iteratee` function for each property.
|
|
31
|
+
*
|
|
32
|
+
* Iterates over string keyed properties including inherited properties.
|
|
33
|
+
*
|
|
34
|
+
* The iteration is terminated early if the `iteratee` function returns `false`.
|
|
35
|
+
*
|
|
36
|
+
* @template T - The type of the object
|
|
37
|
+
* @param {T | null | undefined} object - The object to iterate over
|
|
38
|
+
* @param {(value: T[keyof T], key: string, obj: T) => any} iteratee - The function invoked per iteration
|
|
39
|
+
* @returns {T | null | undefined} Returns the object
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Iterate over all properties including inherited ones
|
|
43
|
+
* const obj = { a: 1, b: 2 };
|
|
44
|
+
* forIn(obj, (value, key) => {
|
|
45
|
+
* console.log(key, value);
|
|
46
|
+
* });
|
|
47
|
+
* // Output: 'a' 1, 'b' 2
|
|
48
|
+
*
|
|
49
|
+
* // Early termination
|
|
50
|
+
* forIn(obj, (value, key) => {
|
|
51
|
+
* console.log(key, value);
|
|
52
|
+
* return key !== 'a'; // stop after 'a'
|
|
53
|
+
* });
|
|
54
|
+
* // Output: 'a' 1
|
|
55
|
+
*/
|
|
56
|
+
declare function forIn<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
|
|
57
|
+
|
|
58
|
+
export { forIn };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { identity } from '../../function/identity.mjs';
|
|
2
|
+
|
|
3
|
+
function forIn(object, iteratee = identity) {
|
|
4
|
+
if (object == null) {
|
|
5
|
+
return object;
|
|
6
|
+
}
|
|
7
|
+
for (const key in object) {
|
|
8
|
+
const result = iteratee(object[key], key, object);
|
|
9
|
+
if (result === false) {
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return object;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { forIn };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates over an object in reverse order and invokes the `iteratee` function for each property.
|
|
3
|
+
*
|
|
4
|
+
* Iterates over string keyed properties including inherited properties in reverse order.
|
|
5
|
+
*
|
|
6
|
+
* The iteration is terminated early if the `iteratee` function returns `false`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of the object
|
|
9
|
+
* @param {T} object - The object to iterate over
|
|
10
|
+
* @param {(value: T[keyof T], key: string, collection: T) => any} iteratee - The function invoked per iteration
|
|
11
|
+
* @returns {T} Returns the object
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Iterate over all properties including inherited ones
|
|
15
|
+
* const obj = { a: 1, b: 2 };
|
|
16
|
+
* forInRight(obj, (value, key) => {
|
|
17
|
+
* console.log(key, value);
|
|
18
|
+
* });
|
|
19
|
+
* // Output: 'b' 2, 'a' 1
|
|
20
|
+
*
|
|
21
|
+
* // Early termination
|
|
22
|
+
* forInRight(obj, (value, key) => {
|
|
23
|
+
* console.log(key, value);
|
|
24
|
+
* return key !== 'a'; // stop after 'a'
|
|
25
|
+
* });
|
|
26
|
+
* // Output: 'b' 2
|
|
27
|
+
*/
|
|
28
|
+
declare function forInRight<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
|
|
29
|
+
/**
|
|
30
|
+
* Iterates over an object in reverse order and invokes the `iteratee` function for each property.
|
|
31
|
+
*
|
|
32
|
+
* Iterates over string keyed properties including inherited properties in reverse order.
|
|
33
|
+
*
|
|
34
|
+
* The iteration is terminated early if the `iteratee` function returns `false`.
|
|
35
|
+
*
|
|
36
|
+
* @template T - The type of the object
|
|
37
|
+
* @param {T | null | undefined} object - The object to iterate over
|
|
38
|
+
* @param {(value: T[keyof T], key: string, obj: T) => any} iteratee - The function invoked per iteration
|
|
39
|
+
* @returns {T | null | undefined} Returns the object
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Iterate over all properties including inherited ones
|
|
43
|
+
* const obj = { a: 1, b: 2 };
|
|
44
|
+
* forInRight(obj, (value, key) => {
|
|
45
|
+
* console.log(key, value);
|
|
46
|
+
* });
|
|
47
|
+
* // Output: 'b' 2, 'a' 1
|
|
48
|
+
*
|
|
49
|
+
* // Early termination
|
|
50
|
+
* forInRight(obj, (value, key) => {
|
|
51
|
+
* console.log(key, value);
|
|
52
|
+
* return key !== 'a'; // stop after 'a'
|
|
53
|
+
* });
|
|
54
|
+
* // Output: 'b' 2
|
|
55
|
+
*/
|
|
56
|
+
declare function forInRight<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
|
|
57
|
+
|
|
58
|
+
export { forInRight };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates over an object in reverse order and invokes the `iteratee` function for each property.
|
|
3
|
+
*
|
|
4
|
+
* Iterates over string keyed properties including inherited properties in reverse order.
|
|
5
|
+
*
|
|
6
|
+
* The iteration is terminated early if the `iteratee` function returns `false`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of the object
|
|
9
|
+
* @param {T} object - The object to iterate over
|
|
10
|
+
* @param {(value: T[keyof T], key: string, collection: T) => any} iteratee - The function invoked per iteration
|
|
11
|
+
* @returns {T} Returns the object
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Iterate over all properties including inherited ones
|
|
15
|
+
* const obj = { a: 1, b: 2 };
|
|
16
|
+
* forInRight(obj, (value, key) => {
|
|
17
|
+
* console.log(key, value);
|
|
18
|
+
* });
|
|
19
|
+
* // Output: 'b' 2, 'a' 1
|
|
20
|
+
*
|
|
21
|
+
* // Early termination
|
|
22
|
+
* forInRight(obj, (value, key) => {
|
|
23
|
+
* console.log(key, value);
|
|
24
|
+
* return key !== 'a'; // stop after 'a'
|
|
25
|
+
* });
|
|
26
|
+
* // Output: 'b' 2
|
|
27
|
+
*/
|
|
28
|
+
declare function forInRight<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
|
|
29
|
+
/**
|
|
30
|
+
* Iterates over an object in reverse order and invokes the `iteratee` function for each property.
|
|
31
|
+
*
|
|
32
|
+
* Iterates over string keyed properties including inherited properties in reverse order.
|
|
33
|
+
*
|
|
34
|
+
* The iteration is terminated early if the `iteratee` function returns `false`.
|
|
35
|
+
*
|
|
36
|
+
* @template T - The type of the object
|
|
37
|
+
* @param {T | null | undefined} object - The object to iterate over
|
|
38
|
+
* @param {(value: T[keyof T], key: string, obj: T) => any} iteratee - The function invoked per iteration
|
|
39
|
+
* @returns {T | null | undefined} Returns the object
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Iterate over all properties including inherited ones
|
|
43
|
+
* const obj = { a: 1, b: 2 };
|
|
44
|
+
* forInRight(obj, (value, key) => {
|
|
45
|
+
* console.log(key, value);
|
|
46
|
+
* });
|
|
47
|
+
* // Output: 'b' 2, 'a' 1
|
|
48
|
+
*
|
|
49
|
+
* // Early termination
|
|
50
|
+
* forInRight(obj, (value, key) => {
|
|
51
|
+
* console.log(key, value);
|
|
52
|
+
* return key !== 'a'; // stop after 'a'
|
|
53
|
+
* });
|
|
54
|
+
* // Output: 'b' 2
|
|
55
|
+
*/
|
|
56
|
+
declare function forInRight<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
|
|
57
|
+
|
|
58
|
+
export { forInRight };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { identity } from '../../function/identity.mjs';
|
|
2
|
+
|
|
3
|
+
function forInRight(object, iteratee = identity) {
|
|
4
|
+
if (object == null) {
|
|
5
|
+
return object;
|
|
6
|
+
}
|
|
7
|
+
const keys = [];
|
|
8
|
+
for (const key in object) {
|
|
9
|
+
keys.push(key);
|
|
10
|
+
}
|
|
11
|
+
for (let i = keys.length - 1; i >= 0; i--) {
|
|
12
|
+
const key = keys[i];
|
|
13
|
+
const result = iteratee(object[key], key, object);
|
|
14
|
+
if (result === false) {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return object;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { forInRight };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates over an object's properties in reverse order and calls the `iteratee` function for each property.
|
|
3
|
+
*
|
|
4
|
+
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
|
|
5
|
+
*
|
|
6
|
+
* The `iteratee` function can terminate the iteration early by returning `false`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of the object.
|
|
9
|
+
* @param {T} object The object to iterate over.
|
|
10
|
+
* @param {(value: T[keyof T], key: string, collection: T) => any} [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
|
|
11
|
+
* @return {T} Returns object.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* function Foo() {
|
|
15
|
+
* this.a = 1;
|
|
16
|
+
* this.b = 2;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* Foo.prototype.c = 3;
|
|
20
|
+
*
|
|
21
|
+
* forOwnRight(new Foo(), function(value, key) {
|
|
22
|
+
* console.log(key);
|
|
23
|
+
* });
|
|
24
|
+
* // => Logs 'b' then 'a' (iteration order is not guaranteed).
|
|
25
|
+
*/
|
|
26
|
+
declare function forOwnRight<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
|
|
27
|
+
/**
|
|
28
|
+
* Iterates over an object's properties in reverse order and calls the `iteratee` function for each property.
|
|
29
|
+
*
|
|
30
|
+
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
|
|
31
|
+
*
|
|
32
|
+
* The `iteratee` function can terminate the iteration early by returning `false`.
|
|
33
|
+
*
|
|
34
|
+
* @template T - The type of the object.
|
|
35
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
36
|
+
* @param {(value: T[keyof T], key: string, collection: T) => any} [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
|
|
37
|
+
* @return {T | null | undefined} Returns object.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* function Foo() {
|
|
41
|
+
* this.a = 1;
|
|
42
|
+
* this.b = 2;
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* Foo.prototype.c = 3;
|
|
46
|
+
*
|
|
47
|
+
* forOwnRight(new Foo(), function(value, key) {
|
|
48
|
+
* console.log(key);
|
|
49
|
+
* });
|
|
50
|
+
* // => Logs 'b' then 'a' (iteration order is not guaranteed).
|
|
51
|
+
*/
|
|
52
|
+
declare function forOwnRight<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
|
|
53
|
+
|
|
54
|
+
export { forOwnRight };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates over an object's properties in reverse order and calls the `iteratee` function for each property.
|
|
3
|
+
*
|
|
4
|
+
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
|
|
5
|
+
*
|
|
6
|
+
* The `iteratee` function can terminate the iteration early by returning `false`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of the object.
|
|
9
|
+
* @param {T} object The object to iterate over.
|
|
10
|
+
* @param {(value: T[keyof T], key: string, collection: T) => any} [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
|
|
11
|
+
* @return {T} Returns object.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* function Foo() {
|
|
15
|
+
* this.a = 1;
|
|
16
|
+
* this.b = 2;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* Foo.prototype.c = 3;
|
|
20
|
+
*
|
|
21
|
+
* forOwnRight(new Foo(), function(value, key) {
|
|
22
|
+
* console.log(key);
|
|
23
|
+
* });
|
|
24
|
+
* // => Logs 'b' then 'a' (iteration order is not guaranteed).
|
|
25
|
+
*/
|
|
26
|
+
declare function forOwnRight<T>(object: T, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T;
|
|
27
|
+
/**
|
|
28
|
+
* Iterates over an object's properties in reverse order and calls the `iteratee` function for each property.
|
|
29
|
+
*
|
|
30
|
+
* It only iterates over the object's own properties, not including inherited properties or properties with `Symbol` keys.
|
|
31
|
+
*
|
|
32
|
+
* The `iteratee` function can terminate the iteration early by returning `false`.
|
|
33
|
+
*
|
|
34
|
+
* @template T - The type of the object.
|
|
35
|
+
* @param {T | null | undefined} object The object to iterate over.
|
|
36
|
+
* @param {(value: T[keyof T], key: string, collection: T) => any} [iteratee=identity] The function invoked per iteration. If not provided, the identity function will be used.
|
|
37
|
+
* @return {T | null | undefined} Returns object.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* function Foo() {
|
|
41
|
+
* this.a = 1;
|
|
42
|
+
* this.b = 2;
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* Foo.prototype.c = 3;
|
|
46
|
+
*
|
|
47
|
+
* forOwnRight(new Foo(), function(value, key) {
|
|
48
|
+
* console.log(key);
|
|
49
|
+
* });
|
|
50
|
+
* // => Logs 'b' then 'a' (iteration order is not guaranteed).
|
|
51
|
+
*/
|
|
52
|
+
declare function forOwnRight<T>(object: T | null | undefined, iteratee?: (value: T[keyof T], key: string, collection: T) => any): T | null | undefined;
|
|
53
|
+
|
|
54
|
+
export { forOwnRight };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { keys } from './keys.mjs';
|
|
2
|
+
import { identity } from '../../function/identity.mjs';
|
|
3
|
+
|
|
4
|
+
function forOwnRight(object, iteratee = identity) {
|
|
5
|
+
if (object == null) {
|
|
6
|
+
return object;
|
|
7
|
+
}
|
|
8
|
+
const iterable = Object(object);
|
|
9
|
+
const keys$1 = keys(object);
|
|
10
|
+
for (let i = keys$1.length - 1; i >= 0; --i) {
|
|
11
|
+
const key = keys$1[i];
|
|
12
|
+
if (iteratee(iterable[key], key, iterable) === false) {
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return object;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { forOwnRight };
|
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.35.0-dev.
|
|
4
|
+
"version": "1.35.0-dev.1200+f49fd5b4",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|