Add settings page for managing forecasting API key and URL via UI

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-20 14:37:36 +00:00
parent cae411eae7
commit 1c411e402e
19809 changed files with 1962608 additions and 97 deletions

View file

@ -0,0 +1,19 @@
//#region src/compat/math/add.d.ts
/**
* Adds two numbers while safely handling `NaN` values.
*
* This function takes two numbers and returns their sum. If either of the numbers is `NaN`,
* the function returns `NaN`.
*
* @param value - The first number to add.
* @param other - The second number to add.
* @returns The sum of the two numbers, or `NaN` if any input is `NaN`.
*
* @example
* const result1 = add(2, 3); // result1 will be 5
* const result2 = add(5, NaN); // result2 will be NaN
* const result3 = add(NaN, 10); // result3 will be NaN
*/
declare function add(value: number, other: number): number;
//#endregion
export { add };

View file

@ -0,0 +1,19 @@
//#region src/compat/math/add.d.ts
/**
* Adds two numbers while safely handling `NaN` values.
*
* This function takes two numbers and returns their sum. If either of the numbers is `NaN`,
* the function returns `NaN`.
*
* @param value - The first number to add.
* @param other - The second number to add.
* @returns The sum of the two numbers, or `NaN` if any input is `NaN`.
*
* @example
* const result1 = add(2, 3); // result1 will be 5
* const result2 = add(5, NaN); // result2 will be NaN
* const result3 = add(NaN, 10); // result3 will be NaN
*/
declare function add(value: number, other: number): number;
//#endregion
export { add };

View file

@ -0,0 +1,32 @@
const require_toString = require("../util/toString.js");
const require_toNumber = require("../util/toNumber.js");
//#region src/compat/math/add.ts
/**
* Adds two numbers while safely handling `NaN` values.
*
* This function takes two numbers and returns their sum. If either of the numbers is `NaN`,
* the function returns `NaN`.
*
* @param value - The first number to add.
* @param other - The second number to add.
* @returns The sum of the two numbers, or `NaN` if any input is `NaN`.
*
* @example
* const result1 = add(2, 3); // result1 will be 5
* const result2 = add(5, NaN); // result2 will be NaN
* const result3 = add(NaN, 10); // result3 will be NaN
*/
function add(value, other) {
if (value === void 0 && other === void 0) return 0;
if (value === void 0 || other === void 0) return value ?? other;
if (typeof value === "string" || typeof other === "string") {
value = require_toString.toString(value);
other = require_toString.toString(other);
} else {
value = require_toNumber.toNumber(value);
other = require_toNumber.toNumber(other);
}
return value + other;
}
//#endregion
exports.add = add;

View file

@ -0,0 +1,32 @@
import { toString } from "../util/toString.mjs";
import { toNumber } from "../util/toNumber.mjs";
//#region src/compat/math/add.ts
/**
* Adds two numbers while safely handling `NaN` values.
*
* This function takes two numbers and returns their sum. If either of the numbers is `NaN`,
* the function returns `NaN`.
*
* @param value - The first number to add.
* @param other - The second number to add.
* @returns The sum of the two numbers, or `NaN` if any input is `NaN`.
*
* @example
* const result1 = add(2, 3); // result1 will be 5
* const result2 = add(5, NaN); // result2 will be NaN
* const result3 = add(NaN, 10); // result3 will be NaN
*/
function add(value, other) {
if (value === void 0 && other === void 0) return 0;
if (value === void 0 || other === void 0) return value ?? other;
if (typeof value === "string" || typeof other === "string") {
value = toString(value);
other = toString(other);
} else {
value = toNumber(value);
other = toNumber(other);
}
return value + other;
}
//#endregion
export { add };

View file

@ -0,0 +1,16 @@
//#region src/compat/math/ceil.d.ts
/**
* Computes number rounded up to precision.
*
* @param number The number to round up.
* @param precision The precision to round up to.
* @returns Returns the rounded up number.
*
* @example
* ceil(4.006); // => 5
* ceil(6.004, 2); // => 6.01
* ceil(6040, -2); // => 6100
*/
declare function ceil(number: number, precision?: number): number;
//#endregion
export { ceil };

View file

@ -0,0 +1,16 @@
//#region src/compat/math/ceil.d.ts
/**
* Computes number rounded up to precision.
*
* @param number The number to round up.
* @param precision The precision to round up to.
* @returns Returns the rounded up number.
*
* @example
* ceil(4.006); // => 5
* ceil(6.004, 2); // => 6.01
* ceil(6040, -2); // => 6100
*/
declare function ceil(number: number, precision?: number): number;
//#endregion
export { ceil };

View file

@ -0,0 +1,19 @@
const require_decimalAdjust = require("../_internal/decimalAdjust.js");
//#region src/compat/math/ceil.ts
/**
* Computes number rounded up to precision.
*
* @param number The number to round up.
* @param precision The precision to round up to.
* @returns Returns the rounded up number.
*
* @example
* ceil(4.006); // => 5
* ceil(6.004, 2); // => 6.01
* ceil(6040, -2); // => 6100
*/
function ceil(number, precision = 0) {
return require_decimalAdjust.decimalAdjust("ceil", number, precision);
}
//#endregion
exports.ceil = ceil;

View file

@ -0,0 +1,19 @@
import { decimalAdjust } from "../_internal/decimalAdjust.mjs";
//#region src/compat/math/ceil.ts
/**
* Computes number rounded up to precision.
*
* @param number The number to round up.
* @param precision The precision to round up to.
* @returns Returns the rounded up number.
*
* @example
* ceil(4.006); // => 5
* ceil(6.004, 2); // => 6.01
* ceil(6040, -2); // => 6100
*/
function ceil(number, precision = 0) {
return decimalAdjust("ceil", number, precision);
}
//#endregion
export { ceil };

View file

@ -0,0 +1,27 @@
//#region src/compat/math/clamp.d.ts
/**
* Clamps a number within the specified bounds.
*
* @param number The number to clamp
* @param lower The lower bound
* @param upper The upper bound
* @returns Returns the clamped number
* @example
* clamp(3, 2, 4) // => 3
* clamp(0, 5, 10) // => 5
* clamp(15, 5, 10) // => 10
*/
declare function clamp(number: number, lower: number, upper: number): number;
/**
* Clamps a number to an upper bound.
*
* @param number The number to clamp
* @param upper The upper bound
* @returns Returns the clamped number
* @example
* clamp(5, 3) // => 3
* clamp(2, 3) // => 2
*/
declare function clamp(number: number, upper: number): number;
//#endregion
export { clamp };

View file

@ -0,0 +1,27 @@
//#region src/compat/math/clamp.d.ts
/**
* Clamps a number within the specified bounds.
*
* @param number The number to clamp
* @param lower The lower bound
* @param upper The upper bound
* @returns Returns the clamped number
* @example
* clamp(3, 2, 4) // => 3
* clamp(0, 5, 10) // => 5
* clamp(15, 5, 10) // => 10
*/
declare function clamp(number: number, lower: number, upper: number): number;
/**
* Clamps a number to an upper bound.
*
* @param number The number to clamp
* @param upper The upper bound
* @returns Returns the clamped number
* @example
* clamp(5, 3) // => 3
* clamp(2, 3) // => 2
*/
declare function clamp(number: number, upper: number): number;
//#endregion
export { clamp };

View file

@ -0,0 +1,36 @@
const require_toNumber = require("../util/toNumber.js");
//#region src/compat/math/clamp.ts
/**
* Clamps a number within the specified bounds.
*
* This function takes a number and one or two bounds, and returns the number clamped within the specified bounds.
* If only one bound is provided, it returns the minimum of the value and the bound.
*
* @param value - The number to clamp.
* @param bound1 - The minimum bound to clamp the number, or the maximum bound if bound2 is not provided.
* @param [bound2] - The maximum bound to clamp the number. If not provided, the function will only consider bound1 as the upper limit.
* @returns The clamped number within the specified bounds.
*
* @example
* const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5
* const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15
* const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5
* const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15
*/
function clamp(value, bound1, bound2) {
if (bound2 === void 0) {
bound2 = bound1;
bound1 = void 0;
}
if (bound2 !== void 0) {
bound2 = require_toNumber.toNumber(bound2);
value = Math.min(value, Number.isNaN(bound2) ? 0 : bound2);
}
if (bound1 !== void 0) {
bound1 = require_toNumber.toNumber(bound1);
value = Math.max(value, Number.isNaN(bound1) ? 0 : bound1);
}
return value;
}
//#endregion
exports.clamp = clamp;

View file

