es-toolkit 1.3.1 → 1.4.0-dev.100
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.js +9 -2
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +13 -13
- package/dist/array/intersectionWith.js.map +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- 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-6E6PBLFK.mjs +18 -0
- package/dist/chunk-6E6PBLFK.mjs.map +1 -0
- 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-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-WXIBCOES.mjs → chunk-G2TTBLLJ.mjs} +2 -2
- 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-JQUZTDPN.mjs +24 -0
- package/dist/chunk-JQUZTDPN.mjs.map +1 -0
- 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-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-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-SAL5OUAE.mjs +18 -0
- package/dist/chunk-SAL5OUAE.mjs.map +1 -0
- package/dist/chunk-TZE6EDCX.mjs +1 -0
- package/dist/chunk-TZE6EDCX.mjs.map +1 -0
- 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-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 +52 -27
- package/dist/math/index.d.mts +5 -0
- package/dist/math/index.d.ts +5 -0
- package/dist/math/index.js +74 -0
- package/dist/math/index.js.map +1 -1
- package/dist/math/index.mjs +24 -4
- package/dist/math/maxBy.d.mts +21 -0
- package/dist/math/maxBy.d.ts +21 -0
- package/dist/math/maxBy.js +42 -0
- package/dist/math/maxBy.js.map +1 -0
- package/dist/math/maxBy.mjs +8 -0
- package/dist/math/maxBy.mjs.map +1 -0
- package/dist/math/minBy.d.mts +13 -0
- package/dist/math/minBy.d.ts +13 -0
- package/dist/math/minBy.js +42 -0
- package/dist/math/minBy.js.map +1 -0
- package/dist/math/minBy.mjs +8 -0
- package/dist/math/minBy.mjs.map +1 -0
- 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-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-EW3RT4QW.mjs.map → chunk-AM2EGFCU.mjs.map} +0 -0
- /package/dist/{chunk-IJLQVGW4.mjs.map → chunk-FZEZH22H.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
package/dist/math/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/round.ts","../../src/math/sum.ts"],"sourcesContent":["export { clamp } from './clamp';\nexport { round } from './round';\nexport { sum } from './sum';\n","/**\n * Clamps a number within the inclusive lower and upper bounds.\n *\n * This function takes a number and two bounds, and returns the number clamped within the specified bounds.\n * If only one bound is provided, it returns the minimum of the value and the bound.\n *\n * @param {number} value - The number to clamp.\n * @param {number} minimum - The minimum bound to clamp the number.\n * @param {number} maximum - The maximum bound to clamp the number.\n * @returns {number} The clamped number within the specified bounds.\n *\n * @example\n * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5\n * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15\n * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5\n * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15\n */\nexport function clamp(value: number, maximum: number): number;\nexport function clamp(value: number, minimum: number, maximum: number): number;\nexport function clamp(value: number, bound1: number, bound2?: number): number {\n if (bound2 == null) {\n return Math.min(value, bound1);\n }\n\n return Math.min(Math.max(value, bound1), bound2);\n}\n","/**\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/index.ts","../../src/math/clamp.ts","../../src/math/random.ts","../../src/math/randomInt.ts","../../src/math/round.ts","../../src/math/sum.ts","../../src/math/maxBy.ts","../../src/math/minBy.ts","../../src/math/range.ts"],"sourcesContent":["export { clamp } from './clamp';\nexport { random } from './random';\nexport { randomInt } from './randomInt';\nexport { round } from './round';\nexport { sum } from './sum';\nexport { maxBy } from './maxBy';\nexport { minBy } from './minBy';\nexport { range } from './range';\n","/**\n * Clamps a number within the inclusive lower and upper bounds.\n *\n * This function takes a number and two bounds, and returns the number clamped within the specified bounds.\n * If only one bound is provided, it returns the minimum of the value and the bound.\n *\n * @param {number} value - The number to clamp.\n * @param {number} minimum - The minimum bound to clamp the number.\n * @param {number} maximum - The maximum bound to clamp the number.\n * @returns {number} The clamped number within the specified bounds.\n *\n * @example\n * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5\n * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15\n * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5\n * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15\n */\nexport function clamp(value: number, maximum: number): number;\nexport function clamp(value: number, minimum: number, maximum: number): number;\nexport function clamp(value: number, bound1: number, bound2?: number): number {\n if (bound2 == null) {\n return Math.min(value, bound1);\n }\n\n return Math.min(Math.max(value, bound1), bound2);\n}\n","/**\n * Generate a random number within the given range.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(minimum: number, maximum: number): number {\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n","import { random } from './random';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(minimum: number, maximum: number): number {\n return Math.floor(random(minimum, maximum));\n}\n","/**\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","/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: number[]): number {\n let result = 0;\n\n for (const num of nums) {\n result += num;\n }\n\n return result;\n}\n","/**\n * Returns the element of the specified array that has the maximum value, according to the specified selector.\n *\n * This function takes an array of elements and a selector function, and returns the element with the maximum value according to the selector.\n *\n * @param {T[]} elements - An array of elements to be compared.\n * @param {(element: T) => number} selector - A function that takes an element and returns a number.\n * @returns {T} The element with the maximum value according to the selector.\n *\n * @example\n * const people = [\n * { name: 'Mark', age: 25 },\n * { name: 'Nunu', age: 30 },\n * { name: 'Overmars', age: 20 }\n * ];\n * const result = maxBy(people, person => person.age);\n * // result will be { name: 'Nunu', age: 30 }\n */\nexport function maxBy<T>(elements: T[], selector: (element: T) => number): T {\n let maxElement = elements[0];\n let max = -Infinity;\n\n for (const element of elements) {\n const value = selector(element);\n if (value > max) {\n max = value;\n maxElement = element;\n }\n }\n\n return maxElement;\n}\n","/**\n * Returns the minimum value in an array of numbers.\n *\n * This function takes an array of elements and a selector function, and returns the element with the minimum value according to the selector.\n *\n * If the array is empty, the function returns `undefined`.\n *\n * @param elements An array of elements.\n * @param selector A function that selects a number from an element.\n */\nexport function minBy<T>(elements: T[], selector: (element: T) => number): T {\n let minElement = elements[0];\n let min = Infinity;\n\n for (const element of elements) {\n const value = selector(element);\n if (value < min) {\n min = value;\n minElement = element;\n }\n }\n\n return minElement;\n}\n","/**\n * Returns an array of numbers from `start` to `end`, incrementing by `step`.\n *\n * If `step` is not provided, it defaults to `1` for an\n * ascending range and `-1` for a descending range.\n *\n * @param {number} start - The starting number of the range.\n * @param {number} [end] - The end number of the range.\n * @param {number} [step] - The step value for the range.\n * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.\n *\n * @example\n * // Returns [0, 1, 2, 3]\n * range(4);\n *\n * @example\n * // Returns [0, 5, 10, 15]\n * range(0, 20, 5);\n *\n * @example\n * // Returns []\n * range(0, -4, -1);\n *\n * @example\n * // Throws an error: The step value must be a non-zero integer.\n * range(1, 4, 0);\n */\nexport function range(end: number): number[];\nexport function range(start: number, end: number): number[];\nexport function range(start: number, end: number, step: number): number[];\nexport function range(start: number, end?: number, step?: number): number[] {\n if (end == null) {\n end = start;\n start = 0;\n }\n\n if (step == null) {\n step = 1;\n }\n\n if (!Number.isInteger(step) || step === 0) {\n throw new Error(`The step value must be a non-zero integer.`);\n }\n\n const length = Math.max(Math.ceil((end - start) / (step || 1)), 0);\n const result = new Array(length);\n\n for (let i = 0; i < length; i++) {\n result[i] = start + i * step;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBO,SAAS,MAAM,OAAe,QAAgB,QAAyB;AAC5E,MAAI,UAAU,MAAM;AAClB,WAAO,KAAK,IAAI,OAAO,MAAM;AAAA,EAC/B;AAEA,SAAO,KAAK,IAAI,KAAK,IAAI,OAAO,MAAM,GAAG,MAAM;AACjD;;;ACZO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ACLO,SAAS,UAAU,SAAiB,SAAyB;AAClE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAO,CAAC;AAC5C;;;ACCO,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;;;ACVO,SAAS,IAAI,MAAwB;AAC1C,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,cAAU;AAAA,EACZ;AAEA,SAAO;AACT;;;ACHO,SAAS,MAAS,UAAe,UAAqC;AAC3E,MAAI,aAAa,SAAS,CAAC;AAC3B,MAAI,MAAM;AAEV,aAAW,WAAW,UAAU;AAC9B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;;;ACrBO,SAAS,MAAS,UAAe,UAAqC;AAC3E,MAAI,aAAa,SAAS,CAAC;AAC3B,MAAI,MAAM;AAEV,aAAW,WAAW,UAAU;AAC9B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;;;ACOO,SAAS,MAAM,OAAe,KAAc,MAAyB;AAC1E,MAAI,OAAO,MAAM;AACf,UAAM;AACN,YAAQ;AAAA,EACV;AAEA,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,SAAS,GAAG;AACzC,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AAEA,QAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,UAAU,QAAQ,EAAE,GAAG,CAAC;AACjE,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,WAAO,CAAC,IAAI,QAAQ,IAAI;AAAA,EAC1B;AAEA,SAAO;AACT;","names":[]}
|
package/dist/math/index.mjs
CHANGED
|
@@ -1,16 +1,36 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-TZE6EDCX.mjs";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from "../chunk-
|
|
3
|
+
maxBy
|
|
4
|
+
} from "../chunk-6E6PBLFK.mjs";
|
|
5
|
+
import {
|
|
6
|
+
minBy
|
|
7
|
+
} from "../chunk-SAL5OUAE.mjs";
|
|
8
|
+
import {
|
|
9
|
+
randomInt
|
|
10
|
+
} from "../chunk-5UT77WON.mjs";
|
|
11
|
+
import {
|
|
12
|
+
random
|
|
13
|
+
} from "../chunk-LCP6FOCX.mjs";
|
|
14
|
+
import {
|
|
15
|
+
range
|
|
16
|
+
} from "../chunk-JQUZTDPN.mjs";
|
|
5
17
|
import {
|
|
6
18
|
round
|
|
7
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-5PMKOZ2F.mjs";
|
|
8
20
|
import {
|
|
9
21
|
sum
|
|
10
22
|
} from "../chunk-7OU22ENP.mjs";
|
|
23
|
+
import {
|
|
24
|
+
clamp
|
|
25
|
+
} from "../chunk-MLCL773E.mjs";
|
|
11
26
|
import "../chunk-2MM5EJJX.mjs";
|
|
12
27
|
export {
|
|
13
28
|
clamp,
|
|
29
|
+
maxBy,
|
|
30
|
+
minBy,
|
|
31
|
+
random,
|
|
32
|
+
randomInt,
|
|
33
|
+
range,
|
|
14
34
|
round,
|
|
15
35
|
sum
|
|
16
36
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the element of the specified array that has the maximum value, according to the specified selector.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array of elements and a selector function, and returns the element with the maximum value according to the selector.
|
|
5
|
+
*
|
|
6
|
+
* @param {T[]} elements - An array of elements to be compared.
|
|
7
|
+
* @param {(element: T) => number} selector - A function that takes an element and returns a number.
|
|
8
|
+
* @returns {T} The element with the maximum value according to the selector.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const people = [
|
|
12
|
+
* { name: 'Mark', age: 25 },
|
|
13
|
+
* { name: 'Nunu', age: 30 },
|
|
14
|
+
* { name: 'Overmars', age: 20 }
|
|
15
|
+
* ];
|
|
16
|
+
* const result = maxBy(people, person => person.age);
|
|
17
|
+
* // result will be { name: 'Nunu', age: 30 }
|
|
18
|
+
*/
|
|
19
|
+
declare function maxBy<T>(elements: T[], selector: (element: T) => number): T;
|
|
20
|
+
|
|
21
|
+
export { maxBy };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the element of the specified array that has the maximum value, according to the specified selector.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array of elements and a selector function, and returns the element with the maximum value according to the selector.
|
|
5
|
+
*
|
|
6
|
+
* @param {T[]} elements - An array of elements to be compared.
|
|
7
|
+
* @param {(element: T) => number} selector - A function that takes an element and returns a number.
|
|
8
|
+
* @returns {T} The element with the maximum value according to the selector.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const people = [
|
|
12
|
+
* { name: 'Mark', age: 25 },
|
|
13
|
+
* { name: 'Nunu', age: 30 },
|
|
14
|
+
* { name: 'Overmars', age: 20 }
|
|
15
|
+
* ];
|
|
16
|
+
* const result = maxBy(people, person => person.age);
|
|
17
|
+
* // result will be { name: 'Nunu', age: 30 }
|
|
18
|
+
*/
|
|
19
|
+
declare function maxBy<T>(elements: T[], selector: (element: T) => number): T;
|
|
20
|
+
|
|
21
|
+
export { maxBy };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/math/maxBy.ts
|
|
21
|
+
var maxBy_exports = {};
|
|
22
|
+
__export(maxBy_exports, {
|
|
23
|
+
maxBy: () => maxBy
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(maxBy_exports);
|
|
26
|
+
function maxBy(elements, selector) {
|
|
27
|
+
let maxElement = elements[0];
|
|
28
|
+
let max = -Infinity;
|
|
29
|
+
for (const element of elements) {
|
|
30
|
+
const value = selector(element);
|
|
31
|
+
if (value > max) {
|
|
32
|
+
max = value;
|
|
33
|
+
maxElement = element;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return maxElement;
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
maxBy
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=maxBy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/math/maxBy.ts"],"sourcesContent":["/**\n * Returns the element of the specified array that has the maximum value, according to the specified selector.\n *\n * This function takes an array of elements and a selector function, and returns the element with the maximum value according to the selector.\n *\n * @param {T[]} elements - An array of elements to be compared.\n * @param {(element: T) => number} selector - A function that takes an element and returns a number.\n * @returns {T} The element with the maximum value according to the selector.\n *\n * @example\n * const people = [\n * { name: 'Mark', age: 25 },\n * { name: 'Nunu', age: 30 },\n * { name: 'Overmars', age: 20 }\n * ];\n * const result = maxBy(people, person => person.age);\n * // result will be { name: 'Nunu', age: 30 }\n */\nexport function maxBy<T>(elements: T[], selector: (element: T) => number): T {\n let maxElement = elements[0];\n let max = -Infinity;\n\n for (const element of elements) {\n const value = selector(element);\n if (value > max) {\n max = value;\n maxElement = element;\n }\n }\n\n return maxElement;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,MAAS,UAAe,UAAqC;AAC3E,MAAI,aAAa,SAAS,CAAC;AAC3B,MAAI,MAAM;AAEV,aAAW,WAAW,UAAU;AAC9B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the minimum value in an array of numbers.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array of elements and a selector function, and returns the element with the minimum value according to the selector.
|
|
5
|
+
*
|
|
6
|
+
* If the array is empty, the function returns `undefined`.
|
|
7
|
+
*
|
|
8
|
+
* @param elements An array of elements.
|
|
9
|
+
* @param selector A function that selects a number from an element.
|
|
10
|
+
*/
|
|
11
|
+
declare function minBy<T>(elements: T[], selector: (element: T) => number): T;
|
|
12
|
+
|
|
13
|
+
export { minBy };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the minimum value in an array of numbers.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array of elements and a selector function, and returns the element with the minimum value according to the selector.
|
|
5
|
+
*
|
|
6
|
+
* If the array is empty, the function returns `undefined`.
|
|
7
|
+
*
|
|
8
|
+
* @param elements An array of elements.
|
|
9
|
+
* @param selector A function that selects a number from an element.
|
|
10
|
+
*/
|
|
11
|
+
declare function minBy<T>(elements: T[], selector: (element: T) => number): T;
|
|
12
|
+
|
|
13
|
+
export { minBy };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/math/minBy.ts
|
|
21
|
+
var minBy_exports = {};
|
|
22
|
+
__export(minBy_exports, {
|
|
23
|
+
minBy: () => minBy
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(minBy_exports);
|
|
26
|
+
function minBy(elements, selector) {
|
|
27
|
+
let minElement = elements[0];
|
|
28
|
+
let min = Infinity;
|
|
29
|
+
for (const element of elements) {
|
|
30
|
+
const value = selector(element);
|
|
31
|
+
if (value < min) {
|
|
32
|
+
min = value;
|
|
33
|
+
minElement = element;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return minElement;
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
minBy
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=minBy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/math/minBy.ts"],"sourcesContent":["/**\n * Returns the minimum value in an array of numbers.\n *\n * This function takes an array of elements and a selector function, and returns the element with the minimum value according to the selector.\n *\n * If the array is empty, the function returns `undefined`.\n *\n * @param elements An array of elements.\n * @param selector A function that selects a number from an element.\n */\nexport function minBy<T>(elements: T[], selector: (element: T) => number): T {\n let minElement = elements[0];\n let min = Infinity;\n\n for (const element of elements) {\n const value = selector(element);\n if (value < min) {\n min = value;\n minElement = element;\n }\n }\n\n return minElement;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,SAAS,MAAS,UAAe,UAAqC;AAC3E,MAAI,aAAa,SAAS,CAAC;AAC3B,MAAI,MAAM;AAEV,aAAW,WAAW,UAAU;AAC9B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a random number within the given range.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} minimum - The lower bound (inclusive).
|
|
5
|
+
* @param {number} maximum - The upper bound (exclusive).
|
|
6
|
+
* @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
|
|
7
|
+
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result1 = random(0, 5); // Returns a random number between 0 and 5.
|
|
11
|
+
* const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown
|
|
12
|
+
* const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
|
|
13
|
+
*/
|
|
14
|
+
declare function random(minimum: number, maximum: number): number;
|
|
15
|
+
|
|
16
|
+
export { random };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a random number within the given range.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} minimum - The lower bound (inclusive).
|
|
5
|
+
* @param {number} maximum - The upper bound (exclusive).
|
|
6
|
+
* @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
|
|
7
|
+
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result1 = random(0, 5); // Returns a random number between 0 and 5.
|
|
11
|
+
* const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown
|
|
12
|
+
* const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
|
|
13
|
+
*/
|
|
14
|
+
declare function random(minimum: number, maximum: number): number;
|
|
15
|
+
|
|
16
|
+
export { random };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/math/random.ts
|
|
21
|
+
var random_exports = {};
|
|
22
|
+
__export(random_exports, {
|
|
23
|
+
random: () => random
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(random_exports);
|
|
26
|
+
function random(minimum, maximum) {
|
|
27
|
+
if (minimum >= maximum) {
|
|
28
|
+
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
29
|
+
}
|
|
30
|
+
return Math.random() * (maximum - minimum) + minimum;
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
random
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=random.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/math/random.ts"],"sourcesContent":["/**\n * Generate a random number within the given range.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(minimum: number, maximum: number): number {\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random integer between minimum (inclusive) and maximum (exclusive).
|
|
3
|
+
*
|
|
4
|
+
* @param {number} minimum - The lower bound (inclusive).
|
|
5
|
+
* @param {number} maximum - The upper bound (exclusive).
|
|
6
|
+
* @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).
|
|
7
|
+
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
|
|
11
|
+
* const result2 = randomInt(5, 0); // This will throw an error
|
|
12
|
+
*/
|
|
13
|
+
declare function randomInt(minimum: number, maximum: number): number;
|
|
14
|
+
|
|
15
|
+
export { randomInt };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random integer between minimum (inclusive) and maximum (exclusive).
|
|
3
|
+
*
|
|
4
|
+
* @param {number} minimum - The lower bound (inclusive).
|
|
5
|
+
* @param {number} maximum - The upper bound (exclusive).
|
|
6
|
+
* @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).
|
|
7
|
+
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
|
|
11
|
+
* const result2 = randomInt(5, 0); // This will throw an error
|
|
12
|
+
*/
|
|
13
|
+
declare function randomInt(minimum: number, maximum: number): number;
|
|
14
|
+
|
|
15
|
+
export { randomInt };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/math/randomInt.ts
|
|
21
|
+
var randomInt_exports = {};
|
|
22
|
+
__export(randomInt_exports, {
|
|
23
|
+
randomInt: () => randomInt
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(randomInt_exports);
|
|
26
|
+
|
|
27
|
+
// src/math/random.ts
|
|
28
|
+
function random(minimum, maximum) {
|
|
29
|
+
if (minimum >= maximum) {
|
|
30
|
+
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
31
|
+
}
|
|
32
|
+
return Math.random() * (maximum - minimum) + minimum;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/math/randomInt.ts
|
|
36
|
+
function randomInt(minimum, maximum) {
|
|
37
|
+
return Math.floor(random(minimum, maximum));
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
randomInt
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=randomInt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/math/randomInt.ts","../../src/math/random.ts"],"sourcesContent":["import { random } from './random';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(minimum: number, maximum: number): number {\n return Math.floor(random(minimum, maximum));\n}\n","/**\n * Generate a random number within the given range.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(minimum: number, maximum: number): number {\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ADLO,SAAS,UAAU,SAAiB,SAAyB;AAClE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAO,CAAC;AAC5C;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns an array of numbers from `start` to `end`, incrementing by `step`.
|
|
3
|
+
*
|
|
4
|
+
* If `step` is not provided, it defaults to `1` for an
|
|
5
|
+
* ascending range and `-1` for a descending range.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} start - The starting number of the range.
|
|
8
|
+
* @param {number} [end] - The end number of the range.
|
|
9
|
+
* @param {number} [step] - The step value for the range.
|
|
10
|
+
* @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Returns [0, 1, 2, 3]
|
|
14
|
+
* range(4);
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Returns [0, 5, 10, 15]
|
|
18
|
+
* range(0, 20, 5);
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Returns []
|
|
22
|
+
* range(0, -4, -1);
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Throws an error: The step value must be a non-zero integer.
|
|
26
|
+
* range(1, 4, 0);
|
|
27
|
+
*/
|
|
28
|
+
declare function range(end: number): number[];
|
|
29
|
+
declare function range(start: number, end: number): number[];
|
|
30
|
+
declare function range(start: number, end: number, step: number): number[];
|
|
31
|
+
|
|
32
|
+
export { range };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns an array of numbers from `start` to `end`, incrementing by `step`.
|
|
3
|
+
*
|
|
4
|
+
* If `step` is not provided, it defaults to `1` for an
|
|
5
|
+
* ascending range and `-1` for a descending range.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} start - The starting number of the range.
|
|
8
|
+
* @param {number} [end] - The end number of the range.
|
|
9
|
+
* @param {number} [step] - The step value for the range.
|
|
10
|
+
* @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Returns [0, 1, 2, 3]
|
|
14
|
+
* range(4);
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Returns [0, 5, 10, 15]
|
|
18
|
+
* range(0, 20, 5);
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Returns []
|
|
22
|
+
* range(0, -4, -1);
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Throws an error: The step value must be a non-zero integer.
|
|
26
|
+
* range(1, 4, 0);
|
|
27
|
+
*/
|
|
28
|
+
declare function range(end: number): number[];
|
|
29
|
+
declare function range(start: number, end: number): number[];
|
|
30
|
+
declare function range(start: number, end: number, step: number): number[];
|
|
31
|
+
|
|
32
|
+
export { range };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/math/range.ts
|
|
21
|
+
var range_exports = {};
|
|
22
|
+
__export(range_exports, {
|
|
23
|
+
range: () => range
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(range_exports);
|
|
26
|
+
function range(start, end, step) {
|
|
27
|
+
if (end == null) {
|
|
28
|
+
end = start;
|
|
29
|
+
start = 0;
|
|
30
|
+
}
|
|
31
|
+
if (step == null) {
|
|
32
|
+
step = 1;
|
|
33
|
+
}
|
|
34
|
+
if (!Number.isInteger(step) || step === 0) {
|
|
35
|
+
throw new Error(`The step value must be a non-zero integer.`);
|
|
36
|
+
}
|
|
37
|
+
const length = Math.max(Math.ceil((end - start) / (step || 1)), 0);
|
|
38
|
+
const result = new Array(length);
|
|
39
|
+
for (let i = 0; i < length; i++) {
|
|
40
|
+
result[i] = start + i * step;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
range
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/math/range.ts"],"sourcesContent":["/**\n * Returns an array of numbers from `start` to `end`, incrementing by `step`.\n *\n * If `step` is not provided, it defaults to `1` for an\n * ascending range and `-1` for a descending range.\n *\n * @param {number} start - The starting number of the range.\n * @param {number} [end] - The end number of the range.\n * @param {number} [step] - The step value for the range.\n * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.\n *\n * @example\n * // Returns [0, 1, 2, 3]\n * range(4);\n *\n * @example\n * // Returns [0, 5, 10, 15]\n * range(0, 20, 5);\n *\n * @example\n * // Returns []\n * range(0, -4, -1);\n *\n * @example\n * // Throws an error: The step value must be a non-zero integer.\n * range(1, 4, 0);\n */\nexport function range(end: number): number[];\nexport function range(start: number, end: number): number[];\nexport function range(start: number, end: number, step: number): number[];\nexport function range(start: number, end?: number, step?: number): number[] {\n if (end == null) {\n end = start;\n start = 0;\n }\n\n if (step == null) {\n step = 1;\n }\n\n if (!Number.isInteger(step) || step === 0) {\n throw new Error(`The step value must be a non-zero integer.`);\n }\n\n const length = Math.max(Math.ceil((end - start) / (step || 1)), 0);\n const result = new Array(length);\n\n for (let i = 0; i < length; i++) {\n result[i] = start + i * step;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BO,SAAS,MAAM,OAAe,KAAc,MAAyB;AAC1E,MAAI,OAAO,MAAM;AACf,UAAM;AACN,YAAQ;AAAA,EACV;AAEA,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,SAAS,GAAG;AACzC,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AAEA,QAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,UAAU,QAAQ,EAAE,GAAG,CAAC;AACjE,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,WAAO,CAAC,IAAI,QAAQ,IAAI;AAAA,EAC1B;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -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":[]}
|