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.
Files changed (66) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/_chunk/invariant-BfGFfr.js +21 -0
  3. package/dist/_chunk/{isWeakSet-TIM260.js → isWeakSet-CQZSI-.js} +10 -0
  4. package/dist/browser.global.js +1 -1
  5. package/dist/browser.global.js.map +1 -1
  6. package/dist/compat/_internal/assignValue.mjs +10 -0
  7. package/dist/compat/_internal/isKey.mjs +1 -1
  8. package/dist/compat/_internal/toKey.mjs +4 -1
  9. package/dist/compat/array/filter.mjs +14 -31
  10. package/dist/compat/array/intersectionWith.mjs +0 -1
  11. package/dist/compat/array/map.d.mts +1 -1
  12. package/dist/compat/array/map.d.ts +1 -1
  13. package/dist/compat/array/reject.d.mts +117 -0
  14. package/dist/compat/array/reject.d.ts +117 -0
  15. package/dist/compat/array/reject.mjs +9 -0
  16. package/dist/compat/array/sortedIndexOf.d.mts +34 -0
  17. package/dist/compat/array/sortedIndexOf.d.ts +34 -0
  18. package/dist/compat/array/sortedIndexOf.mjs +15 -0
  19. package/dist/compat/index.d.mts +9 -3
  20. package/dist/compat/index.d.ts +9 -3
  21. package/dist/compat/index.js +176 -93
  22. package/dist/compat/index.mjs +9 -3
  23. package/dist/compat/math/add.mjs +17 -0
  24. package/dist/compat/math/divide.mjs +0 -1
  25. package/dist/compat/math/mean.d.mts +16 -0
  26. package/dist/compat/math/mean.d.ts +16 -0
  27. package/dist/compat/math/mean.mjs +8 -0
  28. package/dist/compat/math/meanBy.d.mts +25 -0
  29. package/dist/compat/math/meanBy.d.ts +25 -0
  30. package/dist/compat/math/meanBy.mjs +11 -0
  31. package/dist/compat/math/minBy.d.mts +31 -0
  32. package/dist/compat/math/minBy.d.ts +31 -0
  33. package/dist/compat/math/minBy.mjs +11 -0
  34. package/dist/compat/math/subtract.mjs +17 -0
  35. package/dist/compat/object/functionsIn.d.mts +20 -0
  36. package/dist/compat/object/functionsIn.d.ts +20 -0
  37. package/dist/compat/object/functionsIn.mjs +16 -0
  38. package/dist/compat/object/set.mjs +21 -8
  39. package/dist/compat/util/invoke.mjs +1 -1
  40. package/dist/compat/util/stubObject.d.mts +1 -1
  41. package/dist/compat/util/stubObject.d.ts +1 -1
  42. package/dist/index.d.mts +4 -0
  43. package/dist/index.d.ts +4 -0
  44. package/dist/index.js +7 -2
  45. package/dist/index.mjs +4 -0
  46. package/dist/predicate/index.d.mts +2 -0
  47. package/dist/predicate/index.d.ts +2 -0
  48. package/dist/predicate/index.js +3 -1
  49. package/dist/predicate/index.mjs +2 -0
  50. package/dist/predicate/isBrowser.d.mts +17 -0
  51. package/dist/predicate/isBrowser.d.ts +17 -0
  52. package/dist/predicate/isBrowser.mjs +5 -0
  53. package/dist/predicate/isNode.d.mts +17 -0
  54. package/dist/predicate/isNode.d.ts +17 -0
  55. package/dist/predicate/isNode.mjs +5 -0
  56. package/dist/util/attempt.d.mts +42 -0
  57. package/dist/util/attempt.d.ts +42 -0
  58. package/dist/util/attempt.mjs +10 -0
  59. package/dist/util/attemptAsync.d.mts +35 -0
  60. package/dist/util/attemptAsync.d.ts +35 -0
  61. package/dist/util/attemptAsync.mjs +11 -0
  62. package/dist/util/index.d.mts +2 -0
  63. package/dist/util/index.d.ts +2 -0
  64. package/dist/util/index.js +11 -5
  65. package/dist/util/index.mjs +2 -0
  66. 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 };
@@ -0,0 +1,11 @@
1
+ async function attemptAsync(func) {
2
+ try {
3
+ const result = await func();
4
+ return [null, result];
5
+ }
6
+ catch (error) {
7
+ return [error, null];
8
+ }
9
+ }
10
+
11
+ export { attemptAsync };
@@ -1 +1,3 @@
1
+ export { attempt } from './attempt.mjs';
2
+ export { attemptAsync } from './attemptAsync.mjs';
1
3
  export { invariant } from './invariant.mjs';
@@ -1 +1,3 @@
1
+ export { attempt } from './attempt.js';
2
+ export { attemptAsync } from './attemptAsync.js';
1
3
  export { invariant } from './invariant.js';
@@ -2,11 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- function invariant(condition, message) {
6
- if (condition) {
7
- return;
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.invariant = invariant;
16
+ exports.attemptAsync = invariant.attemptAsync;
17
+ exports.invariant = invariant.invariant;
18
+ exports.attempt = attempt;
@@ -1 +1,3 @@
1
+ export { attempt } from './attempt.mjs';
2
+ export { attemptAsync } from './attemptAsync.mjs';
1
3
  export { invariant } from './invariant.mjs';
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.33.0",
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.2.2",
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.9.0",
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.4.5",
288
- "typescript-eslint": "^8.1.0",
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": {