@ -0,0 +1,36 @@
import { toNumber } from "../util/toNumber.mjs";
//#region src/compat/math/clamp.ts
/**
* Clamps a number within the specified bounds.
*
* This function takes a number and one or two bounds, and returns the number clamped within the specified bounds.
* If only one bound is provided, it returns the minimum of the value and the bound.
*
* @param value - The number to clamp.
* @param bound1 - The minimum bound to clamp the number, or the maximum bound if bound2 is not provided.
* @param [bound2] - The maximum bound to clamp the number. If not provided, the function will only consider bound1 as the upper limit.
* @returns The clamped number within the specified bounds.
*
* @example
* const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5
* const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15
* const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5
* const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15
*/
function clamp(value, bound1, bound2) {
if (bound2 === void 0) {
bound2 = bound1;
bound1 = void 0;
}
if (bound2 !== void 0) {
bound2 = toNumber(bound2);
value = Math.min(value, Number.isNaN(bound2) ? 0 : bound2);
}
if (bound1 !== void 0) {
bound1 = toNumber(bound1);
value = Math.max(value, Number.isNaN(bound1) ? 0 : bound1);
}
return value;
}
//#endregion
export { clamp };

View file

@ -0,0 +1,19 @@
//#region src/compat/math/divide.d.ts
/**
* Divide two numbers.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number in a division.
* @param other The second number in a division.
* @returns The quotient of value and other.
*
* @example
* divide(6, 3); // => 2
* divide(2, NaN); // => NaN
* divide(NaN, 3); // => NaN
* divide(NaN, NaN); // => NaN
*/
declare function divide(value: number, other: number): number;
//#endregion
export { divide };

View file

@ -0,0 +1,19 @@
//#region src/compat/math/divide.d.ts
/**
* Divide two numbers.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number in a division.
* @param other The second number in a division.
* @returns The quotient of value and other.
*
* @example
* divide(6, 3); // => 2
* divide(2, NaN); // => NaN
* divide(NaN, 3); // => NaN
* divide(NaN, NaN); // => NaN
*/
declare function divide(value: number, other: number): number;
//#endregion
export { divide };

View file

@ -0,0 +1,32 @@
const require_toString = require("../util/toString.js");
const require_toNumber = require("../util/toNumber.js");
//#region src/compat/math/divide.ts
/**
* Divide two numbers.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number in a division.
* @param other The second number in a division.
* @returns The quotient of value and other.
*
* @example
* divide(6, 3); // => 2
* divide(2, NaN); // => NaN
* divide(NaN, 3); // => NaN
* divide(NaN, NaN); // => NaN
*/
function divide(value, other) {
if (value === void 0 && other === void 0) return 1;
if (value === void 0 || other === void 0) return value ?? other;
if (typeof value === "string" || typeof other === "string") {
value = require_toString.toString(value);
other = require_toString.toString(other);
} else {
value = require_toNumber.toNumber(value);
other = require_toNumber.toNumber(other);
}
return value / other;
}
//#endregion
exports.divide = divide;

View file

@ -0,0 +1,32 @@
import { toString } from "../util/toString.mjs";
import { toNumber } from "../util/toNumber.mjs";
//#region src/compat/math/divide.ts
/**
* Divide two numbers.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number in a division.
* @param other The second number in a division.
* @returns The quotient of value and other.
*
* @example
* divide(6, 3); // => 2
* divide(2, NaN); // => NaN
* divide(NaN, 3); // => NaN
* divide(NaN, NaN); // => NaN
*/
function divide(value, other) {
if (value === void 0 && other === void 0) return 1;
if (value === void 0 || other === void 0) return value ?? other;
if (typeof value === "string" || typeof other === "string") {
value = toString(value);
other = toString(other);
} else {
value = toNumber(value);
other = toNumber(other);
}
return value / other;
}
//#endregion
export { divide };

View file

@ -0,0 +1,16 @@
//#region src/compat/math/floor.d.ts
/**
* Computes number rounded down to precision.
*
* @param number The number to round down.
* @param precision The precision to round down to.
* @returns Returns the rounded down number.
*
* @example
* floor(4.006); // => 4
* floor(0.046, 2); // => 0.04
* floor(4060, -2); // => 4000
*/
declare function floor(number: number, precision?: number): number;
//#endregion
export { floor };

View file

@ -0,0 +1,16 @@
//#region src/compat/math/floor.d.ts
/**
* Computes number rounded down to precision.
*
* @param number The number to round down.
* @param precision The precision to round down to.
* @returns Returns the rounded down number.
*
* @example
* floor(4.006); // => 4
* floor(0.046, 2); // => 0.04
* floor(4060, -2); // => 4000
*/
declare function floor(number: number, precision?: number): number;
//#endregion
export { floor };

View file

@ -0,0 +1,19 @@
const require_decimalAdjust = require("../_internal/decimalAdjust.js");
//#region src/compat/math/floor.ts
/**
* Computes number rounded down to precision.
*
* @param number The number to round down.
* @param precision The precision to round down to.
* @returns Returns the rounded down number.
*
* @example
* floor(4.006); // => 4
* floor(0.046, 2); // => 0.04
* floor(4060, -2); // => 4000
*/
function floor(number, precision = 0) {
return require_decimalAdjust.decimalAdjust("floor", number, precision);
}
//#endregion
exports.floor = floor;

View file

@ -0,0 +1,19 @@
import { decimalAdjust } from "../_internal/decimalAdjust.mjs";
//#region src/compat/math/floor.ts
/**
* Computes number rounded down to precision.
*
* @param number The number to round down.
* @param precision The precision to round down to.
* @returns Returns the rounded down number.
*
* @example
* floor(4.006); // => 4
* floor(0.046, 2); // => 0.04
* floor(4060, -2); // => 4000
*/
function floor(number, precision = 0) {
return decimalAdjust("floor", number, precision);
}
//#endregion
export { floor };

View file

@ -0,0 +1,18 @@
//#region src/compat/math/inRange.d.ts
/**
* Checks if the value is within a specified range.
*
* @param value The value to check.
* @param minimum The lower bound of the range (inclusive).
* @param maximum The upper bound of the range (exclusive).
* @returns `true` if the value is within the specified range, otherwise `false`.
* @throws {Error} Throws an error if the `minimum` is greater or equal than the `maximum`.
*
* @example
* const result1 = inRange(3, 5); // result1 will be true.
* const result2 = inRange(1, 2, 5); // result2 will be false.
* const result3 = inRange(1, 5, 2); // If the minimum is greater or equal than the maximum, an error is thrown.
*/
declare function inRange(value: number, minimum: number, maximum?: number): boolean;
//#endregion
export { inRange };

View file

@ -0,0 +1,18 @@
//#region src/compat/math/inRange.d.ts
/**
* Checks if the value is within a specified range.
*
* @param value The value to check.
* @param minimum The lower bound of the range (inclusive).
* @param maximum The upper bound of the range (exclusive).
* @returns `true` if the value is within the specified range, otherwise `false`.
* @throws {Error} Throws an error if the `minimum` is greater or equal than the `maximum`.
*
* @example
* const result1 = inRange(3, 5); // result1 will be true.
* const result2 = inRange(1, 2, 5); // result2 will be false.
* const result3 = inRange(1, 5, 2); // If the minimum is greater or equal than the maximum, an error is thrown.
*/
declare function inRange(value: number, minimum: number, maximum?: number): boolean;
//#endregion
export { inRange };

View file

@ -0,0 +1,28 @@
const require_inRange = require("../../math/inRange.js");
//#region src/compat/math/inRange.ts
/**
* Checks if the value is within a specified range.
*
* @param value The value to check.
* @param minimum The lower bound of the range (inclusive).
* @param maximum The upper bound of the range (exclusive).
* @returns `true` if the value is within the specified range, otherwise `false`.
* @throws {Error} Throws an error if the `minimum` is greater or equal than the `maximum`.
*
* @example
* const result1 = inRange(3, 5); // result1 will be true.
* const result2 = inRange(1, 2, 5); // result2 will be false.
* const result3 = inRange(1, 5, 2); // If the minimum is greater or equal than the maximum, an error is thrown.
*/
function inRange(value, minimum, maximum) {
if (!minimum) minimum = 0;
if (maximum != null && !maximum) maximum = 0;
if (minimum != null && typeof minimum !== "number") minimum = Number(minimum);
if (maximum == null && minimum === 0) return false;
if (maximum != null && typeof maximum !== "number") maximum = Number(maximum);
if (maximum != null && minimum > maximum) [minimum, maximum] = [maximum, minimum];
if (minimum === maximum) return false;
return require_inRange.inRange(value, minimum, maximum);
}
//#endregion
exports.inRange = inRange;

View file

