es-toolkit 1.33.0 → 1.34.0
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 +10 -0
- package/dist/_chunk/invariant-BfGFfr.js +21 -0
- package/dist/_chunk/{isWeakSet-TIM260.js → isWeakSet-CQZSI-.js} +10 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/assignValue.mjs +10 -0
- package/dist/compat/_internal/isKey.mjs +1 -1
- package/dist/compat/_internal/toKey.mjs +4 -1
- package/dist/compat/array/filter.mjs +14 -31
- package/dist/compat/array/intersectionWith.mjs +0 -1
- package/dist/compat/array/map.d.mts +1 -1
- package/dist/compat/array/map.d.ts +1 -1
- package/dist/compat/array/reject.d.mts +117 -0
- package/dist/compat/array/reject.d.ts +117 -0
- package/dist/compat/array/reject.mjs +9 -0
- package/dist/compat/array/sortedIndexOf.d.mts +34 -0
- package/dist/compat/array/sortedIndexOf.d.ts +34 -0
- package/dist/compat/array/sortedIndexOf.mjs +15 -0
- package/dist/compat/index.d.mts +9 -3
- package/dist/compat/index.d.ts +9 -3
- package/dist/compat/index.js +176 -93
- package/dist/compat/index.mjs +9 -3
- package/dist/compat/math/add.mjs +17 -0
- package/dist/compat/math/divide.mjs +0 -1
- package/dist/compat/math/mean.d.mts +16 -0
- package/dist/compat/math/mean.d.ts +16 -0
- package/dist/compat/math/mean.mjs +8 -0
- package/dist/compat/math/meanBy.d.mts +25 -0
- package/dist/compat/math/meanBy.d.ts +25 -0
- package/dist/compat/math/meanBy.mjs +11 -0
- package/dist/compat/math/minBy.d.mts +31 -0
- package/dist/compat/math/minBy.d.ts +31 -0
- package/dist/compat/math/minBy.mjs +11 -0
- package/dist/compat/math/subtract.mjs +17 -0
- package/dist/compat/object/functionsIn.d.mts +20 -0
- package/dist/compat/object/functionsIn.d.ts +20 -0
- package/dist/compat/object/functionsIn.mjs +16 -0
- package/dist/compat/object/set.mjs +21 -8
- package/dist/compat/util/invoke.mjs +1 -1
- package/dist/compat/util/stubObject.d.mts +1 -1
- package/dist/compat/util/stubObject.d.ts +1 -1
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +7 -2
- package/dist/index.mjs +4 -0
- package/dist/predicate/index.d.mts +2 -0
- package/dist/predicate/index.d.ts +2 -0
- package/dist/predicate/index.js +3 -1
- package/dist/predicate/index.mjs +2 -0
- package/dist/predicate/isBrowser.d.mts +17 -0
- package/dist/predicate/isBrowser.d.ts +17 -0
- package/dist/predicate/isBrowser.mjs +5 -0
- package/dist/predicate/isNode.d.mts +17 -0
- package/dist/predicate/isNode.d.ts +17 -0
- package/dist/predicate/isNode.mjs +5 -0
- package/dist/util/attempt.d.mts +42 -0
- package/dist/util/attempt.d.ts +42 -0
- package/dist/util/attempt.mjs +10 -0
- package/dist/util/attemptAsync.d.mts +35 -0
- package/dist/util/attemptAsync.d.ts +35 -0
- package/dist/util/attemptAsync.mjs +11 -0
- package/dist/util/index.d.mts +2 -0
- package/dist/util/index.d.ts +2 -0
- package/dist/util/index.js +11 -5
- package/dist/util/index.mjs +2 -0
- package/package.json +7 -5
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attempt to execute an async function and return the result or error.
|
|
3
|
+
* Returns a Promise that resolves to a tuple where:
|
|
4
|
+
* - On success: [null, Result] - First element is null, second is the result
|
|
5
|
+
* - On error: [Error, null] - First element is the caught error, second is null
|
|
6
|
+
*
|
|
7
|
+
* @template {unknown} T - The type of the result of the async function.
|
|
8
|
+
* @template {unknown} E - The type of the error that can be thrown by the async function.
|
|
9
|
+
* @param {() => Promise<T>} func - The async function to execute.
|
|
10
|
+
* @returns {Promise<[null, T] | [E, null]>} A Promise that resolves to a tuple containing either [null, result] or [error, null].
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Successful execution
|
|
14
|
+
* const [error, data] = await attemptAsync(async () => {
|
|
15
|
+
* const response = await fetch('https://api.example.com/data');
|
|
16
|
+
* return response.json();
|
|
17
|
+
* });
|
|
18
|
+
* // If successful: [null, { ... data ... }]
|
|
19
|
+
*
|
|
20
|
+
* // Failed execution
|
|
21
|
+
* const [error, data] = await attemptAsync(async () => {
|
|
22
|
+
* throw new Error('Network error');
|
|
23
|
+
* });
|
|
24
|
+
* // [Error, null]
|
|
25
|
+
*
|
|
26
|
+
* // With type parameter
|
|
27
|
+
* const [error, users] = await attemptAsync<User[]>(async () => {
|
|
28
|
+
* const response = await fetch('https://api.example.com/users');
|
|
29
|
+
* return response.json();
|
|
30
|
+
* });
|
|
31
|
+
* // users is typed as User[]
|
|
32
|
+
*/
|
|
33
|
+
declare function attemptAsync<T, E>(func: () => Promise<T>): Promise<[null, T] | [E, null]>;
|
|
34
|
+
|
|
35
|
+
export { attemptAsync };
|
package/dist/util/index.d.mts
CHANGED
package/dist/util/index.d.ts
CHANGED
package/dist/util/index.js
CHANGED
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const invariant = require('../_chunk/invariant-BfGFfr.js');
|
|
6
|
+
|
|
7
|
+
function attempt(func) {
|
|
8
|
+
try {
|
|
9
|
+
return [null, func()];
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
return [error, null];
|
|
8
13
|
}
|
|
9
|
-
throw new Error(message);
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
exports.
|
|
16
|
+
exports.attemptAsync = invariant.attemptAsync;
|
|
17
|
+
exports.invariant = invariant.invariant;
|
|
18
|
+
exports.attempt = attempt;
|
package/dist/util/index.mjs
CHANGED
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.
|
|
4
|
+
"version": "1.34.0",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"docs",
|
|
14
14
|
"benchmarks"
|
|
15
15
|
],
|
|
16
|
-
"packageManager": "yarn@4.
|
|
16
|
+
"packageManager": "yarn@4.7.0",
|
|
17
17
|
"react-native": "./dist/index.js",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
@@ -265,10 +265,11 @@
|
|
|
265
265
|
"@types/jscodeshift": "^0.12.0",
|
|
266
266
|
"@types/node": "^22.7.4",
|
|
267
267
|
"@types/tar": "^6.1.13",
|
|
268
|
+
"@typescript-eslint/parser": "^8.26.1",
|
|
268
269
|
"@vitest/coverage-istanbul": "^2.1.2",
|
|
269
270
|
"@vue/compiler-sfc": "^3.5.10",
|
|
270
271
|
"broken-link-checker": "^0.7.8",
|
|
271
|
-
"eslint": "^9.
|
|
272
|
+
"eslint": "^9.22.0",
|
|
272
273
|
"eslint-config-prettier": "^9.1.0",
|
|
273
274
|
"eslint-plugin-no-for-of-array": "^0.0.1",
|
|
274
275
|
"eslint-plugin-prettier": "^5.2.1",
|
|
@@ -284,8 +285,9 @@
|
|
|
284
285
|
"tar": "^6",
|
|
285
286
|
"tslib": "^2.6.3",
|
|
286
287
|
"tsx": "^4.19.0",
|
|
287
|
-
"typescript": "^5.
|
|
288
|
-
"typescript-eslint": "^8.
|
|
288
|
+
"typescript": "^5.8.2",
|
|
289
|
+
"typescript-eslint": "^8.6.0",
|
|
290
|
+
"vercel": "^41.4.1",
|
|
289
291
|
"vitest": "^2.1.2"
|
|
290
292
|
},
|
|
291
293
|
"dependenciesMeta": {
|