es-toolkit 1.26.1-dev.834 → 1.26.1-dev.835
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 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +16 -0
- package/dist/compat/index.mjs +1 -0
- package/dist/compat/util/iteratee.d.mts +41 -0
- package/dist/compat/util/iteratee.d.ts +41 -0
- package/dist/compat/util/iteratee.mjs +20 -0
- package/package.json +1 -1
package/dist/compat/index.d.mts
CHANGED
|
@@ -210,6 +210,7 @@ export { upperCase } from './string/upperCase.mjs';
|
|
|
210
210
|
export { constant } from './util/constant.mjs';
|
|
211
211
|
export { defaultTo } from './util/defaultTo.mjs';
|
|
212
212
|
export { eq } from './util/eq.mjs';
|
|
213
|
+
export { iteratee } from './util/iteratee.mjs';
|
|
213
214
|
export { times } from './util/times.mjs';
|
|
214
215
|
export { toFinite } from './util/toFinite.mjs';
|
|
215
216
|
export { toInteger } from './util/toInteger.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -210,6 +210,7 @@ export { upperCase } from './string/upperCase.js';
|
|
|
210
210
|
export { constant } from './util/constant.js';
|
|
211
211
|
export { defaultTo } from './util/defaultTo.js';
|
|
212
212
|
export { eq } from './util/eq.js';
|
|
213
|
+
export { iteratee } from './util/iteratee.js';
|
|
213
214
|
export { times } from './util/times.js';
|
|
214
215
|
export { toFinite } from './util/toFinite.js';
|
|
215
216
|
export { toInteger } from './util/toInteger.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -2329,6 +2329,21 @@ function defaultTo(value, defaultValue) {
|
|
|
2329
2329
|
return value;
|
|
2330
2330
|
}
|
|
2331
2331
|
|
|
2332
|
+
function iteratee(value) {
|
|
2333
|
+
if (value == null) {
|
|
2334
|
+
return (value) => value;
|
|
2335
|
+
}
|
|
2336
|
+
switch (typeof value) {
|
|
2337
|
+
case 'function': {
|
|
2338
|
+
return value;
|
|
2339
|
+
}
|
|
2340
|
+
case 'object': {
|
|
2341
|
+
return Array.isArray(value) ? matchesProperty(value[0], value[1]) : matches(value);
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
return property(value);
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2332
2347
|
function times(n, getValue) {
|
|
2333
2348
|
n = toInteger(n);
|
|
2334
2349
|
if (n < 1 || !Number.isSafeInteger(n)) {
|
|
@@ -2531,6 +2546,7 @@ exports.isSymbol = isSymbol;
|
|
|
2531
2546
|
exports.isTypedArray = isTypedArray;
|
|
2532
2547
|
exports.isWeakMap = isWeakMap;
|
|
2533
2548
|
exports.isWeakSet = isWeakSet;
|
|
2549
|
+
exports.iteratee = iteratee;
|
|
2534
2550
|
exports.join = join;
|
|
2535
2551
|
exports.kebabCase = kebabCase;
|
|
2536
2552
|
exports.last = last;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -210,6 +210,7 @@ export { trimStart } from './string/trimStart.mjs';
|
|
|
210
210
|
export { upperCase } from './string/upperCase.mjs';
|
|
211
211
|
export { constant } from './util/constant.mjs';
|
|
212
212
|
export { defaultTo } from './util/defaultTo.mjs';
|
|
213
|
+
export { iteratee } from './util/iteratee.mjs';
|
|
213
214
|
export { times } from './util/times.mjs';
|
|
214
215
|
export { toFinite } from './util/toFinite.mjs';
|
|
215
216
|
export { toInteger } from './util/toInteger.mjs';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a `identity` function when `value` is `null` or `undefined`.
|
|
3
|
+
*
|
|
4
|
+
* @param {null} [value] - The value to convert to an iteratee.
|
|
5
|
+
* @returns {(value: unknown) => unknown} - Returns a `identity` function.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const func = iteratee();
|
|
9
|
+
*
|
|
10
|
+
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [{ a: 1 }, { a: 2 }, { a: 3 }]
|
|
11
|
+
*/
|
|
12
|
+
declare function iteratee(value?: null): (value: unknown) => unknown;
|
|
13
|
+
/**
|
|
14
|
+
* Returns a given `func` function when `value` is a `function`.
|
|
15
|
+
*
|
|
16
|
+
* @template {(...args: any[]) => unknown} F - The function type.
|
|
17
|
+
* @param {F} func - The function to return.
|
|
18
|
+
* @returns {F} - Returns the given function.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const func = iteratee((object) => object.a);
|
|
22
|
+
*
|
|
23
|
+
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
|
|
24
|
+
*/
|
|
25
|
+
declare function iteratee<F extends (...args: any[]) => unknown>(func: F): F;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a function that invokes `value` with the arguments of the created function.
|
|
28
|
+
*
|
|
29
|
+
* The created function returns the property value for a given element.
|
|
30
|
+
*
|
|
31
|
+
* @param {symbol | number | string | object} value - The value to convert to an iteratee.
|
|
32
|
+
* @returns {(...args: any[]) => unknown} - Returns the new iteratee function.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const func = iteratee('a');
|
|
36
|
+
*
|
|
37
|
+
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
|
|
38
|
+
*/
|
|
39
|
+
declare function iteratee(value: symbol | number | string | object): (...args: any[]) => unknown;
|
|
40
|
+
|
|
41
|
+
export { iteratee };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a `identity` function when `value` is `null` or `undefined`.
|
|
3
|
+
*
|
|
4
|
+
* @param {null} [value] - The value to convert to an iteratee.
|
|
5
|
+
* @returns {(value: unknown) => unknown} - Returns a `identity` function.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const func = iteratee();
|
|
9
|
+
*
|
|
10
|
+
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [{ a: 1 }, { a: 2 }, { a: 3 }]
|
|
11
|
+
*/
|
|
12
|
+
declare function iteratee(value?: null): (value: unknown) => unknown;
|
|
13
|
+
/**
|
|
14
|
+
* Returns a given `func` function when `value` is a `function`.
|
|
15
|
+
*
|
|
16
|
+
* @template {(...args: any[]) => unknown} F - The function type.
|
|
17
|
+
* @param {F} func - The function to return.
|
|
18
|
+
* @returns {F} - Returns the given function.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const func = iteratee((object) => object.a);
|
|
22
|
+
*
|
|
23
|
+
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
|
|
24
|
+
*/
|
|
25
|
+
declare function iteratee<F extends (...args: any[]) => unknown>(func: F): F;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a function that invokes `value` with the arguments of the created function.
|
|
28
|
+
*
|
|
29
|
+
* The created function returns the property value for a given element.
|
|
30
|
+
*
|
|
31
|
+
* @param {symbol | number | string | object} value - The value to convert to an iteratee.
|
|
32
|
+
* @returns {(...args: any[]) => unknown} - Returns the new iteratee function.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const func = iteratee('a');
|
|
36
|
+
*
|
|
37
|
+
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
|
|
38
|
+
*/
|
|
39
|
+
declare function iteratee(value: symbol | number | string | object): (...args: any[]) => unknown;
|
|
40
|
+
|
|
41
|
+
export { iteratee };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { property } from '../object/property.mjs';
|
|
2
|
+
import { matches } from '../predicate/matches.mjs';
|
|
3
|
+
import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|
4
|
+
|
|
5
|
+
function iteratee(value) {
|
|
6
|
+
if (value == null) {
|
|
7
|
+
return (value) => value;
|
|
8
|
+
}
|
|
9
|
+
switch (typeof value) {
|
|
10
|
+
case 'function': {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
case 'object': {
|
|
14
|
+
return Array.isArray(value) ? matchesProperty(value[0], value[1]) : matches(value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return property(value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { iteratee };
|
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.26.1-dev.
|
|
4
|
+
"version": "1.26.1-dev.835+62fe7e03",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|