@ -0,0 +1,28 @@
import { inRange as inRange$1 } from "../../math/inRange.mjs";
//#region src/compat/math/inRange.ts
/**
* Checks if the value is within a specified range.
*
* @param value The value to check.
* @param minimum The lower bound of the range (inclusive).
* @param maximum The upper bound of the range (exclusive).
* @returns `true` if the value is within the specified range, otherwise `false`.
* @throws {Error} Throws an error if the `minimum` is greater or equal than the `maximum`.
*
* @example
* const result1 = inRange(3, 5); // result1 will be true.
* const result2 = inRange(1, 2, 5); // result2 will be false.
* const result3 = inRange(1, 5, 2); // If the minimum is greater or equal than the maximum, an error is thrown.
*/
function inRange(value, minimum, maximum) {
if (!minimum) minimum = 0;
if (maximum != null && !maximum) maximum = 0;
if (minimum != null && typeof minimum !== "number") minimum = Number(minimum);
if (maximum == null && minimum === 0) return false;
if (maximum != null && typeof maximum !== "number") maximum = Number(maximum);
if (maximum != null && minimum > maximum) [minimum, maximum] = [maximum, minimum];
if (minimum === maximum) return false;
return inRange$1(value, minimum, maximum);
}
//#endregion
export { inRange };

View file

@ -0,0 +1,11 @@
//#region src/compat/math/max.d.ts
/**
* Finds the element in an array that has the maximum value.
*
* @template T - The type of elements in the array.
* @param [items] - The array of elements to search. Defaults to an empty array.
* @returns The element with the maximum value, or undefined if the array is empty.
*/
declare function max<T>(items: ArrayLike<T> | null | undefined): T | undefined;
//#endregion
export { max };

View file

@ -0,0 +1,11 @@
//#region src/compat/math/max.d.ts
/**
* Finds the element in an array that has the maximum value.
*
* @template T - The type of elements in the array.
* @param [items] - The array of elements to search. Defaults to an empty array.
* @returns The element with the maximum value, or undefined if the array is empty.
*/
declare function max<T>(items: ArrayLike<T> | null | undefined): T | undefined;
//#endregion
export { max };

View file

@ -0,0 +1,20 @@
//#region src/compat/math/max.ts
/**
* Finds the element in an array that has the maximum value.
*
* @template T - The type of elements in the array.
* @param [items] - The array of elements to search. Defaults to an empty array.
* @returns The element with the maximum value, or undefined if the array is empty.
*/
function max(items) {
if (!items || items.length === 0) return;
let maxResult = void 0;
for (let i = 0; i < items.length; i++) {
const current = items[i];
if (current == null || Number.isNaN(current) || typeof current === "symbol") continue;
if (maxResult === void 0 || current > maxResult) maxResult = current;
}
return maxResult;
}
//#endregion
exports.max = max;

View file

@ -0,0 +1,20 @@
//#region src/compat/math/max.ts
/**
* Finds the element in an array that has the maximum value.
*
* @template T - The type of elements in the array.
* @param [items] - The array of elements to search. Defaults to an empty array.
* @returns The element with the maximum value, or undefined if the array is empty.
*/
function max(items) {
if (!items || items.length === 0) return;
let maxResult = void 0;
for (let i = 0; i < items.length; i++) {
const current = items[i];
if (current == null || Number.isNaN(current) || typeof current === "symbol") continue;
if (maxResult === void 0 || current > maxResult) maxResult = current;
}
return maxResult;
}
//#endregion
export { max };

View file

@ -0,0 +1,34 @@
import { ValueIteratee } from "../_internal/ValueIteratee.mjs";
//#region src/compat/math/maxBy.d.ts
/**
* Finds the element in an array that has the maximum value when applying
* the `iteratee` to each element.
*
* @template T - The type of elements in the array.
* @param items The array of elements to search.
* @param iteratee
* The criteria used to determine the maximum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The element with the maximum value as determined by the `iteratee`.
* @example
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
* maxBy([], x => x.a); // Returns: undefined
* maxBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'john', age: 30 }
* maxBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 2 }
* maxBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 1 }
* maxBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 1 }
*/
declare function maxBy<T>(items: ArrayLike<T> | null | undefined, iteratee?: ValueIteratee<T>): T | undefined;
//#endregion
export { maxBy };

View file

@ -0,0 +1,34 @@
import { ValueIteratee } from "../_internal/ValueIteratee.js";
//#region src/compat/math/maxBy.d.ts
/**
* Finds the element in an array that has the maximum value when applying
* the `iteratee` to each element.
*
* @template T - The type of elements in the array.
* @param items The array of elements to search.
* @param iteratee
* The criteria used to determine the maximum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The element with the maximum value as determined by the `iteratee`.
* @example
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
* maxBy([], x => x.a); // Returns: undefined
* maxBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'john', age: 30 }
* maxBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 2 }
* maxBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 1 }
* maxBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 1 }
*/
declare function maxBy<T>(items: ArrayLike<T> | null | undefined, iteratee?: ValueIteratee<T>): T | undefined;
//#endregion
export { maxBy };

View file

@ -0,0 +1,38 @@
const require_maxBy = require("../../array/maxBy.js");
const require_identity = require("../../function/identity.js");
const require_iteratee = require("../util/iteratee.js");
//#region src/compat/math/maxBy.ts
/**
* Finds the element in an array that has the maximum value when applying
* the `iteratee` to each element.
*
* @template T - The type of elements in the array.
* @param items The array of elements to search.
* @param iteratee
* The criteria used to determine the maximum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The element with the maximum value as determined by the `iteratee`.
* @example
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
* maxBy([], x => x.a); // Returns: undefined
* maxBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'john', age: 30 }
* maxBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 2 }
* maxBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 1 }
* maxBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 1 }
*/
function maxBy(items, iteratee$1) {
if (items == null) return;
return require_maxBy.maxBy(Array.from(items), require_iteratee.iteratee(iteratee$1 ?? require_identity.identity));
}
//#endregion
exports.maxBy = maxBy;

View file

@ -0,0 +1,38 @@
import { maxBy as maxBy$1 } from "../../array/maxBy.mjs";
import { identity } from "../../function/identity.mjs";
import { iteratee } from "../util/iteratee.mjs";
//#region src/compat/math/maxBy.ts
/**
* Finds the element in an array that has the maximum value when applying
* the `iteratee` to each element.
*
* @template T - The type of elements in the array.
* @param items The array of elements to search.
* @param iteratee
* The criteria used to determine the maximum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The element with the maximum value as determined by the `iteratee`.
* @example
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
* maxBy([], x => x.a); // Returns: undefined
* maxBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'john', age: 30 }
* maxBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 2 }
* maxBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 1 }
* maxBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 1 }
*/
function maxBy(items, iteratee$1) {
if (items == null) return;
return maxBy$1(Array.from(items), iteratee(iteratee$1 ?? identity));
}
//#endregion
export { maxBy };

View file

@ -0,0 +1,17 @@
//#region src/compat/math/mean.d.ts
/**
* Calculates the average of an array of numbers.
*
* If the array is empty, this function returns `NaN`.
*
* @param nums - An array of numbers to calculate the average.
* @returns The average of all the numbers in the array.
*
* @example
* const numbers = [1, 2, 3, 4, 5];
* const result = mean(numbers);
* // result will be 3
*/
declare function mean(nums: ArrayLike<any> | null | undefined): number;
//#endregion
export { mean };

View file

@ -0,0 +1,17 @@
//#region src/compat/math/mean.d.ts
/**
* Calculates the average of an array of numbers.
*
* If the array is empty, this function returns `NaN`.
*
* @param nums - An array of numbers to calculate the average.
* @returns The average of all the numbers in the array.
*
* @example
* const numbers = [1, 2, 3, 4, 5];
* const result = mean(numbers);
* // result will be 3
*/
declare function mean(nums: ArrayLike<any> | null | undefined): number;
//#endregion
export { mean };

View file

@ -0,0 +1,21 @@
const require_sum = require("./sum.js");
//#region src/compat/math/mean.ts
/**
* Calculates the average of an array of numbers.
*
* If the array is empty, this function returns `NaN`.
*
* @param nums - An array of numbers to calculate the average.
* @returns The average of all the numbers in the array.
*
* @example
* const numbers = [1, 2, 3, 4, 5];
* const result = mean(numbers);
* // result will be 3
*/
function mean(nums) {
const length = nums ? nums.length : 0;
return length === 0 ? NaN : require_sum.sum(nums) / length;
}
//#endregion
exports.mean = mean;

View file

@ -0,0 +1,21 @@
import { sum } from "./sum.mjs";
//#region src/compat/math/mean.ts
/**
* Calculates the average of an array of numbers.
*
* If the array is empty, this function returns `NaN`.
*
* @param nums - An array of numbers to calculate the average.
* @returns The average of all the numbers in the array.
*
* @example
* const numbers = [1, 2, 3, 4, 5];
* const result = mean(numbers);
* // result will be 3
*/
function mean(nums) {
const length = nums ? nums.length : 0;
return length === 0 ? NaN : sum(nums) / length;
}
//#endregion
export { mean };

View file

