es-toolkit 0.0.1-dev.20

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 (163) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +31 -0
  3. package/dist/array/chunk.d.ts +24 -0
  4. package/dist/array/chunk.spec.d.ts +1 -0
  5. package/dist/array/difference.d.ts +23 -0
  6. package/dist/array/difference.spec.d.ts +1 -0
  7. package/dist/array/differenceBy.d.ts +26 -0
  8. package/dist/array/differenceBy.spec.d.ts +1 -0
  9. package/dist/array/differenceWith.d.ts +22 -0
  10. package/dist/array/differenceWith.spec.d.ts +1 -0
  11. package/dist/array/drop.d.ts +16 -0
  12. package/dist/array/drop.spec.d.ts +1 -0
  13. package/dist/array/dropRight.d.ts +16 -0
  14. package/dist/array/dropRight.spec.d.ts +1 -0
  15. package/dist/array/dropRightWhile.d.ts +18 -0
  16. package/dist/array/dropRightWhile.spec.d.ts +1 -0
  17. package/dist/array/dropWhile.d.ts +18 -0
  18. package/dist/array/dropWhile.spec.d.ts +1 -0
  19. package/dist/array/groupBy.d.ts +31 -0
  20. package/dist/array/groupBy.spec.d.ts +1 -0
  21. package/dist/array/index.d.ts +30 -0
  22. package/dist/array/index.js +991 -0
  23. package/dist/array/intersection.d.ts +18 -0
  24. package/dist/array/intersection.spec.d.ts +1 -0
  25. package/dist/array/intersectionBy.d.ts +21 -0
  26. package/dist/array/intersectionBy.spec.d.ts +1 -0
  27. package/dist/array/intersectionWith.d.ts +22 -0
  28. package/dist/array/intersectionWith.spec.d.ts +1 -0
  29. package/dist/array/partition.d.ts +22 -0
  30. package/dist/array/partition.spec.d.ts +1 -0
  31. package/dist/array/sample.d.ts +14 -0
  32. package/dist/array/sample.spec.d.ts +1 -0
  33. package/dist/array/shuffle.d.ts +14 -0
  34. package/dist/array/shuffle.spec.d.ts +1 -0
  35. package/dist/array/take.d.ts +23 -0
  36. package/dist/array/take.spec.d.ts +1 -0
  37. package/dist/array/takeRight.d.ts +21 -0
  38. package/dist/array/takeRight.spec.d.ts +1 -0
  39. package/dist/array/takeRightWhile.d.ts +18 -0
  40. package/dist/array/takeRightWhile.spec.d.ts +1 -0
  41. package/dist/array/takeWhile.d.ts +19 -0
  42. package/dist/array/takeWhile.spec.d.ts +1 -0
  43. package/dist/array/union.d.ts +17 -0
  44. package/dist/array/union.spec.d.ts +1 -0
  45. package/dist/array/unionBy.d.ts +21 -0
  46. package/dist/array/unionBy.spec.d.ts +1 -0
  47. package/dist/array/unionWith.d.ts +20 -0
  48. package/dist/array/unionWith.spec.d.ts +1 -0
  49. package/dist/array/uniq.d.ts +15 -0
  50. package/dist/array/uniq.spec.d.ts +1 -0
  51. package/dist/array/uniqBy.d.ts +12 -0
  52. package/dist/array/uniqBy.spec.d.ts +1 -0
  53. package/dist/array/uniqWith.d.ts +12 -0
  54. package/dist/array/uniqWith.spec.d.ts +1 -0
  55. package/dist/array/xor.d.ts +17 -0
  56. package/dist/array/xor.spec.d.ts +1 -0
  57. package/dist/array/xorBy.d.ts +20 -0
  58. package/dist/array/xorBy.spec.d.ts +1 -0
  59. package/dist/array/xorWith.d.ts +19 -0
  60. package/dist/array/xorWith.spec.d.ts +1 -0
  61. package/dist/array/zip.d.ts +25 -0
  62. package/dist/array/zip.spec.d.ts +1 -0
  63. package/dist/array/zipWith.d.ts +32 -0
  64. package/dist/array/zipWith.spec.d.ts +1 -0
  65. package/dist/function/debounce.d.ts +24 -0
  66. package/dist/function/debounce.spec.d.ts +1 -0
  67. package/dist/function/index.d.ts +3 -0
  68. package/dist/function/index.js +112 -0
  69. package/dist/function/once.d.ts +17 -0
  70. package/dist/function/once.spec.d.ts +1 -0
  71. package/dist/function/throttle.d.ts +26 -0
  72. package/dist/function/throttle.spec.d.ts +1 -0
  73. package/dist/index.d.ts +6 -0
  74. package/dist/index.js +1514 -0
  75. package/dist/math/clamp.d.ts +19 -0
  76. package/dist/math/clamp.spec.d.ts +1 -0
  77. package/dist/math/index.d.ts +3 -0
  78. package/dist/math/index.js +148 -0
  79. package/dist/math/round.d.ts +16 -0
  80. package/dist/math/round.spec.d.ts +1 -0
  81. package/dist/math/sum.d.ts +14 -0
  82. package/dist/math/sum.spec.d.ts +1 -0
  83. package/dist/object/index.d.ts +4 -0
  84. package/dist/object/index.js +286 -0
  85. package/dist/object/omit.d.ts +16 -0
  86. package/dist/object/omit.spec.d.ts +1 -0
  87. package/dist/object/omitBy.d.ts +19 -0
  88. package/dist/object/omitBy.spec.d.ts +1 -0
  89. package/dist/object/pick.d.ts +16 -0
  90. package/dist/object/pick.spec.d.ts +1 -0
  91. package/dist/object/pickBy.d.ts +19 -0
  92. package/dist/object/pickBy.spec.d.ts +1 -0
  93. package/dist/predicate/index.d.ts +4 -0
  94. package/dist/predicate/index.js +98 -0
  95. package/dist/predicate/isNil.d.ts +20 -0
  96. package/dist/predicate/isNil.spec.d.ts +1 -0
  97. package/dist/predicate/isNotNil.d.ts +16 -0
  98. package/dist/predicate/isNotNil.spec.d.ts +1 -0
  99. package/dist/predicate/isNull.d.ts +21 -0
  100. package/dist/predicate/isNull.spec.d.ts +1 -0
  101. package/dist/predicate/isUndefined.d.ts +21 -0
  102. package/dist/predicate/isUndefined.spec.d.ts +1 -0
  103. package/dist/promise/delay.d.ts +19 -0
  104. package/dist/promise/delay.spec.d.ts +1 -0
  105. package/dist/promise/index.d.ts +1 -0
  106. package/dist/promise/index.js +29 -0
  107. package/esm/_virtual/_rollupPluginBabelHelpers.mjs +163 -0
  108. package/esm/array/_virtual/_rollupPluginBabelHelpers.mjs +78 -0
  109. package/esm/array/chunk.mjs +38 -0
  110. package/esm/array/difference.mjs +29 -0
  111. package/esm/array/differenceBy.mjs +35 -0
  112. package/esm/array/differenceWith.mjs +30 -0
  113. package/esm/array/drop.mjs +20 -0
  114. package/esm/array/dropRight.mjs +20 -0
  115. package/esm/array/dropRightWhile.mjs +26 -0
  116. package/esm/array/dropWhile.mjs +25 -0
  117. package/esm/array/groupBy.mjs +54 -0
  118. package/esm/array/index.mjs +30 -0
  119. package/esm/array/intersection.mjs +24 -0
  120. package/esm/array/intersectionBy.mjs +30 -0
  121. package/esm/array/intersectionWith.mjs +30 -0
  122. package/esm/array/partition.mjs +46 -0
  123. package/esm/array/sample.mjs +19 -0
  124. package/esm/array/shuffle.mjs +27 -0
  125. package/esm/array/take.mjs +27 -0
  126. package/esm/array/takeRight.mjs +28 -0
  127. package/esm/array/takeRightWhile.mjs +27 -0
  128. package/esm/array/takeWhile.mjs +41 -0
  129. package/esm/array/union.mjs +23 -0
  130. package/esm/array/unionBy.mjs +35 -0
  131. package/esm/array/unionWith.mjs +26 -0
  132. package/esm/array/uniq.mjs +37 -0
  133. package/esm/array/uniqBy.mjs +20 -0
  134. package/esm/array/uniqWith.mjs +39 -0
  135. package/esm/array/xor.mjs +25 -0
  136. package/esm/array/xorBy.mjs +30 -0
  137. package/esm/array/xorWith.mjs +29 -0
  138. package/esm/array/zip.mjs +52 -0
  139. package/esm/array/zipWith.mjs +54 -0
  140. package/esm/function/debounce.mjs +39 -0
  141. package/esm/function/index.mjs +3 -0
  142. package/esm/function/once.mjs +31 -0
  143. package/esm/function/throttle.mjs +38 -0
  144. package/esm/index.mjs +45 -0
  145. package/esm/math/_virtual/_rollupPluginBabelHelpers.mjs +66 -0
  146. package/esm/math/clamp.mjs +26 -0
  147. package/esm/math/index.mjs +3 -0
  148. package/esm/math/round.mjs +22 -0
  149. package/esm/math/sum.mjs +33 -0
  150. package/esm/object/_virtual/_rollupPluginBabelHelpers.mjs +151 -0
  151. package/esm/object/index.mjs +4 -0
  152. package/esm/object/omit.mjs +35 -0
  153. package/esm/object/omitBy.mjs +35 -0
  154. package/esm/object/pick.mjs +35 -0
  155. package/esm/object/pickBy.mjs +35 -0
  156. package/esm/predicate/index.mjs +4 -0
  157. package/esm/predicate/isNil.mjs +24 -0
  158. package/esm/predicate/isNotNil.mjs +20 -0
  159. package/esm/predicate/isNull.mjs +25 -0
  160. package/esm/predicate/isUndefined.mjs +25 -0
  161. package/esm/promise/delay.mjs +25 -0
  162. package/esm/promise/index.mjs +1 -0
  163. package/package.json +108 -0
