es-toolkit 1.3.1 → 1.4.0-dev.101
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 +14 -0
- package/dist/array/difference.d.mts +1 -1
- package/dist/array/difference.d.ts +1 -1
- package/dist/array/difference.js.map +1 -1
- package/dist/array/difference.mjs +1 -1
- package/dist/array/differenceWith.js.map +1 -1
- package/dist/array/differenceWith.mjs +1 -1
- package/dist/array/dropRightWhile.js.map +1 -1
- package/dist/array/dropRightWhile.mjs +2 -2
- package/dist/array/dropWhile.js.map +1 -1
- package/dist/array/dropWhile.mjs +1 -1
- package/dist/array/index.d.mts +2 -0
- package/dist/array/index.d.ts +2 -0
- package/dist/array/index.js +41 -2
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +31 -23
- package/dist/array/intersectionWith.js.map +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- package/dist/array/maxBy.d.mts +21 -0
- package/dist/array/maxBy.d.ts +21 -0
- package/dist/array/maxBy.js +42 -0
- package/dist/array/maxBy.js.map +1 -0
- package/dist/array/maxBy.mjs +8 -0
- package/dist/array/minBy.d.mts +13 -0
- package/dist/array/minBy.d.ts +13 -0
- package/dist/array/minBy.js +42 -0
- package/dist/array/minBy.js.map +1 -0
- package/dist/array/minBy.mjs +8 -0
- package/dist/array/unionBy.js +1 -1
- package/dist/array/unionBy.js.map +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/unionWith.js.map +1 -1
- package/dist/array/unionWith.mjs +1 -1
- package/dist/array/uniqBy.js +6 -13
- package/dist/array/uniqBy.js.map +1 -1
- package/dist/array/uniqBy.mjs +1 -2
- package/dist/array/xor.js.map +1 -1
- package/dist/array/xor.mjs +2 -2
- package/dist/array/xorBy.js +1 -1
- package/dist/array/xorBy.js.map +1 -1
- package/dist/array/xorBy.mjs +2 -2
- package/dist/array/xorWith.js.map +1 -1
- package/dist/array/xorWith.mjs +4 -4
- package/dist/array/zip.js.map +1 -1
- package/dist/array/zip.mjs +1 -1
- package/dist/array/zipWith.js.map +1 -1
- package/dist/array/zipWith.mjs +1 -1
- package/dist/{chunk-KLJRZJOR.mjs → chunk-2EFS3VA3.mjs} +1 -1
- package/dist/{chunk-KLJRZJOR.mjs.map → chunk-2EFS3VA3.mjs.map} +1 -1
- package/dist/{chunk-T5FDOBCA.mjs → chunk-4KYXHZ4R.mjs} +1 -1
- package/dist/{chunk-T5FDOBCA.mjs.map → chunk-4KYXHZ4R.mjs.map} +1 -1
- package/dist/{chunk-V7E5DGZP.mjs → chunk-5PMKOZ2F.mjs} +4 -1
- package/dist/chunk-5PMKOZ2F.mjs.map +1 -0
- package/dist/chunk-5UT77WON.mjs +13 -0
- package/dist/chunk-5UT77WON.mjs.map +1 -0
- package/dist/{chunk-3KHI4I2X.mjs → chunk-642SWVKJ.mjs} +1 -1
- package/dist/{chunk-3KHI4I2X.mjs.map → chunk-642SWVKJ.mjs.map} +1 -1
- package/dist/{chunk-FQ4K36VD.mjs → chunk-6NVQAHXP.mjs} +1 -1
- package/dist/{chunk-FQ4K36VD.mjs.map → chunk-6NVQAHXP.mjs.map} +1 -1
- package/dist/chunk-7LAMAYGN.mjs +1 -0
- package/dist/chunk-7LAMAYGN.mjs.map +1 -0
- package/dist/{chunk-SF3V7XXM.mjs → chunk-A67NF2C7.mjs} +1 -1
- package/dist/chunk-A67NF2C7.mjs.map +1 -0
- package/dist/chunk-AL3GJBEI.mjs +26 -0
- package/dist/chunk-AL3GJBEI.mjs.map +1 -0
- package/dist/{chunk-EW3RT4QW.mjs → chunk-AM2EGFCU.mjs} +2 -2
- package/dist/chunk-FZEZH22H.mjs +1 -0
- package/dist/chunk-FZEZH22H.mjs.map +1 -0
- package/dist/{chunk-WXIBCOES.mjs → chunk-G2TTBLLJ.mjs} +2 -2
- package/dist/chunk-H23GUJVF.mjs +18 -0
- package/dist/chunk-H23GUJVF.mjs.map +1 -0
- package/dist/{chunk-DD73BULA.mjs → chunk-IDCUZVJL.mjs} +1 -1
- package/dist/{chunk-DD73BULA.mjs.map → chunk-IDCUZVJL.mjs.map} +1 -1
- package/dist/{chunk-M7UI5ETO.mjs → chunk-JPUKH67K.mjs} +1 -1
- package/dist/{chunk-M7UI5ETO.mjs.map → chunk-JPUKH67K.mjs.map} +1 -1
- package/dist/{chunk-JFHM6EY2.mjs → chunk-K2BAFL2T.mjs} +1 -1
- package/dist/{chunk-JFHM6EY2.mjs.map → chunk-K2BAFL2T.mjs.map} +1 -1
- package/dist/chunk-KZ5JY7J3.mjs +18 -0
- package/dist/chunk-KZ5JY7J3.mjs.map +1 -0
- package/dist/chunk-LCP6FOCX.mjs +12 -0
- package/dist/chunk-LCP6FOCX.mjs.map +1 -0
- package/dist/{chunk-GOXQV6DX.mjs → chunk-MKETZ2RP.mjs} +2 -3
- package/dist/{chunk-GOXQV6DX.mjs.map → chunk-MKETZ2RP.mjs.map} +1 -1
- package/dist/{chunk-T2C2WVFL.mjs → chunk-MQWVBKUT.mjs} +1 -1
- package/dist/chunk-MQWVBKUT.mjs.map +1 -0
- package/dist/chunk-NP6PDX3E.mjs +1 -0
- package/dist/chunk-NP6PDX3E.mjs.map +1 -0
- package/dist/{chunk-JBDGK6X4.mjs → chunk-NRNKP6JF.mjs} +2 -2
- package/dist/{chunk-JBDGK6X4.mjs.map → chunk-NRNKP6JF.mjs.map} +1 -1
- package/dist/{chunk-CIRFWC7Y.mjs → chunk-RNJM5BHX.mjs} +2 -2
- package/dist/{chunk-FCF2RHPW.mjs → chunk-UMDNWTJC.mjs} +4 -4
- package/dist/{chunk-FCF2RHPW.mjs.map → chunk-UMDNWTJC.mjs.map} +1 -1
- package/dist/chunk-UNLX2F2Y.mjs +24 -0
- package/dist/chunk-UNLX2F2Y.mjs.map +1 -0
- package/dist/chunk-VP2LXY75.mjs +12 -0
- package/dist/chunk-VP2LXY75.mjs.map +1 -0
- package/dist/chunk-WPDDOUQT.mjs +16 -0
- package/dist/chunk-WPDDOUQT.mjs.map +1 -0
- package/dist/error/AbortError.d.mts +5 -0
- package/dist/error/AbortError.d.ts +5 -0
- package/dist/error/AbortError.js +36 -0
- package/dist/error/AbortError.js.map +1 -0
- package/dist/error/AbortError.mjs +8 -0
- package/dist/error/AbortError.mjs.map +1 -0
- package/dist/error/index.d.mts +1 -0
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +38 -0
- package/dist/error/index.js.map +1 -0
- package/dist/error/index.mjs +9 -0
- package/dist/error/index.mjs.map +1 -0
- package/dist/function/debounce.js +1 -2
- package/dist/function/debounce.js.map +1 -1
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.js +1 -2
- package/dist/function/index.js.map +1 -1
- package/dist/function/index.mjs +4 -4
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +108 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -43
- package/dist/math/index.d.mts +3 -0
- package/dist/math/index.d.ts +3 -0
- package/dist/math/index.js +42 -0
- package/dist/math/index.js.map +1 -1
- package/dist/math/index.mjs +14 -2
- package/dist/math/random.d.mts +16 -0
- package/dist/math/random.d.ts +16 -0
- package/dist/math/random.js +36 -0
- package/dist/math/random.js.map +1 -0
- package/dist/math/random.mjs +8 -0
- package/dist/math/random.mjs.map +1 -0
- package/dist/math/randomInt.d.mts +15 -0
- package/dist/math/randomInt.d.ts +15 -0
- package/dist/math/randomInt.js +43 -0
- package/dist/math/randomInt.js.map +1 -0
- package/dist/math/randomInt.mjs +9 -0
- package/dist/math/randomInt.mjs.map +1 -0
- package/dist/math/range.d.mts +32 -0
- package/dist/math/range.d.ts +32 -0
- package/dist/math/range.js +48 -0
- package/dist/math/range.js.map +1 -0
- package/dist/math/range.mjs +8 -0
- package/dist/math/range.mjs.map +1 -0
- package/dist/math/round.d.mts +2 -0
- package/dist/math/round.d.ts +2 -0
- package/dist/math/round.js +3 -0
- package/dist/math/round.js.map +1 -1
- package/dist/math/round.mjs +1 -1
- package/dist/object/index.js.map +1 -1
- package/dist/object/index.mjs +2 -2
- package/dist/object/omitBy.d.mts +2 -2
- package/dist/object/omitBy.d.ts +2 -2
- package/dist/object/omitBy.js.map +1 -1
- package/dist/object/omitBy.mjs +1 -1
- package/dist/object/pickBy.d.mts +2 -2
- package/dist/object/pickBy.d.ts +2 -2
- package/dist/object/pickBy.js.map +1 -1
- package/dist/object/pickBy.mjs +1 -1
- package/dist/predicate/index.mjs +3 -3
- package/dist/promise/delay.d.mts +18 -1
- package/dist/promise/delay.d.ts +18 -1
- package/dist/promise/delay.js +24 -3
- package/dist/promise/delay.js.map +1 -1
- package/dist/promise/delay.mjs +2 -1
- package/dist/promise/index.js +22 -3
- package/dist/promise/index.js.map +1 -1
- package/dist/promise/index.mjs +2 -1
- package/package.json +3 -1
- package/dist/chunk-ASFOKYTY.mjs +0 -13
- package/dist/chunk-ASFOKYTY.mjs.map +0 -1
- package/dist/chunk-EJGAXTF7.mjs +0 -1
- package/dist/chunk-IJLQVGW4.mjs +0 -1
- package/dist/chunk-SF3V7XXM.mjs.map +0 -1
- package/dist/chunk-T2C2WVFL.mjs.map +0 -1
- package/dist/chunk-V7E5DGZP.mjs.map +0 -1
- package/dist/chunk-ZBG3EYM3.mjs +0 -11
- package/dist/chunk-ZBG3EYM3.mjs.map +0 -1
- /package/dist/{chunk-EJGAXTF7.mjs.map → array/maxBy.mjs.map} +0 -0
- /package/dist/{chunk-IJLQVGW4.mjs.map → array/minBy.mjs.map} +0 -0
- /package/dist/{chunk-EW3RT4QW.mjs.map → chunk-AM2EGFCU.mjs.map} +0 -0
- /package/dist/{chunk-WXIBCOES.mjs.map → chunk-G2TTBLLJ.mjs.map} +0 -0
- /package/dist/{chunk-CIRFWC7Y.mjs.map → chunk-RNJM5BHX.mjs.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/math/round.d.mts
CHANGED
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
* @param {number} value - The number to round.
|
|
8
8
|
* @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.
|
|
9
9
|
* @returns {number} The rounded number.
|
|
10
|
+
* @throws {Error} Throws an error if `Precision` is not integer.
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
12
13
|
* const result1 = round(1.2345); // result1 will be 1
|
|
13
14
|
* const result2 = round(1.2345, 2); // result2 will be 1.23
|
|
14
15
|
* const result3 = round(1.2345, 3); // result3 will be 1.235
|
|
16
|
+
* const result4 = round(1.2345, 3.1); // This will throw an error
|
|
15
17
|
*/
|
|
16
18
|
declare function round(value: number, precision?: number): number;
|
|
17
19
|
|
package/dist/math/round.d.ts
CHANGED
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
* @param {number} value - The number to round.
|
|
8
8
|
* @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.
|
|
9
9
|
* @returns {number} The rounded number.
|
|
10
|
+
* @throws {Error} Throws an error if `Precision` is not integer.
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
12
13
|
* const result1 = round(1.2345); // result1 will be 1
|
|
13
14
|
* const result2 = round(1.2345, 2); // result2 will be 1.23
|
|
14
15
|
* const result3 = round(1.2345, 3); // result3 will be 1.235
|
|
16
|
+
* const result4 = round(1.2345, 3.1); // This will throw an error
|
|
15
17
|
*/
|
|
16
18
|
declare function round(value: number, precision?: number): number;
|
|
17
19
|
|
package/dist/math/round.js
CHANGED
|
@@ -24,6 +24,9 @@ __export(round_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(round_exports);
|
|
26
26
|
function round(value, precision = 0) {
|
|
27
|
+
if (!Number.isInteger(precision)) {
|
|
28
|
+
throw new Error("Precision must be an integer.");
|
|
29
|
+
}
|
|
27
30
|
const multiplier = Math.pow(10, precision);
|
|
28
31
|
return Math.round(value * multiplier) / multiplier;
|
|
29
32
|
}
|
package/dist/math/round.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/round.ts"],"sourcesContent":["/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n */\nexport function round(value: number, precision
|
|
1
|
+
{"version":3,"sources":["../../src/math/round.ts"],"sourcesContent":["/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n * @throws {Error} Throws an error if `Precision` is not integer.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n * const result4 = round(1.2345, 3.1); // This will throw an error\n */\nexport function round(value: number, precision = 0): number {\n if (!Number.isInteger(precision)) {\n throw new Error('Precision must be an integer.');\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,SAAS,MAAM,OAAe,YAAY,GAAW;AAC1D,MAAI,CAAC,OAAO,UAAU,SAAS,GAAG;AAChC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACA,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;","names":[]}
|
package/dist/math/round.mjs
CHANGED
package/dist/object/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts"],"sourcesContent":["export { omit } from './omit';\nexport { omitBy } from './omitBy';\nexport { pick } from './pick';\nexport { pickBy } from './pickBy';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key:
|
|
1
|
+
{"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts"],"sourcesContent":["export { omit } from './omit';\nexport { omitBy } from './omitBy';\nexport { pick } from './pick';\nexport { pickBy } from './pickBy';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACLO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;AClBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,MAAM;AACtB,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACLO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
|
package/dist/object/index.mjs
CHANGED
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
} from "../chunk-PLTO44KM.mjs";
|
|
5
5
|
import {
|
|
6
6
|
omitBy
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-A67NF2C7.mjs";
|
|
8
8
|
import {
|
|
9
9
|
pick
|
|
10
10
|
} from "../chunk-OFWKFUFZ.mjs";
|
|
11
11
|
import {
|
|
12
12
|
pickBy
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-MQWVBKUT.mjs";
|
|
14
14
|
import "../chunk-2MM5EJJX.mjs";
|
|
15
15
|
export {
|
|
16
16
|
omit,
|
package/dist/object/omitBy.d.mts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* includes only the properties for which the predicate function returns false.
|
|
6
6
|
*
|
|
7
7
|
* @param {T} obj - The object to omit properties from.
|
|
8
|
-
* @param {(value: T[string], key:
|
|
8
|
+
* @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines
|
|
9
9
|
* whether a property should be omitted. It takes the property's key and value as arguments and returns `true`
|
|
10
10
|
* if the property should be omitted, and `false` otherwise.
|
|
11
11
|
* @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
* const result = omitBy(obj, shouldOmit);
|
|
17
17
|
* // result will be { a: 1, c: 3 }
|
|
18
18
|
*/
|
|
19
|
-
declare function omitBy<T extends Record<string, any>>(obj: T, shouldOmit: (value: T[keyof T], key:
|
|
19
|
+
declare function omitBy<T extends Record<string, any>>(obj: T, shouldOmit: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
|
|
20
20
|
|
|
21
21
|
export { omitBy };
|
package/dist/object/omitBy.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* includes only the properties for which the predicate function returns false.
|
|
6
6
|
*
|
|
7
7
|
* @param {T} obj - The object to omit properties from.
|
|
8
|
-
* @param {(value: T[string], key:
|
|
8
|
+
* @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines
|
|
9
9
|
* whether a property should be omitted. It takes the property's key and value as arguments and returns `true`
|
|
10
10
|
* if the property should be omitted, and `false` otherwise.
|
|
11
11
|
* @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
* const result = omitBy(obj, shouldOmit);
|
|
17
17
|
* // result will be { a: 1, c: 3 }
|
|
18
18
|
*/
|
|
19
|
-
declare function omitBy<T extends Record<string, any>>(obj: T, shouldOmit: (value: T[keyof T], key:
|
|
19
|
+
declare function omitBy<T extends Record<string, any>>(obj: T, shouldOmit: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
|
|
20
20
|
|
|
21
21
|
export { omitBy };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/object/omitBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key:
|
|
1
|
+
{"version":3,"sources":["../../src/object/omitBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
|
package/dist/object/omitBy.mjs
CHANGED
package/dist/object/pickBy.d.mts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* includes only the properties for which the predicate function returns true.
|
|
6
6
|
*
|
|
7
7
|
* @param {T} obj - The object to pick properties from.
|
|
8
|
-
* @param {(value: T[keyof T], key:
|
|
8
|
+
* @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines
|
|
9
9
|
* whether a property should be picked. It takes the property's key and value as arguments and returns `true`
|
|
10
10
|
* if the property should be picked, and `false` otherwise.
|
|
11
11
|
* @returns {Partial<T>} A new object with the properties that satisfy the predicate function.
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
* const result = pickBy(obj, shouldPick);
|
|
17
17
|
* // result will be { b: 'pick' }
|
|
18
18
|
*/
|
|
19
|
-
declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick: (value: T[keyof T], key:
|
|
19
|
+
declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
|
|
20
20
|
|
|
21
21
|
export { pickBy };
|
package/dist/object/pickBy.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* includes only the properties for which the predicate function returns true.
|
|
6
6
|
*
|
|
7
7
|
* @param {T} obj - The object to pick properties from.
|
|
8
|
-
* @param {(value: T[keyof T], key:
|
|
8
|
+
* @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines
|
|
9
9
|
* whether a property should be picked. It takes the property's key and value as arguments and returns `true`
|
|
10
10
|
* if the property should be picked, and `false` otherwise.
|
|
11
11
|
* @returns {Partial<T>} A new object with the properties that satisfy the predicate function.
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
* const result = pickBy(obj, shouldPick);
|
|
17
17
|
* // result will be { b: 'pick' }
|
|
18
18
|
*/
|
|
19
|
-
declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick: (value: T[keyof T], key:
|
|
19
|
+
declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
|
|
20
20
|
|
|
21
21
|
export { pickBy };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/object/pickBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key:
|
|
1
|
+
{"version":3,"sources":["../../src/object/pickBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
|
package/dist/object/pickBy.mjs
CHANGED
package/dist/predicate/index.mjs
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import "../chunk-MAJSPFA6.mjs";
|
|
2
|
-
import {
|
|
3
|
-
isNotNil
|
|
4
|
-
} from "../chunk-ZQNAZPSK.mjs";
|
|
5
2
|
import {
|
|
6
3
|
isNull
|
|
7
4
|
} from "../chunk-AIRSKN47.mjs";
|
|
@@ -11,6 +8,9 @@ import {
|
|
|
11
8
|
import {
|
|
12
9
|
isNil
|
|
13
10
|
} from "../chunk-OHQAR5AU.mjs";
|
|
11
|
+
import {
|
|
12
|
+
isNotNil
|
|
13
|
+
} from "../chunk-ZQNAZPSK.mjs";
|
|
14
14
|
import "../chunk-2MM5EJJX.mjs";
|
|
15
15
|
export {
|
|
16
16
|
isNil,
|
package/dist/promise/delay.d.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
interface DelayOptions {
|
|
2
|
+
signal?: AbortSignal;
|
|
3
|
+
}
|
|
1
4
|
/**
|
|
2
5
|
* Delays the execution of code for a specified number of milliseconds.
|
|
3
6
|
*
|
|
@@ -5,6 +8,8 @@
|
|
|
5
8
|
* with async/await to pause execution.
|
|
6
9
|
*
|
|
7
10
|
* @param {number} ms - The number of milliseconds to delay.
|
|
11
|
+
* @param {DelayOptions} options - The options object.
|
|
12
|
+
* @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.
|
|
8
13
|
* @returns {Promise<void>} A Promise that resolves after the specified delay.
|
|
9
14
|
*
|
|
10
15
|
* @example
|
|
@@ -15,7 +20,19 @@
|
|
|
15
20
|
* }
|
|
16
21
|
*
|
|
17
22
|
* foo();
|
|
23
|
+
*
|
|
24
|
+
* // With AbortSignal
|
|
25
|
+
* const controller = new AbortController();
|
|
26
|
+
* const { signal } = controller;
|
|
27
|
+
*
|
|
28
|
+
* setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms
|
|
29
|
+
* try {
|
|
30
|
+
* await delay(100, { signal });
|
|
31
|
+
* } catch (error) {
|
|
32
|
+
* console.error(error); // Will log 'AbortError'
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
18
35
|
*/
|
|
19
|
-
declare function delay(ms: number): Promise<void>;
|
|
36
|
+
declare function delay(ms: number, { signal }?: DelayOptions): Promise<void>;
|
|
20
37
|
|
|
21
38
|
export { delay };
|
package/dist/promise/delay.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
interface DelayOptions {
|
|
2
|
+
signal?: AbortSignal;
|
|
3
|
+
}
|
|
1
4
|
/**
|
|
2
5
|
* Delays the execution of code for a specified number of milliseconds.
|
|
3
6
|
*
|
|
@@ -5,6 +8,8 @@
|
|
|
5
8
|
* with async/await to pause execution.
|
|
6
9
|
*
|
|
7
10
|
* @param {number} ms - The number of milliseconds to delay.
|
|
11
|
+
* @param {DelayOptions} options - The options object.
|
|
12
|
+
* @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.
|
|
8
13
|
* @returns {Promise<void>} A Promise that resolves after the specified delay.
|
|
9
14
|
*
|
|
10
15
|
* @example
|
|
@@ -15,7 +20,19 @@
|
|
|
15
20
|
* }
|
|
16
21
|
*
|
|
17
22
|
* foo();
|
|
23
|
+
*
|
|
24
|
+
* // With AbortSignal
|
|
25
|
+
* const controller = new AbortController();
|
|
26
|
+
* const { signal } = controller;
|
|
27
|
+
*
|
|
28
|
+
* setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms
|
|
29
|
+
* try {
|
|
30
|
+
* await delay(100, { signal });
|
|
31
|
+
* } catch (error) {
|
|
32
|
+
* console.error(error); // Will log 'AbortError'
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
18
35
|
*/
|
|
19
|
-
declare function delay(ms: number): Promise<void>;
|
|
36
|
+
declare function delay(ms: number, { signal }?: DelayOptions): Promise<void>;
|
|
20
37
|
|
|
21
38
|
export { delay };
|
package/dist/promise/delay.js
CHANGED
|
@@ -23,9 +23,30 @@ __export(delay_exports, {
|
|
|
23
23
|
delay: () => delay
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(delay_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
|
|
27
|
+
// src/error/AbortError.ts
|
|
28
|
+
var AbortError = class extends Error {
|
|
29
|
+
constructor(message = "The operation was aborted") {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "AbortError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/promise/delay.ts
|
|
36
|
+
function delay(ms, { signal } = {}) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const abortError = () => {
|
|
39
|
+
reject(new AbortError());
|
|
40
|
+
};
|
|
41
|
+
const abortHandler = () => {
|
|
42
|
+
clearTimeout(timeoutId);
|
|
43
|
+
abortError();
|
|
44
|
+
};
|
|
45
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
46
|
+
return abortError();
|
|
47
|
+
}
|
|
48
|
+
const timeoutId = setTimeout(resolve, ms);
|
|
49
|
+
signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
|
|
29
50
|
});
|
|
30
51
|
}
|
|
31
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/promise/delay.ts"],"sourcesContent":["/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../src/promise/delay.ts","../../src/error/AbortError.ts"],"sourcesContent":["import { AbortError } from '../error/AbortError';\n\ninterface DelayOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @param {DelayOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const { signal } = controller;\n *\n * setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms\n * try {\n * await delay(100, { signal });\n * } catch (error) {\n * console.error(error); // Will log 'AbortError'\n * }\n * }\n */\nexport function delay(ms: number, { signal }: DelayOptions = {}): Promise<void> {\n return new Promise((resolve, reject) => {\n const abortError = () => {\n reject(new AbortError());\n };\n\n const abortHandler = () => {\n clearTimeout(timeoutId);\n abortError();\n };\n\n if (signal?.aborted) {\n return abortError();\n }\n\n const timeoutId = setTimeout(resolve, ms);\n\n signal?.addEventListener('abort', abortHandler, { once: true });\n });\n}\n","export class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ADiCO,SAAS,MAAM,IAAY,EAAE,OAAO,IAAkB,CAAC,GAAkB;AAC9E,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,aAAa,MAAM;AACvB,aAAO,IAAI,WAAW,CAAC;AAAA,IACzB;AAEA,UAAM,eAAe,MAAM;AACzB,mBAAa,SAAS;AACtB,iBAAW;AAAA,IACb;AAEA,QAAI,iCAAQ,SAAS;AACnB,aAAO,WAAW;AAAA,IACpB;AAEA,UAAM,YAAY,WAAW,SAAS,EAAE;AAExC,qCAAQ,iBAAiB,SAAS,cAAc,EAAE,MAAM,KAAK;AAAA,EAC/D,CAAC;AACH;","names":[]}
|
package/dist/promise/delay.mjs
CHANGED
package/dist/promise/index.js
CHANGED
|
@@ -24,10 +24,29 @@ __export(promise_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(promise_exports);
|
|
26
26
|
|
|
27
|
+
// src/error/AbortError.ts
|
|
28
|
+
var AbortError = class extends Error {
|
|
29
|
+
constructor(message = "The operation was aborted") {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "AbortError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
27
35
|
// src/promise/delay.ts
|
|
28
|
-
function delay(ms) {
|
|
29
|
-
return new Promise((resolve) => {
|
|
30
|
-
|
|
36
|
+
function delay(ms, { signal } = {}) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const abortError = () => {
|
|
39
|
+
reject(new AbortError());
|
|
40
|
+
};
|
|
41
|
+
const abortHandler = () => {
|
|
42
|
+
clearTimeout(timeoutId);
|
|
43
|
+
abortError();
|
|
44
|
+
};
|
|
45
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
46
|
+
return abortError();
|
|
47
|
+
}
|
|
48
|
+
const timeoutId = setTimeout(resolve, ms);
|
|
49
|
+
signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
|
|
31
50
|
});
|
|
32
51
|
}
|
|
33
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/promise/index.ts","../../src/promise/delay.ts"],"sourcesContent":["export { delay } from './delay';\n","/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;
|
|
1
|
+
{"version":3,"sources":["../../src/promise/index.ts","../../src/error/AbortError.ts","../../src/promise/delay.ts"],"sourcesContent":["export { delay } from './delay';\n","export class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n","import { AbortError } from '../error/AbortError';\n\ninterface DelayOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @param {DelayOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const { signal } = controller;\n *\n * setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms\n * try {\n * await delay(100, { signal });\n * } catch (error) {\n * console.error(error); // Will log 'AbortError'\n * }\n * }\n */\nexport function delay(ms: number, { signal }: DelayOptions = {}): Promise<void> {\n return new Promise((resolve, reject) => {\n const abortError = () => {\n reject(new AbortError());\n };\n\n const abortHandler = () => {\n clearTimeout(timeoutId);\n abortError();\n };\n\n if (signal?.aborted) {\n return abortError();\n }\n\n const timeoutId = setTimeout(resolve, ms);\n\n signal?.addEventListener('abort', abortHandler, { once: true });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACiCO,SAAS,MAAM,IAAY,EAAE,OAAO,IAAkB,CAAC,GAAkB;AAC9E,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,aAAa,MAAM;AACvB,aAAO,IAAI,WAAW,CAAC;AAAA,IACzB;AAEA,UAAM,eAAe,MAAM;AACzB,mBAAa,SAAS;AACtB,iBAAW;AAAA,IACb;AAEA,QAAI,iCAAQ,SAAS;AACnB,aAAO,WAAW;AAAA,IACpB;AAEA,UAAM,YAAY,WAAW,SAAS,EAAE;AAExC,qCAAQ,iBAAiB,SAAS,cAAc,EAAE,MAAM,KAAK;AAAA,EAC/D,CAAC;AACH;","names":[]}
|
package/dist/promise/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.4.0-dev.101+ed145c50",
|
|
5
5
|
"workspaces": [
|
|
6
6
|
"docs"
|
|
7
7
|
],
|
|
@@ -168,6 +168,7 @@
|
|
|
168
168
|
"@babel/preset-typescript": "^7.24.1",
|
|
169
169
|
"@changesets/changelog-github": "^0.5.0",
|
|
170
170
|
"@changesets/cli": "^2.27.1",
|
|
171
|
+
"@codspeed/vitest-plugin": "^3.1.0",
|
|
171
172
|
"@types/babel__core": "^7",
|
|
172
173
|
"@types/babel__preset-env": "^7",
|
|
173
174
|
"@types/broken-link-checker": "^0",
|
|
@@ -190,6 +191,7 @@
|
|
|
190
191
|
"prepack": "yarn build",
|
|
191
192
|
"build": "tsup && ./.scripts/postbuild.sh",
|
|
192
193
|
"test": "vitest run --coverage --typecheck",
|
|
194
|
+
"bench": "vitest bench",
|
|
193
195
|
"lint": "eslint ./src --ext .ts",
|
|
194
196
|
"format": "prettier --write ."
|
|
195
197
|
},
|
package/dist/chunk-ASFOKYTY.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
uniqWith
|
|
3
|
-
} from "./chunk-2PFDLYQC.mjs";
|
|
4
|
-
|
|
5
|
-
// src/array/uniqBy.ts
|
|
6
|
-
function uniqBy(arr, mapper) {
|
|
7
|
-
return uniqWith(arr, (item1, item2) => mapper(item1) === mapper(item2));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
uniqBy
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=chunk-ASFOKYTY.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/array/uniqBy.ts"],"sourcesContent":["import { uniqWith } from './uniqWith';\n\n/**\n * Returns a new array containing only the unique elements from the original array,\n * based on the values returned by the mapper function.\n *\n * @param {T[]} arr - The array to process.\n * @param {(item: T) => U} mapper - The function used to convert the array elements.\n * @returns {T[]} A new array containing only the unique elements from the original array, based on the values returned by the mapper function.\n *\n * @example\n * ```ts\n * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);\n * // [1.2, 2.1, 3.3, 5.7, 7.19]\n * ```\n */\nexport function uniqBy<T, U>(arr: readonly T[], mapper: (item: T) => U): T[] {\n return uniqWith(arr, (item1, item2) => mapper(item1) === mapper(item2));\n}\n"],"mappings":";;;;;AAgBO,SAAS,OAAa,KAAmB,QAA6B;AAC3E,SAAO,SAAS,KAAK,CAAC,OAAO,UAAU,OAAO,KAAK,MAAM,OAAO,KAAK,CAAC;AACxE;","names":[]}
|
package/dist/chunk-EJGAXTF7.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-EJGAXTF7.mjs.map
|
package/dist/chunk-IJLQVGW4.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-IJLQVGW4.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/object/omitBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: string) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: string) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";AAkBO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/object/pickBy.ts"],"sourcesContent":["/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: string) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: string) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";AAkBO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/math/round.ts"],"sourcesContent":["/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n */\nexport function round(value: number, precision: number = 0): number {\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":";AAeO,SAAS,MAAM,OAAe,YAAoB,GAAW;AAClE,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;","names":[]}
|
package/dist/chunk-ZBG3EYM3.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/promise/delay.ts"],"sourcesContent":["/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";AAkBO,SAAS,MAAM,IAA2B;AAC/C,SAAO,IAAI,QAAQ,aAAW;AAC5B,eAAW,SAAS,EAAE;AAAA,EACxB,CAAC;AACH;","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|