@ -0,0 +1,28 @@
import { ValueIteratee } from "../_internal/ValueIteratee.mjs";
//#region src/compat/math/meanBy.d.ts
/**
* Calculates the average of an array of numbers when applying
* the `iteratee` function to each element.
*
* If the array is empty, this function returns `NaN`.
*
* @template T - The type of elements in the array.
* @param items An array to calculate the average.
* @param iteratee
* The criteria used to determine the maximum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The average of all the numbers as determined by the `iteratee` function.
*
* @example
* meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2
* meanBy([], x => x.a); // Returns: NaN
* meanBy([[2], [3], [1]], 0); // Returns: 2
* meanBy([{ a: 2 }, { a: 3 }, { a: 1 }], 'a'); // Returns: 2
*/
declare function meanBy<T>(items: ArrayLike<T> | null | undefined, iteratee?: ValueIteratee<T>): number;
//#endregion
export { meanBy };

View file

@ -0,0 +1,28 @@
import { ValueIteratee } from "../_internal/ValueIteratee.js";
//#region src/compat/math/meanBy.d.ts
/**
* Calculates the average of an array of numbers when applying
* the `iteratee` function to each element.
*
* If the array is empty, this function returns `NaN`.
*
* @template T - The type of elements in the array.
* @param items An array to calculate the average.
* @param iteratee
* The criteria used to determine the maximum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The average of all the numbers as determined by the `iteratee` function.
*
* @example
* meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2
* meanBy([], x => x.a); // Returns: NaN
* meanBy([[2], [3], [1]], 0); // Returns: 2
* meanBy([{ a: 2 }, { a: 3 }, { a: 1 }], 'a'); // Returns: 2
*/
declare function meanBy<T>(items: ArrayLike<T> | null | undefined, iteratee?: ValueIteratee<T>): number;
//#endregion
export { meanBy };

View file

@ -0,0 +1,32 @@
const require_identity = require("../../function/identity.js");
const require_meanBy = require("../../math/meanBy.js");
const require_iteratee = require("../util/iteratee.js");
//#region src/compat/math/meanBy.ts
/**
* Calculates the average of an array of numbers when applying
* the `iteratee` function to each element.
*
* If the array is empty, this function returns `NaN`.
*
* @template T - The type of elements in the array.
* @param items An array to calculate the average.
* @param iteratee
* The criteria used to determine the maximum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The average of all the numbers as determined by the `iteratee` function.
*
* @example
* meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2
* meanBy([], x => x.a); // Returns: NaN
* meanBy([[2], [3], [1]], 0); // Returns: 2
* meanBy([{ a: 2 }, { a: 3 }, { a: 1 }], 'a'); // Returns: 2
*/
function meanBy(items, iteratee$1) {
if (items == null) return NaN;
return require_meanBy.meanBy(Array.from(items), require_iteratee.iteratee(iteratee$1 ?? require_identity.identity));
}
//#endregion
exports.meanBy = meanBy;

View file

@ -0,0 +1,32 @@
import { identity } from "../../function/identity.mjs";
import { meanBy as meanBy$1 } from "../../math/meanBy.mjs";
import { iteratee } from "../util/iteratee.mjs";
//#region src/compat/math/meanBy.ts
/**
* Calculates the average of an array of numbers when applying
* the `iteratee` function to each element.
*
* If the array is empty, this function returns `NaN`.
*
* @template T - The type of elements in the array.
* @param items An array to calculate the average.
* @param iteratee
* The criteria used to determine the maximum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The average of all the numbers as determined by the `iteratee` function.
*
* @example
* meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2
* meanBy([], x => x.a); // Returns: NaN
* meanBy([[2], [3], [1]], 0); // Returns: 2
* meanBy([{ a: 2 }, { a: 3 }, { a: 1 }], 'a'); // Returns: 2
*/
function meanBy(items, iteratee$1) {
if (items == null) return NaN;
return meanBy$1(Array.from(items), iteratee(iteratee$1 ?? identity));
}
//#endregion
export { meanBy };

View file

@ -0,0 +1,11 @@
//#region src/compat/math/min.d.ts
/**
* Finds the element in an array that has the minimum value.
*
* @template T - The type of elements in the array.
* @param [items] - The array of elements to search. Defaults to an empty array.
* @returns The element with the minimum value, or undefined if the array is empty.
*/
declare function min<T>(items: ArrayLike<T> | null | undefined): T | undefined;
//#endregion
export { min };

View file

@ -0,0 +1,11 @@
//#region src/compat/math/min.d.ts
/**
* Finds the element in an array that has the minimum value.
*
* @template T - The type of elements in the array.
* @param [items] - The array of elements to search. Defaults to an empty array.
* @returns The element with the minimum value, or undefined if the array is empty.
*/
declare function min<T>(items: ArrayLike<T> | null | undefined): T | undefined;
//#endregion
export { min };

View file

@ -0,0 +1,20 @@
//#region src/compat/math/min.ts
/**
* Finds the element in an array that has the minimum value.
*
* @template T - The type of elements in the array.
* @param [items] - The array of elements to search. Defaults to an empty array.
* @returns The element with the minimum value, or undefined if the array is empty.
*/
function min(items) {
if (!items || items.length === 0) return;
let minResult = void 0;
for (let i = 0; i < items.length; i++) {
const current = items[i];
if (current == null || Number.isNaN(current) || typeof current === "symbol") continue;
if (minResult === void 0 || current < minResult) minResult = current;
}
return minResult;
}
//#endregion
exports.min = min;

View file

@ -0,0 +1,20 @@
//#region src/compat/math/min.ts
/**
* Finds the element in an array that has the minimum value.
*
* @template T - The type of elements in the array.
* @param [items] - The array of elements to search. Defaults to an empty array.
* @returns The element with the minimum value, or undefined if the array is empty.
*/
function min(items) {
if (!items || items.length === 0) return;
let minResult = void 0;
for (let i = 0; i < items.length; i++) {
const current = items[i];
if (current == null || Number.isNaN(current) || typeof current === "symbol") continue;
if (minResult === void 0 || current < minResult) minResult = current;
}
return minResult;
}
//#endregion
export { min };

View file

@ -0,0 +1,34 @@
import { ValueIteratee } from "../_internal/ValueIteratee.mjs";
//#region src/compat/math/minBy.d.ts
/**
* Finds the element in an array that has the minimum value when applying
* the `iteratee` to each element.
*
* @template T - The type of elements in the array.
* @param items The array of elements to search.
* @param iteratee
* The criteria used to determine the minimum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The element with the minimum value as determined by the `iteratee`.
* @example
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
* minBy([], x => x.a); // Returns: undefined
* minBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'joe', age: 26 }
* minBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 1 }
* minBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 2 }
* minBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 2 }
*/
declare function minBy<T>(items: ArrayLike<T> | null | undefined, iteratee?: ValueIteratee<T>): T | undefined;
//#endregion
export { minBy };

View file

@ -0,0 +1,34 @@
import { ValueIteratee } from "../_internal/ValueIteratee.js";
//#region src/compat/math/minBy.d.ts
/**
* Finds the element in an array that has the minimum value when applying
* the `iteratee` to each element.
*
* @template T - The type of elements in the array.
* @param items The array of elements to search.
* @param iteratee
* The criteria used to determine the minimum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The element with the minimum value as determined by the `iteratee`.
* @example
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
* minBy([], x => x.a); // Returns: undefined
* minBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'joe', age: 26 }
* minBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 1 }
* minBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 2 }
* minBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 2 }
*/
declare function minBy<T>(items: ArrayLike<T> | null | undefined, iteratee?: ValueIteratee<T>): T | undefined;
//#endregion
export { minBy };

View file

@ -0,0 +1,38 @@
const require_minBy = require("../../array/minBy.js");
const require_identity = require("../../function/identity.js");
const require_iteratee = require("../util/iteratee.js");
//#region src/compat/math/minBy.ts
/**
* Finds the element in an array that has the minimum value when applying
* the `iteratee` to each element.
*
* @template T - The type of elements in the array.
* @param items The array of elements to search.
* @param iteratee
* The criteria used to determine the minimum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The element with the minimum value as determined by the `iteratee`.
* @example
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
* minBy([], x => x.a); // Returns: undefined
* minBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'joe', age: 26 }
* minBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 1 }
* minBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 2 }
* minBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 2 }
*/
function minBy(items, iteratee$1) {
if (items == null) return;
return require_minBy.minBy(Array.from(items), require_iteratee.iteratee(iteratee$1 ?? require_identity.identity));
}
//#endregion
exports.minBy = minBy;

View file

@ -0,0 +1,38 @@
import { minBy as minBy$1 } from "../../array/minBy.mjs";
import { identity } from "../../function/identity.mjs";
import { iteratee } from "../util/iteratee.mjs";
//#region src/compat/math/minBy.ts
/**
* Finds the element in an array that has the minimum value when applying
* the `iteratee` to each element.
*
* @template T - The type of elements in the array.
* @param items The array of elements to search.
* @param iteratee
* The criteria used to determine the minimum value.
* - If a **function** is provided, it extracts a numeric value from each element.
* - If a **string** is provided, it is treated as a key to extract values from the objects.
* - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
* - If an **object** is provided, it matches elements that contain the specified properties.
* @returns The element with the minimum value as determined by the `iteratee`.
* @example
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
* minBy([], x => x.a); // Returns: undefined
* minBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'joe', age: 26 }
* minBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 1 }
* minBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 2 }
* minBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 2 }
*/
function minBy(items, iteratee$1) {
if (items == null) return;
return minBy$1(Array.from(items), iteratee(iteratee$1 ?? identity));
}
//#endregion
export { minBy };