@@ -0,0 +1,35 @@
1
+ import { slicedToArray as _slicedToArray } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
+
3
+ /**
4
+ * Creates a new object composed of the properties that do not satisfy the predicate function.
5
+ *
6
+ * This function takes an object and a predicate function, and returns a new object that
7
+ * includes only the properties for which the predicate function returns false.
8
+ *
9
+ * @param {T} obj - The object to omit properties from.
10
+ * @param {(value: T[string], key: string) => boolean} shouldOmit - A predicate function that determines
11
+ * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`
12
+ * if the property should be omitted, and `false` otherwise.
13
+ * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.
14
+ *
15
+ * @example
16
+ * const obj = { a: 1, b: 'omit', c: 3 };
17
+ * const shouldOmit = (key, value) => typeof value === 'string';
18
+ * const result = omitBy(obj, shouldOmit);
19
+ * // result will be { a: 1, c: 3 }
20
+ */
21
+ function omitBy(obj, shouldOmit) {
22
+ var result = {};
23
+ for (var _i = 0, _Object$entries = Object.entries(obj); _i < _Object$entries.length; _i++) {
24
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
25
+ key = _Object$entries$_i[0],
26
+ value = _Object$entries$_i[1];
27
+ if (shouldOmit(value, key)) {
28
+ continue;
29
+ }
30
+ result[key] = value;
31
+ }
32
+ return result;
33
+ }
34
+
35
+ export { omitBy };
@@ -0,0 +1,35 @@
1
+ import { createForOfIteratorHelper as _createForOfIteratorHelper } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
+
3
+ /**
4
+ * Creates a new object composed of the picked object properties.
5
+ *
6
+ * This function takes an object and an array of keys, and returns a new object that
7
+ * includes only the properties corresponding to the specified keys.
8
+ *
9
+ * @param {T} obj - The object to pick keys from.
10
+ * @param {K[]} keys - An array of keys to be picked from the object.
11
+ * @returns {Pick<T, K>} A new object with the specified keys picked.
12
+ *
13
+ * @example
14
+ * * const obj = { a: 1, b: 2, c: 3 };
15
+ * const result = pick(obj, ['a', 'c']);
16
+ * // result will be { a: 1, c: 3 }
17
+ */
18
+ function pick(obj, keys) {
19
+ var result = {};
20
+ var _iterator = _createForOfIteratorHelper(keys),
21
+ _step;
22
+ try {
23
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
24
+ var key = _step.value;
25
+ result[key] = obj[key];
26
+ }
27
+ } catch (err) {
28
+ _iterator.e(err);
29
+ } finally {
30
+ _iterator.f();
31
+ }
32
+ return result;
33
+ }
34
+
35
+ export { pick };
@@ -0,0 +1,35 @@
1
+ import { slicedToArray as _slicedToArray } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
+
3
+ /**
4
+ * Creates a new object composed of the properties that satisfy the predicate function.
5
+ *
6
+ * This function takes an object and a predicate function, and returns a new object that
7
+ * includes only the properties for which the predicate function returns true.
8
+ *
9
+ * @param {T} obj - The object to pick properties from.
10
+ * @param {(value: T[keyof T], key: string) => boolean} shouldPick - A predicate function that determines
11
+ * whether a property should be picked. It takes the property's key and value as arguments and returns `true`
12
+ * if the property should be picked, and `false` otherwise.
13
+ * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.
14
+ *
15
+ * @example
16
+ * const obj = { a: 1, b: 'pick', c: 3 };
17
+ * const shouldPick = (value) => typeof value === 'string';
18
+ * const result = pickBy(obj, shouldPick);
19
+ * // result will be { b: 'pick' }
20
+ */
21
+ function pickBy(obj, shouldPick) {
22
+ var result = {};
23
+ for (var _i = 0, _Object$entries = Object.entries(obj); _i < _Object$entries.length; _i++) {
24
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
25
+ key = _Object$entries$_i[0],
26
+ value = _Object$entries$_i[1];
27
+ if (!shouldPick(value, key)) {
28
+ continue;
29
+ }
30
+ result[key] = value;
31
+ }
32
+ return result;
33
+ }
34
+
35
+ export { pickBy };
@@ -0,0 +1,4 @@
1
+ export { isNil } from './isNil.mjs';
2
+ export { isNotNil } from './isNotNil.mjs';
3
+ export { isNull } from './isNull.mjs';
4
+ export { isUndefined } from './isUndefined.mjs';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Checks if a given value is null or undefined.
3
+ *
4
+ * This function tests whether the provided value is either `null` or `undefined`.
5
+ * It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
6
+ *
7
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
8
+ *
9
+ * @param {unknown} x - The value to test for null or undefined.
10
+ * @returns {boolean} `true` if the value is null or undefined, `false` otherwise.
11
+ *
12
+ * @example
13
+ * * const value1 = null;
14
+ * const value2 = undefined;
15
+ * const value3 = 42;
16
+ * const result1 = isNil(value1); // true
17
+ * const result2 = isNil(value2); // true
18
+ * const result3 = isNil(value3); // false
19
+ */
20
+ function isNil(x) {
21
+ return x == null || x == undefined;
22
+ }
23
+
24
+ export { isNil };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks if the given value is not null nor undefined.
3
+ *
4
+ * The main use of this function is to be used with TypeScript as a type predicate.
5
+ *
6
+ * @param {T | null | undefined} x - The value to test if it is not null nor undefined.
7
+ * @returns {x is T} True if the value is not null nor undefined, false otherwise.
8
+ *
9
+ * @example
10
+ * // Here the type of `arr` is (number | undefined)[]
11
+ * const arr = [1, undefined, 3];
12
+ * // Here the type of `result` is number[]
13
+ * const result = arr.filter(isNotNil);
14
+ * // result will be [1, 3]
15
+ */
16
+ function isNotNil(x) {
17
+ return x != null && x != undefined;
18
+ }
19
+
20
+ export { isNotNil };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Checks if the given value is null.
3
+ *
4
+ * This function tests whether the provided value is strictly equal to `null`.
5
+ * It returns `true` if the value is `null`, and `false` otherwise.
6
+ *
7
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
8
+ *
9
+ * @param {unknown} x - The value to test if it is null.
10
+ * @returns {x is null} True if the value is null, false otherwise.
11
+ *
12
+ * @example
13
+ * * const value1 = null;
14
+ * const value2 = undefined;
15
+ * const value3 = 42;
16
+ *
17
+ * console.log(isNull(value1)); // true
18
+ * console.log(isNull(value2)); // false
19
+ * console.log(isNull(value3)); // false
20
+ */
21
+ function isNull(x) {
22
+ return x === null;
23
+ }
24
+
25
+ export { isNull };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Checks if the given value is undefined.
3
+ *
4
+ * This function tests whether the provided value is strictly equal to `undefined`.
5
+ * It returns `true` if the value is `undefined`, and `false` otherwise.
6
+ *
7
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`.
8
+ *
9
+ * @param {unknown} x - The value to test if it is undefined.
10
+ * @returns {x is undefined} true if the value is undefined, false otherwise.
11
+ *
12
+ * @example
13
+ * * const value1 = undefined;
14
+ * const value2 = null;
15
+ * const value3 = 42;
16
+ *
17
+ * console.log(isUndefined(value1)); // true
18
+ * console.log(isUndefined(value2)); // false
19
+ * console.log(isUndefined(value3)); // false
20
+ */
21
+ function isUndefined(x) {
22
+ return x === undefined;
23
+ }
24
+
25
+ export { isUndefined };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Delays the execution of code for a specified number of milliseconds.
3
+ *
4
+ * This function returns a Promise that resolves after the specified delay, allowing you to use it
5
+ * with async/await to pause execution.
6
+ *
7
+ * @param {number} ms - The number of milliseconds to delay.
8
+ * @returns {Promise<void>} A Promise that resolves after the specified delay.
9
+ *
10
+ * @example
11
+ * async function foo() {
12
+ * console.log('Start');
13
+ * await delay(1000); // Delays execution for 1 second
14
+ * console.log('End');
15
+ * }
16
+ *
17
+ * foo();
18
+ */
19
+ function delay(ms) {
20
+ return new Promise(function (resolve) {
21
+ setTimeout(resolve, ms);
22
+ });
23
+ }
24
+
25
+ export { delay };
@@ -0,0 +1 @@
1
+ export { delay } from './delay.mjs';
package/package.json ADDED
@@ -0,0 +1,108 @@
1
+ {
2
+ "name": "es-toolkit",
3
+ "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
+ "version": "0.0.1-dev.20+0e8c4504",
5
+ "workspaces": [
6
+ "docs"
7
+ ],
8
+ "packageManager": "yarn@4.2.2",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./esm/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./array": {
15
+ "import": "./esm/array/index.mjs",
16
+ "require": "./dist/array/index.js"
17
+ },
18
+ "./function": {
19
+ "import": "./esm/function/index.mjs",
20
+ "require": "./dist/function/index.js"
21
+ },
22
+ "./math": {
23
+ "import": "./esm/math/index.mjs",
24
+ "require": "./dist/math/index.js"
25
+ },
26
+ "./object": {
27
+ "import": "./esm/object/index.mjs",
28
+ "require": "./dist/object/index.js"
29
+ },
30
+ "./predicate": {
31
+ "import": "./esm/predicate/index.mjs",
32
+ "require": "./dist/predicate/index.js"
33
+ },
34
+ "./promise": {
35
+ "import": "./esm/promise/index.mjs",
36
+ "require": "./dist/promise/index.js"
37
+ },
38
+ "./package.json": "./package.json"
39
+ },
40
+ "files": [
41
+ "dist/**/*",
42
+ "esm/**/*"
43
+ ],
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "exports": {
47
+ ".": {
48
+ "import": "./esm/index.mjs",
49
+ "require": "./dist/index.js"
50
+ },
51
+ "./array": {
52
+ "import": "./esm/array/index.mjs",
53
+ "require": "./dist/array/index.js"
54
+ },
55
+ "./function": {
56
+ "import": "./esm/function/index.mjs",
57
+ "require": "./dist/function/index.js"
58
+ },
59
+ "./math": {
60
+ "import": "./esm/math/index.mjs",
61
+ "require": "./dist/math/index.js"
62
+ },
63
+ "./object": {
64
+ "import": "./esm/object/index.mjs",
65
+ "require": "./dist/object/index.js"
66
+ },
67
+ "./predicate": {
68
+ "import": "./esm/predicate/index.mjs",
69
+ "require": "./dist/predicate/index.js"
70
+ },
71
+ "./promise": {
72
+ "import": "./esm/promise/index.mjs",
73
+ "require": "./dist/promise/index.js"
74
+ },
75
+ "./package.json": "./package.json"
76
+ }
77
+ },
78
+ "devDependencies": {
79
+ "@babel/core": "^7.24.5",
80
+ "@babel/preset-env": "^7.24.5",
81
+ "@babel/preset-typescript": "^7.24.1",
82
+ "@changesets/changelog-github": "^0.5.0",
83
+ "@changesets/cli": "^2.27.1",
84
+ "@toss/rollup-config": "0.2.0-canary.0",
85
+ "@types/babel__core": "^7",
86
+ "@types/babel__preset-env": "^7",
87
+ "@types/broken-link-checker": "^0",
88
+ "@types/lodash": "^4",
89
+ "@types/node": "^20.12.11",
90
+ "@typescript-eslint/eslint-plugin": "^7.7.1",
91
+ "@typescript-eslint/parser": "^7.7.1",
92
+ "@vitest/coverage-istanbul": "^1.5.2",
93
+ "broken-link-checker": "^0.7.8",
94
+ "eslint": "^8.56.0",
95
+ "eslint-config-prettier": "^8.5.0",
96
+ "lodash": "^4.17.21",
97
+ "prettier": "^3.2.5",
98
+ "rollup": "^2.78.0",
99
+ "typescript": "^5.4.5",
100
+ "vitest": "^1.5.2"
101
+ },
102
+ "sideEffects": false,
103
+ "scripts": {
104
+ "prepack": "yarn build",
105
+ "build": "rm -rf dist esm && tsc -p tsconfig.json --declaration --emitDeclarationOnly --declarationDir dist && rollup -c rollup.config.js",
106
+ "test": "vitest run --coverage --typecheck"
107
+ }
108
+ }