View file

@ -0,0 +1,19 @@
//#region src/compat/math/multiply.d.ts
/**
* Multiply two numbers.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number in a multiplication
* @param other The second number in a multiplication
* @returns The product of value and other
*
* @example
* multiply(2, 3); // => 6
* multiply(2, NaN); // => NaN
* multiply(NaN, 3); // => NaN
* multiply(NaN, NaN); // => NaN
*/
declare function multiply(value: number, other: number): number;
//#endregion
export { multiply };

View file

@ -0,0 +1,19 @@
//#region src/compat/math/multiply.d.ts
/**
* Multiply two numbers.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number in a multiplication
* @param other The second number in a multiplication
* @returns The product of value and other
*
* @example
* multiply(2, 3); // => 6
* multiply(2, NaN); // => NaN
* multiply(NaN, 3); // => NaN
* multiply(NaN, NaN); // => NaN
*/
declare function multiply(value: number, other: number): number;
//#endregion
export { multiply };

View file

@ -0,0 +1,32 @@
const require_toString = require("../util/toString.js");
const require_toNumber = require("../util/toNumber.js");
//#region src/compat/math/multiply.ts
/**
* Multiply two numbers.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number in a multiplication
* @param other The second number in a multiplication
* @returns The product of value and other
*
* @example
* multiply(2, 3); // => 6
* multiply(2, NaN); // => NaN
* multiply(NaN, 3); // => NaN
* multiply(NaN, NaN); // => NaN
*/
function multiply(value, other) {
if (value === void 0 && other === void 0) return 1;
if (value === void 0 || other === void 0) return value ?? other;
if (typeof value === "string" || typeof other === "string") {
value = require_toString.toString(value);
other = require_toString.toString(other);
} else {
value = require_toNumber.toNumber(value);
other = require_toNumber.toNumber(other);
}
return value * other;
}
//#endregion
exports.multiply = multiply;

View file

@ -0,0 +1,32 @@
import { toString } from "../util/toString.mjs";
import { toNumber } from "../util/toNumber.mjs";
//#region src/compat/math/multiply.ts
/**
* Multiply two numbers.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number in a multiplication
* @param other The second number in a multiplication
* @returns The product of value and other
*
* @example
* multiply(2, 3); // => 6
* multiply(2, NaN); // => NaN
* multiply(NaN, 3); // => NaN
* multiply(NaN, NaN); // => NaN
*/
function multiply(value, other) {
if (value === void 0 && other === void 0) return 1;
if (value === void 0 || other === void 0) return value ?? other;
if (typeof value === "string" || typeof other === "string") {
value = toString(value);
other = toString(other);
} else {
value = toNumber(value);
other = toNumber(other);
}
return value * other;
}
//#endregion
export { multiply };

View file

@ -0,0 +1,21 @@
//#region src/compat/math/parseInt.d.ts
/**
* Converts `string` to an integer of the specified radix. If `radix` is undefined or 0, a `radix` of 10 is used unless `string` is a hexadecimal, in which case a `radix` of 16 is used.
*
* @param string The string to convert to an integer.
* @param radix The radix to use when converting the string to an integer. Defaults to `0`.
* @param guard Enables use as an iteratee for methods like `Array#map`.
* @returns Returns the converted integer.
*
* @example
* parseInt('08'); // => 8
* parseInt('0x20'); // => 32
*
* parseInt('08', 10); // => 8
* parseInt('0x20', 16); // => 32
*
* ['6', '08', '10'].map(parseInt); // => [6, 8, 10]
*/
declare function parseInt(string: string, radix?: number): number;
//#endregion
export { parseInt };

View file

@ -0,0 +1,21 @@
//#region src/compat/math/parseInt.d.ts
/**
* Converts `string` to an integer of the specified radix. If `radix` is undefined or 0, a `radix` of 10 is used unless `string` is a hexadecimal, in which case a `radix` of 16 is used.
*
* @param string The string to convert to an integer.
* @param radix The radix to use when converting the string to an integer. Defaults to `0`.
* @param guard Enables use as an iteratee for methods like `Array#map`.
* @returns Returns the converted integer.
*
* @example
* parseInt('08'); // => 8
* parseInt('0x20'); // => 32
*
* parseInt('08', 10); // => 8
* parseInt('0x20', 16); // => 32
*
* ['6', '08', '10'].map(parseInt); // => [6, 8, 10]
*/
declare function parseInt(string: string, radix?: number): number;
//#endregion
export { parseInt };

View file

@ -0,0 +1,25 @@
const require_toString = require("../util/toString.js");
//#region src/compat/math/parseInt.ts
/**
* Converts `string` to an integer of the specified radix. If `radix` is undefined or 0, a `radix` of 10 is used unless `string` is a hexadecimal, in which case a `radix` of 16 is used.
*
* @param string The string to convert to an integer.
* @param radix The radix to use when converting the string to an integer. Defaults to `0`.
* @param guard Enables use as an iteratee for methods like `Array#map`.
* @returns Returns the converted integer.
*
* @example
* parseInt('08'); // => 8
* parseInt('0x20'); // => 32
*
* parseInt('08', 10); // => 8
* parseInt('0x20', 16); // => 32
*
* ['6', '08', '10'].map(parseInt); // => [6, 8, 10]
*/
function parseInt(string, radix = 0, guard) {
if (guard) radix = 0;
return Number.parseInt(require_toString.toString(string), radix);
}
//#endregion
exports.parseInt = parseInt;

View file

@ -0,0 +1,25 @@
import { toString } from "../util/toString.mjs";
//#region src/compat/math/parseInt.ts
/**
* Converts `string` to an integer of the specified radix. If `radix` is undefined or 0, a `radix` of 10 is used unless `string` is a hexadecimal, in which case a `radix` of 16 is used.
*
* @param string The string to convert to an integer.
* @param radix The radix to use when converting the string to an integer. Defaults to `0`.
* @param guard Enables use as an iteratee for methods like `Array#map`.
* @returns Returns the converted integer.
*
* @example
* parseInt('08'); // => 8
* parseInt('0x20'); // => 32
*
* parseInt('08', 10); // => 8
* parseInt('0x20', 16); // => 32
*
* ['6', '08', '10'].map(parseInt); // => [6, 8, 10]
*/
function parseInt(string, radix = 0, guard) {
if (guard) radix = 0;
return Number.parseInt(toString(string), radix);
}
//#endregion
export { parseInt };

View file

@ -0,0 +1,47 @@
//#region src/compat/math/random.d.ts
/**
* Generate a random number between 0 and 1.
* @param [floating] - Whether to return a floating point number. Defaults to false.
* @returns A random number between 0 and 1.
* @example
* random(); // Returns a random number between 0 and 1
* random(true); // Returns a random floating point number between 0 and 1
* random(false); // Returns a random integer between 0 and 1
*/
declare function random(floating?: boolean): number;
/**
* Generate a random number between 0 and max.
* @param max - The upper bound (exclusive).
* @param [floating] - Whether to return a floating point number. Defaults to false.
* @returns A random number between 0 and max.
* @example
* random(5); // Returns a random number between 0 and 5
* random(10, true); // Returns a random floating point number between 0 and 10
* random(3, false); // Returns a random integer between 0 and 3
*/
declare function random(max: number, floating?: boolean): number;
/**
* Generate a random number between min and max.
* @param min - The lower bound (inclusive).
* @param max - The upper bound (exclusive).
* @param [floating] - Whether to return a floating point number. Defaults to false.
* @returns A random number between min and max.
* @example
* random(1, 5); // Returns a random number between 1 and 5
* random(0, 10, true); // Returns a random floating point number between 0 and 10
* random(1, 6, false); // Returns a random integer between 1 and 6
*/
declare function random(min: number, max: number, floating?: boolean): number;
/**
* Generate a random number between 0 and min, using guard object for special cases.
* @param min - The upper bound (exclusive).
* @param index - The index or key to check in the guard object.
* @param guard - The guard object to validate the parameters.
* @returns A random number between 0 and min.
* @example
* const guard = { 5: 5 };
* random(5, 5, guard); // Returns a random number between 0 and 5
*/
declare function random(min: number, index: string | number, guard: object): number;
//#endregion
export { random };

View file

@ -0,0 +1,47 @@
//#region src/compat/math/random.d.ts
/**
* Generate a random number between 0 and 1.
* @param [floating] - Whether to return a floating point number. Defaults to false.
* @returns A random number between 0 and 1.
* @example
* random(); // Returns a random number between 0 and 1
* random(true); // Returns a random floating point number between 0 and 1
* random(false); // Returns a random integer between 0 and 1
*/
declare function random(floating?: boolean): number;
/**
* Generate a random number between 0 and max.
* @param max - The upper bound (exclusive).
* @param [floating] - Whether to return a floating point number. Defaults to false.
* @returns A random number between 0 and max.
* @example
* random(5); // Returns a random number between 0 and 5
* random(10, true); // Returns a random floating point number between 0 and 10
* random(3, false); // Returns a random integer between 0 and 3
*/
declare function random(max: number, floating?: boolean): number;
/**
* Generate a random number between min and max.
* @param min - The lower bound (inclusive).
* @param max - The upper bound (exclusive).
* @param [floating] - Whether to return a floating point number. Defaults to false.
* @returns A random number between min and max.
* @example
* random(1, 5); // Returns a random number between 1 and 5
* random(0, 10, true); // Returns a random floating point number between 0 and 10
* random(1, 6, false); // Returns a random integer between 1 and 6
*/
declare function random(min: number, max: number, floating?: boolean): number;
/**
* Generate a random number between 0 and min, using guard object for special cases.
* @param min - The upper bound (exclusive).
* @param index - The index or key to check in the guard object.
* @param guard - The guard object to validate the parameters.
* @returns A random number between 0 and min.
* @example
* const guard = { 5: 5 };
* random(5, 5, guard); // Returns a random number between 0 and 5
*/
declare function random(min: number, index: string | number, guard: object): number;
//#endregion
export { random };

View file

@ -0,0 +1,58 @@
const require_random = require("../../math/random.js");
const require_randomInt = require("../../math/randomInt.js");
const require_clamp = require("./clamp.js");
//#region src/compat/math/random.ts
/**
* Generate a random number within the given range.
*
* @param minimum - The lower bound (inclusive).
* @param maximum - The upper bound (exclusive).
* @returns A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
*
* @example
* const result1 = random(0, 5); // Returns a random number between 0 and 5.
* const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown.
* const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
*/
function random(...args) {
let minimum = 0;
let maximum = 1;
let floating = false;
switch (args.length) {
case 1:
if (typeof args[0] === "boolean") floating = args[0];
else maximum = args[0];
break;
case 2: if (typeof args[1] === "boolean") {
maximum = args[0];
floating = args[1];
break;
} else {
minimum = args[0];
maximum = args[1];
}
case 3: if (typeof args[2] === "object" && args[2] != null && args[2][args[1]] === args[0]) {
minimum = 0;
maximum = args[0];
floating = false;
} else {
minimum = args[0];
maximum = args[1];
floating = args[2];
}
}
if (typeof minimum !== "number") minimum = Number(minimum);
if (typeof maximum !== "number") maximum = Number(maximum);
if (!minimum) minimum = 0;
if (!maximum) maximum = 0;
if (minimum > maximum) [minimum, maximum] = [maximum, minimum];
if (!floating && (!Number.isInteger(minimum) || !Number.isInteger(maximum))) floating = true;
minimum = require_clamp.clamp(minimum, -Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
maximum = require_clamp.clamp(maximum, -Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
if (minimum === maximum) return minimum;
if (floating) return require_random.random(minimum, maximum);
else return require_randomInt.randomInt(minimum, maximum + 1);
}
//#endregion
exports.random = random;

View file

@ -0,0 +1,58 @@
import { random as random$1 } from "../../math/random.mjs";
import { randomInt } from "../../math/randomInt.mjs";
import { clamp } from "./clamp.mjs";
//#region src/compat/math/random.ts
/**
* Generate a random number within the given range.
*
* @param minimum - The lower bound (inclusive).
* @param maximum - The upper bound (exclusive).
* @returns A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
*
* @example
* const result1 = random(0, 5); // Returns a random number between 0 and 5.
* const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown.
* const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
*/
function random(...args) {
let minimum = 0;
let maximum = 1;
let floating = false;
switch (args.length) {
case 1:
if (typeof args[0] === "boolean") floating = args[0];
else maximum = args[0];
break;
case 2: if (typeof args[1] === "boolean") {
maximum = args[0];
floating = args[1];
break;
} else {
minimum = args[0];
maximum = args[1];
}
case 3: if (typeof args[2] === "object" && args[2] != null && args[2][args[1]] === args[0]) {
minimum = 0;
maximum = args[0];
floating = false;
} else {
minimum = args[0];
maximum = args[1];
floating = args[2];
}
}
if (typeof minimum !== "number") minimum = Number(minimum);
if (typeof maximum !== "number") maximum = Number(maximum);
if (!minimum) minimum = 0;
if (!maximum) maximum = 0;
if (minimum > maximum) [minimum, maximum] = [maximum, minimum];
if (!floating && (!Number.isInteger(minimum) || !Number.isInteger(maximum))) floating = true;
minimum = clamp(minimum, -Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
maximum = clamp(maximum, -Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
if (minimum === maximum) return minimum;
if (floating) return random$1(minimum, maximum);
else return randomInt(minimum, maximum + 1);
}
//#endregion
export { random };

View file

@ -0,0 +1,34 @@
//#region src/compat/math/range.d.ts
/**
* Creates an array of numbers progressing from `start` up to, but not including, `end`.
*
* @param start - The starting number of the range (inclusive)
* @param end - The end number of the range (exclusive)
* @param step - The value to increment or decrement by
* @returns An array of numbers from start to end
* @example
* range(4)
* // => [0, 1, 2, 3]
*
* range(1, 5)
* // => [1, 2, 3, 4]
*
* range(0, 20, 5)
* // => [0, 5, 10, 15]
*/
declare function range(start: number, end?: number, step?: number): number[];
/**
* Creates an array of numbers progressing from 0 up to, but not including, `end`.
* Used internally when range is called as an iteratee.
*
* @param end - The end of the range (exclusive)
* @param index - The index argument passed to the iteratee
* @param guard - The guard object passed to the iteratee
* @returns An array of numbers from 0 to end
* @example
* [1, 2, 3].map(range)
* // => [[0], [0, 1], [0, 1, 2]]
*/
declare function range(end: number, index: string | number, guard: object): number[];
//#endregion
export { range };

View file

@ -0,0 +1,34 @@
//#region src/compat/math/range.d.ts
/**
* Creates an array of numbers progressing from `start` up to, but not including, `end`.
*
* @param start - The starting number of the range (inclusive)
* @param end - The end number of the range (exclusive)
* @param step - The value to increment or decrement by
* @returns An array of numbers from start to end
* @example
* range(4)
* // => [0, 1, 2, 3]
*
* range(1, 5)
* // => [1, 2, 3, 4]
*
* range(0, 20, 5)
* // => [0, 5, 10, 15]
*/
declare function range(start: number, end?: number, step?: number): number[];
/**
* Creates an array of numbers progressing from 0 up to, but not including, `end`.
* Used internally when range is called as an iteratee.
*
* @param end - The end of the range (exclusive)
* @param index - The index argument passed to the iteratee
* @param guard - The guard object passed to the iteratee
* @returns An array of numbers from 0 to end
* @example
* [1, 2, 3].map(range)
* // => [[0], [0, 1], [0, 1, 2]]
*/
declare function range(end: number, index: string | number, guard: object): number[];
//#endregion
export { range };

View file

@ -0,0 +1,37 @@
const require_toFinite = require("../util/toFinite.js");
const require_isIterateeCall = require("../_internal/isIterateeCall.js");
//#region src/compat/math/range.ts
/**
* Returns an array of numbers from `start` (inclusive) to `end` (exclusive), incrementing by `step`.
*
* @param start - The starting number of the range (inclusive).
* @param end - The end number of the range (exclusive).
* @param step - The step value for the range.
* @returns An array of numbers from `start` (inclusive) to `end` (exclusive) with the specified `step`.
*
* @example
* // Returns [0, 1, 2, 3]
* range(4);
*
* @example
* // Returns [0, -1, -2, -3]
* range(0, -4, -1);
*/
function range(start, end, step) {
if (step && typeof step !== "number" && require_isIterateeCall.isIterateeCall(start, end, step)) end = step = void 0;
start = require_toFinite.toFinite(start);
if (end === void 0) {
end = start;
start = 0;
} else end = require_toFinite.toFinite(end);
step = step === void 0 ? start < end ? 1 : -1 : require_toFinite.toFinite(step);
const length = Math.max(Math.ceil((end - start) / (step || 1)), 0);
const result = new Array(length);
for (let index = 0; index < length; index++) {
result[index] = start;
start += step;
}
return result;
}
//#endregion
exports.range = range;

View file

@ -0,0 +1,37 @@
import { toFinite } from "../util/toFinite.mjs";
import { isIterateeCall } from "../_internal/isIterateeCall.mjs";
//#region src/compat/math/range.ts
/**
* Returns an array of numbers from `start` (inclusive) to `end` (exclusive), incrementing by `step`.
*
* @param start - The starting number of the range (inclusive).
* @param end - The end number of the range (exclusive).
* @param step - The step value for the range.
* @returns An array of numbers from `start` (inclusive) to `end` (exclusive) with the specified `step`.
*
* @example
* // Returns [0, 1, 2, 3]
* range(4);
*
* @example
* // Returns [0, -1, -2, -3]
* range(0, -4, -1);
*/
function range(start, end, step) {
if (step && typeof step !== "number" && isIterateeCall(start, end, step)) end = step = void 0;
start = toFinite(start);
if (end === void 0) {
end = start;
start = 0;
} else end = toFinite(end);
step = step === void 0 ? start < end ? 1 : -1 : toFinite(step);
const length = Math.max(Math.ceil((end - start) / (step || 1)), 0);
const result = new Array(length);
for (let index = 0; index < length; index++) {
result[index] = start;
start += step;
}
return result;
}
//#endregion
export { range };

View file

@ -0,0 +1,32 @@
//#region src/compat/math/rangeRight.d.ts
/**
* Creates an array of numbers from `start` to `end` with optional `step`.
* @param start - The starting number of the range (inclusive).
* @param [end] - The end number of the range (exclusive).
* @param [step] - The step value for the range.
* @returns An array of numbers from `start` to `end` with the specified `step`.
* @example
* // Returns [0, 1, 2, 3]
* rangeRight(4);
* @example
* // Returns [0, 2, 4, 6]
* rangeRight(0, 8, 2);
* @example
* // Returns [5, 4, 3, 2, 1]
* rangeRight(1, 6);
*/
declare function rangeRight(start: number, end?: number, step?: number): number[];
/**
* Creates an array of numbers from 0 to `end` with step 1.
* Used when called as an iteratee for methods like `_.map`.
* @param end - The end number of the range (exclusive).
* @param index - The index parameter (used for iteratee calls).
* @param guard - The guard parameter (used for iteratee calls).
* @returns An array of numbers from 0 to `end` with step 1.
* @example
* // Returns [0, 1, 2, 3]
* rangeRight(4, 'index', {});
*/
declare function rangeRight(end: number, index: string | number, guard: object): number[];
//#endregion
export { rangeRight };

View file

@ -0,0 +1,32 @@
//#region src/compat/math/rangeRight.d.ts
/**
* Creates an array of numbers from `start` to `end` with optional `step`.
* @param start - The starting number of the range (inclusive).
* @param [end] - The end number of the range (exclusive).
* @param [step] - The step value for the range.
* @returns An array of numbers from `start` to `end` with the specified `step`.
* @example
* // Returns [0, 1, 2, 3]
* rangeRight(4);
* @example
* // Returns [0, 2, 4, 6]
* rangeRight(0, 8, 2);
* @example
* // Returns [5, 4, 3, 2, 1]
* rangeRight(1, 6);
*/
declare function rangeRight(start: number, end?: number, step?: number): number[];
/**
* Creates an array of numbers from 0 to `end` with step 1.
* Used when called as an iteratee for methods like `_.map`.
* @param end - The end number of the range (exclusive).
* @param index - The index parameter (used for iteratee calls).
* @param guard - The guard parameter (used for iteratee calls).
* @returns An array of numbers from 0 to `end` with step 1.
* @example
* // Returns [0, 1, 2, 3]
* rangeRight(4, 'index', {});
*/
declare function rangeRight(end: number, index: string | number, guard: object): number[];
//#endregion
export { rangeRight };

View file

@ -0,0 +1,38 @@
const require_toFinite = require("../util/toFinite.js");
const require_isIterateeCall = require("../_internal/isIterateeCall.js");
//#region src/compat/math/rangeRight.ts
/**
* Returns an array of numbers from `end` (exclusive) to `start` (inclusive), decrementing by `step`.
*
* @param start - The starting number of the range (inclusive).
* @param end - The end number of the range (exclusive).
* @param step - The step value for the range.
* @returns An array of numbers from `end` (exclusive) to `start` (inclusive) with the specified `step`.
* @throws {Error} Throws an error if the step value is not a non-zero integer.
*
* @example
* // Returns [3, 2, 1, 0]
* rangeRight(4);
*
* @example
* // Returns [-3, -2, -1, 0]
* rangeRight(0, -4, -1);
*/
function rangeRight(start, end, step) {
if (step && typeof step !== "number" && require_isIterateeCall.isIterateeCall(start, end, step)) end = step = void 0;
start = require_toFinite.toFinite(start);
if (end === void 0) {
end = start;
start = 0;
} else end = require_toFinite.toFinite(end);
step = step === void 0 ? start < end ? 1 : -1 : require_toFinite.toFinite(step);
const length = Math.max(Math.ceil((end - start) / (step || 1)), 0);
const result = new Array(length);
for (let index = length - 1; index >= 0; index--) {
result[index] = start;
start += step;
}
return result;
}
//#endregion
exports.rangeRight = rangeRight;

View file

@ -0,0 +1,38 @@
import { toFinite } from "../util/toFinite.mjs";
import { isIterateeCall } from "../_internal/isIterateeCall.mjs";
//#region src/compat/math/rangeRight.ts
/**
* Returns an array of numbers from `end` (exclusive) to `start` (inclusive), decrementing by `step`.
*
* @param start - The starting number of the range (inclusive).
* @param end - The end number of the range (exclusive).
* @param step - The step value for the range.
* @returns An array of numbers from `end` (exclusive) to `start` (inclusive) with the specified `step`.
* @throws {Error} Throws an error if the step value is not a non-zero integer.
*
* @example
* // Returns [3, 2, 1, 0]
* rangeRight(4);
*
* @example
* // Returns [-3, -2, -1, 0]
* rangeRight(0, -4, -1);
*/
function rangeRight(start, end, step) {
if (step && typeof step !== "number" && isIterateeCall(start, end, step)) end = step = void 0;
start = toFinite(start);
if (end === void 0) {
end = start;
start = 0;
} else end = toFinite(end);
step = step === void 0 ? start < end ? 1 : -1 : toFinite(step);
const length = Math.max(Math.ceil((end - start) / (step || 1)), 0);
const result = new Array(length);
for (let index = length - 1; index >= 0; index--) {
result[index] = start;
start += step;
}
return result;
}
//#endregion
export { rangeRight };

View file

@ -0,0 +1,16 @@
//#region src/compat/math/round.d.ts
/**
* Computes number rounded to precision.
*
* @param number The number to round.
* @param precision The precision to round to.
* @returns Returns the rounded number.
*
* @example
* round(4.006); // => 4
* round(4.006, 2); // => 4.01
* round(4060, -2); // => 4100
*/
declare function round(number: number, precision?: number): number;
//#endregion
export { round };

View file

@ -0,0 +1,16 @@
//#region src/compat/math/round.d.ts
/**
* Computes number rounded to precision.
*
* @param number The number to round.
* @param precision The precision to round to.
* @returns Returns the rounded number.
*
* @example
* round(4.006); // => 4
* round(4.006, 2); // => 4.01
* round(4060, -2); // => 4100
*/
declare function round(number: number, precision?: number): number;
//#endregion
export { round };

View file

@ -0,0 +1,19 @@
const require_decimalAdjust = require("../_internal/decimalAdjust.js");
//#region src/compat/math/round.ts
/**
* Computes number rounded to precision.
*
* @param number The number to round.
* @param precision The precision to round to.
* @returns Returns the rounded number.
*
* @example
* round(4.006); // => 4
* round(4.006, 2); // => 4.01
* round(4060, -2); // => 4100
*/
function round(number, precision = 0) {
return require_decimalAdjust.decimalAdjust("round", number, precision);
}
//#endregion
exports.round = round;

View file

@ -0,0 +1,19 @@
import { decimalAdjust } from "../_internal/decimalAdjust.mjs";
//#region src/compat/math/round.ts
/**
* Computes number rounded to precision.
*
* @param number The number to round.
* @param precision The precision to round to.
* @returns Returns the rounded number.
*
* @example
* round(4.006); // => 4
* round(4.006, 2); // => 4.01
* round(4060, -2); // => 4100
*/
function round(number, precision = 0) {
return decimalAdjust("round", number, precision);
}
//#endregion
export { round };

View file

@ -0,0 +1,18 @@
//#region src/compat/math/subtract.d.ts
/**
* Subtracts one number from another.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number. (minuend)
* @param other The second number.(subtrahend)
* @returns The difference of the two numbers, or `NaN` if any input is `NaN`.
*
* @example
* subtract(6, 3); // => 3
* subtract(6, NaN); // => NaN
* subtract(NaN, 3); // => NaN
*/
declare function subtract(value: number, other: number): number;
//#endregion
export { subtract };

View file

@ -0,0 +1,18 @@
//#region src/compat/math/subtract.d.ts
/**
* Subtracts one number from another.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number. (minuend)
* @param other The second number.(subtrahend)
* @returns The difference of the two numbers, or `NaN` if any input is `NaN`.
*
* @example
* subtract(6, 3); // => 3
* subtract(6, NaN); // => NaN
* subtract(NaN, 3); // => NaN
*/
declare function subtract(value: number, other: number): number;
//#endregion
export { subtract };

View file

@ -0,0 +1,31 @@
const require_toString = require("../util/toString.js");
const require_toNumber = require("../util/toNumber.js");
//#region src/compat/math/subtract.ts
/**
* Subtracts one number from another.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number. (minuend)
* @param other The second number.(subtrahend)
* @returns The difference of the two numbers, or `NaN` if any input is `NaN`.
*
* @example
* subtract(6, 3); // => 3
* subtract(6, NaN); // => NaN
* subtract(NaN, 3); // => NaN
*/
function subtract(value, other) {
if (value === void 0 && other === void 0) return 0;
if (value === void 0 || other === void 0) return value ?? other;
if (typeof value === "string" || typeof other === "string") {
value = require_toString.toString(value);
other = require_toString.toString(other);
} else {
value = require_toNumber.toNumber(value);
other = require_toNumber.toNumber(other);
}
return value - other;
}
//#endregion
exports.subtract = subtract;

View file

@ -0,0 +1,31 @@
import { toString } from "../util/toString.mjs";
import { toNumber } from "../util/toNumber.mjs";
//#region src/compat/math/subtract.ts
/**
* Subtracts one number from another.
*
* If either of the numbers is `NaN`, the function returns `NaN`.
*
* @param value The first number. (minuend)
* @param other The second number.(subtrahend)
* @returns The difference of the two numbers, or `NaN` if any input is `NaN`.
*
* @example
* subtract(6, 3); // => 3
* subtract(6, NaN); // => NaN
* subtract(NaN, 3); // => NaN
*/
function subtract(value, other) {
if (value === void 0 && other === void 0) return 0;
if (value === void 0 || other === void 0) return value ?? other;
if (typeof value === "string" || typeof other === "string") {
value = toString(value);
other = toString(other);
} else {
value = toNumber(value);
other = toNumber(other);
}
return value - other;
}
//#endregion
export { subtract };

View file

@ -0,0 +1,20 @@
//#region src/compat/math/sum.d.ts
/**
* Computes the sum of the values that are returned by the `iteratee` function.
*
* It does not coerce values to `number`.
*
* @param array - The array to iterate over.
* @returns Returns the sum.
*
* @example
* sum([1, 2, 3]); // => 6
* sum([1n, 2n, 3n]); // => 6n
* sum(["1", "2"]); // => "12"
* sum([1, undefined, 2]); // => 3
* sum(null); // => 0
* sum(undefined); // => 0
*/
declare function sum(array: ArrayLike<any> | null | undefined): number;
//#endregion
export { sum };

View file

@ -0,0 +1,20 @@
//#region src/compat/math/sum.d.ts
/**
* Computes the sum of the values that are returned by the `iteratee` function.
*
* It does not coerce values to `number`.
*
* @param array - The array to iterate over.
* @returns Returns the sum.
*
* @example
* sum([1, 2, 3]); // => 6
* sum([1n, 2n, 3n]); // => 6n
* sum(["1", "2"]); // => "12"
* sum([1, undefined, 2]); // => 3
* sum(null); // => 0
* sum(undefined); // => 0
*/
declare function sum(array: ArrayLike<any> | null | undefined): number;
//#endregion
export { sum };

View file

@ -0,0 +1,23 @@
const require_sumBy = require("./sumBy.js");
//#region src/compat/math/sum.ts
/**
* Computes the sum of the values that are returned by the `iteratee` function.
*
* It does not coerce values to `number`.
*
* @param array - The array to iterate over.
* @returns Returns the sum.
*
* @example
* sum([1, 2, 3]); // => 6
* sum([1n, 2n, 3n]); // => 6n
* sum(["1", "2"]); // => "12"
* sum([1, undefined, 2]); // => 3
* sum(null); // => 0
* sum(undefined); // => 0
*/
function sum(array) {
return require_sumBy.sumBy(array);
}
//#endregion
exports.sum = sum;

View file

@ -0,0 +1,23 @@
import { sumBy } from "./sumBy.mjs";
//#region src/compat/math/sum.ts
/**
* Computes the sum of the values that are returned by the `iteratee` function.
*
* It does not coerce values to `number`.
*
* @param array - The array to iterate over.
* @returns Returns the sum.
*
* @example
* sum([1, 2, 3]); // => 6
* sum([1n, 2n, 3n]); // => 6n
* sum(["1", "2"]); // => "12"
* sum([1, undefined, 2]); // => 3
* sum(null); // => 0
* sum(undefined); // => 0
*/
function sum(array) {
return sumBy(array);
}
//#endregion
export { sum };

View file

@ -0,0 +1,22 @@
//#region src/compat/math/sumBy.d.ts
/**
* Computes the sum of the values that are returned by the `iteratee` function.
*
* It does not coerce values to `number`.
*
* @template T - The type of the array elements.
* @param array - The array to iterate over.
* @param iteratee - The function invoked per iteration.
* @returns Returns the sum.
*
* @example
* sumBy([1, undefined, 2], value => value); // => 3
* sumBy(null); // => 0
* sumBy(undefined); // => 0
* sumBy([1, 2, 3]); // => 6
* sumBy([1n, 2n, 3n]); // => 6n
* sumBy([{ a: "1" }, { a: "2" }], object => object.a); // => "12"
*/
declare function sumBy<T>(array: ArrayLike<T> | null | undefined, iteratee?: ((value: T) => number) | string): number;
//#endregion
export { sumBy };

View file

@ -0,0 +1,22 @@
//#region src/compat/math/sumBy.d.ts
/**
* Computes the sum of the values that are returned by the `iteratee` function.
*
* It does not coerce values to `number`.
*
* @template T - The type of the array elements.
* @param array - The array to iterate over.
* @param iteratee - The function invoked per iteration.
* @returns Returns the sum.
*
* @example
* sumBy([1, undefined, 2], value => value); // => 3
* sumBy(null); // => 0
* sumBy(undefined); // => 0
* sumBy([1, 2, 3]); // => 6
* sumBy([1n, 2n, 3n]); // => 6n
* sumBy([{ a: "1" }, { a: "2" }], object => object.a); // => "12"
*/
declare function sumBy<T>(array: ArrayLike<T> | null | undefined, iteratee?: ((value: T) => number) | string): number;
//#endregion
export { sumBy };

View file

@ -0,0 +1,33 @@
const require_iteratee = require("../util/iteratee.js");
//#region src/compat/math/sumBy.ts
/**
* Computes the sum of the values that are returned by the `iteratee` function.
*
* It does not coerce values to `number`.
*
* @template T - The type of the array elements.
* @param array - The array to iterate over.
* @param iteratee - The function invoked per iteration.
* @returns Returns the sum.
*
* @example
* sumBy([1, undefined, 2], value => value); // => 3
* sumBy(null); // => 0
* sumBy(undefined); // => 0
* sumBy([1, 2, 3]); // => 6
* sumBy([1n, 2n, 3n]); // => 6n
* sumBy([{ a: "1" }, { a: "2" }], object => object.a); // => "12"
*/
function sumBy(array, iteratee$1) {
if (!array || !array.length) return 0;
if (iteratee$1 != null) iteratee$1 = require_iteratee.iteratee(iteratee$1);
let result = void 0;
for (let i = 0; i < array.length; i++) {
const current = iteratee$1 ? iteratee$1(array[i]) : array[i];
if (current !== void 0) if (result === void 0) result = current;
else result += current;
}
return result;
}
//#endregion
exports.sumBy = sumBy;

View file

@ -0,0 +1,33 @@
import { iteratee } from "../util/iteratee.mjs";
//#region src/compat/math/sumBy.ts
/**
* Computes the sum of the values that are returned by the `iteratee` function.
*
* It does not coerce values to `number`.
*
* @template T - The type of the array elements.
* @param array - The array to iterate over.
* @param iteratee - The function invoked per iteration.
* @returns Returns the sum.
*
* @example
* sumBy([1, undefined, 2], value => value); // => 3
* sumBy(null); // => 0
* sumBy(undefined); // => 0
* sumBy([1, 2, 3]); // => 6
* sumBy([1n, 2n, 3n]); // => 6n
* sumBy([{ a: "1" }, { a: "2" }], object => object.a); // => "12"
*/
function sumBy(array, iteratee$1) {
if (!array || !array.length) return 0;
if (iteratee$1 != null) iteratee$1 = iteratee(iteratee$1);
let result = void 0;
for (let i = 0; i < array.length; i++) {
const current = iteratee$1 ? iteratee$1(array[i]) : array[i];
if (current !== void 0) if (result === void 0) result = current;
else result += current;
}
return result;
}
//#endregion
export { sumBy };