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,32 @@
import { Many } from "../_internal/Many.mjs";
//#region src/compat/util/bindAll.d.ts
/**
* Binds methods of an object to the object itself, overwriting the existing method.
* Method names may be specified as individual arguments or as arrays of method names.
*
* @template T - The type of the object.
* @param object - The object to bind methods to.
* @param [methodNames] - The method names to bind, specified individually or in arrays.
* @returns Returns the object.
*
* @example
* const view = {
* 'label': 'docs',
* 'click': function() {
* console.log('clicked ' + this.label);
* }
* };
*
* bindAll(view, ['click']);
* jQuery(element).on('click', view.click);
* // => Logs 'clicked docs' when clicked.
*
* @example
* // Using individual method names
* bindAll(view, 'click');
* // => Same as above
*/
declare function bindAll<T>(object: T, ...methodNames: Array<Many<string>>): T;
//#endregion
export { bindAll };

View file

@ -0,0 +1,32 @@
import { Many } from "../_internal/Many.js";
//#region src/compat/util/bindAll.d.ts
/**
* Binds methods of an object to the object itself, overwriting the existing method.
* Method names may be specified as individual arguments or as arrays of method names.
*
* @template T - The type of the object.
* @param object - The object to bind methods to.
* @param [methodNames] - The method names to bind, specified individually or in arrays.
* @returns Returns the object.
*
* @example
* const view = {
* 'label': 'docs',
* 'click': function() {
* console.log('clicked ' + this.label);
* }
* };
*
* bindAll(view, ['click']);
* jQuery(element).on('click', view.click);
* // => Logs 'clicked docs' when clicked.
*
* @example
* // Using individual method names
* bindAll(view, 'click');
* // => Same as above
*/
declare function bindAll<T>(object: T, ...methodNames: Array<Many<string>>): T;
//#endregion
export { bindAll };

View file

@ -0,0 +1,53 @@
const require_isArray = require("../predicate/isArray.js");
const require_isFunction = require("../../predicate/isFunction.js");
const require_toString = require("./toString.js");
const require_isObject = require("../predicate/isObject.js");
//#region src/compat/util/bindAll.ts
/**
* Binds methods of an object to the object itself, overwriting the existing method.
* Method names may be specified as individual arguments or as arrays of method names.
*
* @template T - The type of the object.
* @param object - The object to bind methods to.
* @param [methodNames] - The method names to bind, specified individually or in arrays.
* @returns Returns the object.
*
* @example
* const view = {
* 'label': 'docs',
* 'click': function() {
* console.log('clicked ' + this.label);
* }
* };
*
* bindAll(view, ['click']);
* jQuery(element).on('click', view.click);
* // => Logs 'clicked docs' when clicked.
*
* @example
* // Using individual method names
* bindAll(view, 'click');
* // => Same as above
*/
function bindAll(object, ...methodNames) {
if (object == null) return object;
if (!require_isObject.isObject(object)) return object;
if (require_isArray.isArray(object) && methodNames.length === 0) return object;
const methods = [];
for (let i = 0; i < methodNames.length; i++) {
const name = methodNames[i];
if (require_isArray.isArray(name)) methods.push(...name);
else if (name && typeof name === "object" && "length" in name) methods.push(...Array.from(name));
else methods.push(name);
}
if (methods.length === 0) return object;
for (let i = 0; i < methods.length; i++) {
const key = methods[i];
const stringKey = require_toString.toString(key);
const func = object[stringKey];
if (require_isFunction.isFunction(func)) object[stringKey] = func.bind(object);
}
return object;
}
//#endregion
exports.bindAll = bindAll;

View file

@ -0,0 +1,53 @@
import { isArray } from "../predicate/isArray.mjs";
import { isFunction } from "../../predicate/isFunction.mjs";
import { toString } from "./toString.mjs";
import { isObject } from "../predicate/isObject.mjs";
//#region src/compat/util/bindAll.ts
/**
* Binds methods of an object to the object itself, overwriting the existing method.
* Method names may be specified as individual arguments or as arrays of method names.
*
* @template T - The type of the object.
* @param object - The object to bind methods to.
* @param [methodNames] - The method names to bind, specified individually or in arrays.
* @returns Returns the object.
*
* @example
* const view = {
* 'label': 'docs',
* 'click': function() {
* console.log('clicked ' + this.label);
* }
* };
*
* bindAll(view, ['click']);
* jQuery(element).on('click', view.click);
* // => Logs 'clicked docs' when clicked.
*
* @example
* // Using individual method names
* bindAll(view, 'click');
* // => Same as above
*/
function bindAll(object, ...methodNames) {
if (object == null) return object;
if (!isObject(object)) return object;
if (isArray(object) && methodNames.length === 0) return object;
const methods = [];
for (let i = 0; i < methodNames.length; i++) {
const name = methodNames[i];
if (isArray(name)) methods.push(...name);
else if (name && typeof name === "object" && "length" in name) methods.push(...Array.from(name));
else methods.push(name);
}
if (methods.length === 0) return object;
for (let i = 0; i < methods.length; i++) {
const key = methods[i];
const stringKey = toString(key);
const func = object[stringKey];
if (isFunction(func)) object[stringKey] = func.bind(object);
}
return object;
}
//#endregion
export { bindAll };

View file

@ -0,0 +1,59 @@
//#region src/compat/util/cond.d.ts
/**
* Creates a function that checks conditions one by one and runs the matching function.
*
* Each pair consists of a condition (predicate) and a function to run.
* The function goes through each condition in order until it finds one that's true.
* When it finds a true condition, it runs the corresponding function and returns its result.
* If none of the conditions are true, it returns undefined.
*
* @param pairs - Array of pairs. Each pair consists of a predicate function and a function to run.
* @returns A new composite function that checks conditions and runs the matching function.
* @example
*
* const func = cond([
* [matches({ a: 1 }), constant('matches A')],
* [conforms({ b: isNumber }), constant('matches B')],
* [stubTrue, constant('no match')]
* ]);
*
* func({ a: 1, b: 2 });
* // => 'matches A'
*
* func({ a: 0, b: 1 });
* // => 'matches B'
*
* func({ a: '1', b: '2' });
* // => 'no match'
*/
declare function cond<R>(pairs: Array<[truthy: () => boolean, falsey: () => R]>): () => R;
/**
* Creates a function that checks conditions one by one and runs the matching function.
*
* Each pair consists of a condition (predicate) and a function to run.
* The function goes through each condition in order until it finds one that's true.
* When it finds a true condition, it runs the corresponding function and returns its result.
* If none of the conditions are true, it returns undefined.
*
* @param pairs - Array of pairs. Each pair consists of a predicate function and a function to run.
* @returns A new composite function that checks conditions and runs the matching function.
* @example
*
* const func = cond([
* [matches({ a: 1 }), constant('matches A')],
* [conforms({ b: isNumber }), constant('matches B')],
* [stubTrue, constant('no match')]
* ]);
*
* func({ a: 1, b: 2 });
* // => 'matches A'
*
* func({ a: 0, b: 1 });
* // => 'matches B'
*
* func({ a: '1', b: '2' });
* // => 'no match'
*/
declare function cond<T, R>(pairs: Array<[truthy: (val: T) => boolean, falsey: (val: T) => R]>): (val: T) => R;
//#endregion
export { cond };

View file

@ -0,0 +1,59 @@
//#region src/compat/util/cond.d.ts
/**
* Creates a function that checks conditions one by one and runs the matching function.
*
* Each pair consists of a condition (predicate) and a function to run.
* The function goes through each condition in order until it finds one that's true.
* When it finds a true condition, it runs the corresponding function and returns its result.
* If none of the conditions are true, it returns undefined.
*
* @param pairs - Array of pairs. Each pair consists of a predicate function and a function to run.
* @returns A new composite function that checks conditions and runs the matching function.
* @example
*
* const func = cond([
* [matches({ a: 1 }), constant('matches A')],
* [conforms({ b: isNumber }), constant('matches B')],
* [stubTrue, constant('no match')]
* ]);
*
* func({ a: 1, b: 2 });
* // => 'matches A'
*
* func({ a: 0, b: 1 });
* // => 'matches B'
*
* func({ a: '1', b: '2' });
* // => 'no match'
*/
declare function cond<R>(pairs: Array<[truthy: () => boolean, falsey: () => R]>): () => R;
/**
* Creates a function that checks conditions one by one and runs the matching function.
*
* Each pair consists of a condition (predicate) and a function to run.
* The function goes through each condition in order until it finds one that's true.
* When it finds a true condition, it runs the corresponding function and returns its result.
* If none of the conditions are true, it returns undefined.
*
* @param pairs - Array of pairs. Each pair consists of a predicate function and a function to run.
* @returns A new composite function that checks conditions and runs the matching function.
* @example
*
* const func = cond([
* [matches({ a: 1 }), constant('matches A')],
* [conforms({ b: isNumber }), constant('matches B')],
* [stubTrue, constant('no match')]
* ]);
*
* func({ a: 1, b: 2 });
* // => 'matches A'
*
* func({ a: 0, b: 1 });
* // => 'matches B'
*
* func({ a: '1', b: '2' });
* // => 'no match'
*/
declare function cond<T, R>(pairs: Array<[truthy: (val: T) => boolean, falsey: (val: T) => R]>): (val: T) => R;
//#endregion
export { cond };

View file

@ -0,0 +1,22 @@
const require_isFunction = require("../../predicate/isFunction.js");
const require_iteratee = require("./iteratee.js");
//#region src/compat/util/cond.ts
function cond(pairs) {
const length = pairs.length;
const processedPairs = pairs.map((pair) => {
const predicate = pair[0];
const func = pair[1];
if (!require_isFunction.isFunction(func)) throw new TypeError("Expected a function");
return [require_iteratee.iteratee(predicate), func];
});
return function(...args) {
for (let i = 0; i < length; i++) {
const pair = processedPairs[i];
const predicate = pair[0];
const func = pair[1];
if (predicate.apply(this, args)) return func.apply(this, args);
}
};
}
//#endregion
exports.cond = cond;

View file

@ -0,0 +1,22 @@
import { isFunction } from "../../predicate/isFunction.mjs";
import { iteratee } from "./iteratee.mjs";
//#region src/compat/util/cond.ts
function cond(pairs) {
const length = pairs.length;
const processedPairs = pairs.map((pair) => {
const predicate = pair[0];
const func = pair[1];
if (!isFunction(func)) throw new TypeError("Expected a function");
return [iteratee(predicate), func];
});
return function(...args) {
for (let i = 0; i < length; i++) {
const pair = processedPairs[i];
const predicate = pair[0];
const func = pair[1];
if (predicate.apply(this, args)) return func.apply(this, args);
}
};
}
//#endregion
export { cond };

View file

@ -0,0 +1,11 @@
//#region src/compat/util/constant.d.ts
/**
* Creates a new function that always returns `value`.
*
* @template T - The type of the value to return.
* @param value - The value to return from the new function.
* @returns Returns the new constant function.
*/
declare function constant<T>(value: T): () => T;
//#endregion
export { constant };

View file

@ -0,0 +1,11 @@
//#region src/compat/util/constant.d.ts
/**
* Creates a new function that always returns `value`.
*
* @template T - The type of the value to return.
* @param value - The value to return from the new function.
* @returns Returns the new constant function.
*/
declare function constant<T>(value: T): () => T;
//#endregion
export { constant };

View file

@ -0,0 +1,20 @@
//#region src/compat/util/constant.ts
/**
* Creates a new function that always returns `value`.
*
* @template T - The type of the value to return.
* @param value - The value to return from the new function.
* @returns Returns the new constant function.
*
* @example
* const object = { a: 1 };
* const returnsObject = constant(object);
*
* returnsObject(); // => { a: 1 }
* returnsObject() === object; // => true
*/
function constant(value) {
return () => value;
}
//#endregion
exports.constant = constant;

View file

@ -0,0 +1,20 @@
//#region src/compat/util/constant.ts
/**
* Creates a new function that always returns `value`.
*
* @template T - The type of the value to return.
* @param value - The value to return from the new function.
* @returns Returns the new constant function.
*
* @example
* const object = { a: 1 };
* const returnsObject = constant(object);
*
* returnsObject(); // => { a: 1 }
* returnsObject() === object; // => true
*/
function constant(value) {
return () => value;
}
//#endregion
export { constant };

View file

@ -0,0 +1,22 @@
//#region src/compat/util/defaultTo.d.ts
/**
* Returns the default value for `null`, `undefined`, and `NaN`.
*
* @template T - The type of the value parameter
* @param value - The value to check.
* @param defaultValue - The default value to return if the first value is null, undefined, or NaN.
* @returns Returns either the first value or the default value.
*/
declare function defaultTo<T>(value: T | null | undefined, defaultValue: T): T;
/**
* Returns the default value for `null`, `undefined`, and `NaN`.
*
* @template T - The type of the value parameter
* @template D - The type of the defaultValue parameter
* @param value - The value to check.
* @param defaultValue - The default value to return if the first value is null, undefined, or NaN.
* @returns Returns either the first value or the default value.
*/
declare function defaultTo<T, D>(value: T | null | undefined, defaultValue: D): T | D;
//#endregion
export { defaultTo };

View file

@ -0,0 +1,22 @@
//#region src/compat/util/defaultTo.d.ts
/**
* Returns the default value for `null`, `undefined`, and `NaN`.
*
* @template T - The type of the value parameter
* @param value - The value to check.
* @param defaultValue - The default value to return if the first value is null, undefined, or NaN.
* @returns Returns either the first value or the default value.
*/
declare function defaultTo<T>(value: T | null | undefined, defaultValue: T): T;
/**
* Returns the default value for `null`, `undefined`, and `NaN`.
*
* @template T - The type of the value parameter
* @template D - The type of the defaultValue parameter
* @param value - The value to check.
* @param defaultValue - The default value to return if the first value is null, undefined, or NaN.
* @returns Returns either the first value or the default value.
*/
declare function defaultTo<T, D>(value: T | null | undefined, defaultValue: D): T | D;
//#endregion
export { defaultTo };

View file

@ -0,0 +1,23 @@
//#region src/compat/util/defaultTo.ts
/**
* Returns the default value for `null`, `undefined`, and `NaN`.
*
* @template T - The type of the value parameter
* @template D - The type of the defaultValue parameter
* @param value - The value to check.
* @param defaultValue - The default value to return if the first value is null, undefined, or NaN.
* @returns Returns either the first value or the default value.
*
* @example
* defaultTo(null, 'default') // returns 'default'
* defaultTo(undefined, 42) // returns 42
* defaultTo(NaN, 0) // returns 0
* defaultTo('actual', 'default') // returns 'actual'
* defaultTo(123, 0) // returns 123
*/
function defaultTo(value, defaultValue) {
if (value == null || Number.isNaN(value)) return defaultValue;
return value;
}
//#endregion
exports.defaultTo = defaultTo;

View file

@ -0,0 +1,23 @@
//#region src/compat/util/defaultTo.ts
/**
* Returns the default value for `null`, `undefined`, and `NaN`.
*
* @template T - The type of the value parameter
* @template D - The type of the defaultValue parameter
* @param value - The value to check.
* @param defaultValue - The default value to return if the first value is null, undefined, or NaN.
* @returns Returns either the first value or the default value.
*
* @example
* defaultTo(null, 'default') // returns 'default'
* defaultTo(undefined, 42) // returns 42
* defaultTo(NaN, 0) // returns 0
* defaultTo('actual', 'default') // returns 'actual'
* defaultTo(123, 0) // returns 123
*/
function defaultTo(value, defaultValue) {
if (value == null || Number.isNaN(value)) return defaultValue;
return value;
}
//#endregion
export { defaultTo };

View file

@ -0,0 +1 @@
import { isEqualsSameValueZero } from "../../_internal/isEqualsSameValueZero.mjs";

View file

@ -0,0 +1 @@
import { isEqualsSameValueZero } from "../../_internal/isEqualsSameValueZero.js";

View file

@ -0,0 +1 @@
require("../../_internal/isEqualsSameValueZero.js");

View file

@ -0,0 +1 @@
import "../../_internal/isEqualsSameValueZero.mjs";

View file

@ -0,0 +1,16 @@
//#region src/compat/util/gt.d.ts
/**
* Checks if value is greater than other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is greater than other, else `false`.
*
* @example
* gt(3, 1); // true
* gt(3, 3); // false
* gt(1, 3); // false
*/
declare function gt(value: any, other: any): boolean;
//#endregion
export { gt };

View file

@ -0,0 +1,16 @@
//#region src/compat/util/gt.d.ts
/**
* Checks if value is greater than other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is greater than other, else `false`.
*
* @example
* gt(3, 1); // true
* gt(3, 3); // false
* gt(1, 3); // false
*/
declare function gt(value: any, other: any): boolean;
//#endregion
export { gt };

View file

@ -0,0 +1,20 @@
const require_toNumber = require("./toNumber.js");
//#region src/compat/util/gt.ts
/**
* Checks if value is greater than other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is greater than other, else `false`.
*
* @example
* gt(3, 1); // true
* gt(3, 3); // false
* gt(1, 3); // false
*/
function gt(value, other) {
if (typeof value === "string" && typeof other === "string") return value > other;
return require_toNumber.toNumber(value) > require_toNumber.toNumber(other);
}
//#endregion
exports.gt = gt;

View file

@ -0,0 +1,20 @@
import { toNumber } from "./toNumber.mjs";
//#region src/compat/util/gt.ts
/**
* Checks if value is greater than other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is greater than other, else `false`.
*
* @example
* gt(3, 1); // true
* gt(3, 3); // false
* gt(1, 3); // false
*/
function gt(value, other) {
if (typeof value === "string" && typeof other === "string") return value > other;
return toNumber(value) > toNumber(other);
}
//#endregion
export { gt };

View file

@ -0,0 +1,16 @@
//#region src/compat/util/gte.d.ts
/**
* Checks if value is greater than or equal to other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is greater than or equal to other, else `false`.
*
* @example
* gte(3, 1); // => true
* gte(3, 3); // => true
* gte(1, 3); // => false
*/
declare function gte(value: any, other: any): boolean;
//#endregion
export { gte };

View file

@ -0,0 +1,16 @@
//#region src/compat/util/gte.d.ts
/**
* Checks if value is greater than or equal to other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is greater than or equal to other, else `false`.
*
* @example
* gte(3, 1); // => true
* gte(3, 3); // => true
* gte(1, 3); // => false
*/
declare function gte(value: any, other: any): boolean;
//#endregion
export { gte };

View file

@ -0,0 +1,20 @@
const require_toNumber = require("./toNumber.js");
//#region src/compat/util/gte.ts
/**
* Checks if value is greater than or equal to other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is greater than or equal to other, else `false`.
*
* @example
* gte(3, 1); // => true
* gte(3, 3); // => true
* gte(1, 3); // => false
*/
function gte(value, other) {
if (typeof value === "string" && typeof other === "string") return value >= other;
return require_toNumber.toNumber(value) >= require_toNumber.toNumber(other);
}
//#endregion
exports.gte = gte;

View file

@ -0,0 +1,20 @@
import { toNumber } from "./toNumber.mjs";
//#region src/compat/util/gte.ts
/**
* Checks if value is greater than or equal to other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is greater than or equal to other, else `false`.
*
* @example
* gte(3, 1); // => true
* gte(3, 3); // => true
* gte(1, 3); // => false
*/
function gte(value, other) {
if (typeof value === "string" && typeof other === "string") return value >= other;
return toNumber(value) >= toNumber(other);
}
//#endregion
export { gte };

View file

@ -0,0 +1,24 @@
//#region src/compat/util/invoke.d.ts
/**
* Invokes the method at `path` of `object` with the given arguments.
*
* @param object - The object to query.
* @param path - The path of the method to invoke.
* @param args - The arguments to invoke the method with.
* @returns Returns the result of the invoked method.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* invoke(object, 'a.b', [1, 2]); // => 3
* invoke(object, ['a', 'b'], [1, 2]); // => 3
*/
declare function invoke(object: any, path: PropertyKey | readonly PropertyKey[], ...args: any[]): any;
//#endregion
export { invoke };

View file

@ -0,0 +1,24 @@
//#region src/compat/util/invoke.d.ts
/**
* Invokes the method at `path` of `object` with the given arguments.
*
* @param object - The object to query.
* @param path - The path of the method to invoke.
* @param args - The arguments to invoke the method with.
* @returns Returns the result of the invoked method.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* invoke(object, 'a.b', [1, 2]); // => 3
* invoke(object, ['a', 'b'], [1, 2]); // => 3
*/
declare function invoke(object: any, path: PropertyKey | readonly PropertyKey[], ...args: any[]): any;
//#endregion
export { invoke };

View file

@ -0,0 +1,49 @@
const require_toKey = require("../_internal/toKey.js");
const require_toPath = require("./toPath.js");
const require_get = require("../object/get.js");
const require_last = require("../array/last.js");
//#region src/compat/util/invoke.ts
/**
* Invokes the method at `path` of `object` with the given arguments.
*
* @param object - The object to query.
* @param path - The path of the method to invoke.
* @param args - The arguments to invoke the method with.
* @returns Returns the result of the invoked method.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* invoke(object, 'a.b', [1, 2]); // => 3
* invoke(object, ['a', 'b'], [1, 2]); // => 3
*/
function invoke(object, path, ...args) {
args = args.flat(1);
if (object == null) return;
switch (typeof path) {
case "string":
if (typeof object === "object" && Object.hasOwn(object, path)) return invokeImpl(object, [path], args);
return invokeImpl(object, require_toPath.toPath(path), args);
case "number":
case "symbol": return invokeImpl(object, [path], args);
default: if (Array.isArray(path)) return invokeImpl(object, path, args);
else return invokeImpl(object, [path], args);
}
}
function invokeImpl(object, path, args) {
const parent = require_get.get(object, path.slice(0, -1), object);
if (parent == null) return;
let lastKey = require_last.last(path);
const lastValue = lastKey?.valueOf();
if (typeof lastValue === "number") lastKey = require_toKey.toKey(lastValue);
else lastKey = String(lastKey);
return require_get.get(parent, lastKey)?.apply(parent, args);
}
//#endregion
exports.invoke = invoke;

View file

@ -0,0 +1,49 @@
import { toKey } from "../_internal/toKey.mjs";
import { toPath } from "./toPath.mjs";
import { get } from "../object/get.mjs";
import { last } from "../array/last.mjs";
//#region src/compat/util/invoke.ts
/**
* Invokes the method at `path` of `object` with the given arguments.
*
* @param object - The object to query.
* @param path - The path of the method to invoke.
* @param args - The arguments to invoke the method with.
* @returns Returns the result of the invoked method.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* invoke(object, 'a.b', [1, 2]); // => 3
* invoke(object, ['a', 'b'], [1, 2]); // => 3
*/
function invoke(object, path, ...args) {
args = args.flat(1);
if (object == null) return;
switch (typeof path) {
case "string":
if (typeof object === "object" && Object.hasOwn(object, path)) return invokeImpl(object, [path], args);
return invokeImpl(object, toPath(path), args);
case "number":
case "symbol": return invokeImpl(object, [path], args);
default: if (Array.isArray(path)) return invokeImpl(object, path, args);
else return invokeImpl(object, [path], args);
}
}
function invokeImpl(object, path, args) {
const parent = get(object, path.slice(0, -1), object);
if (parent == null) return;
let lastKey = last(path);
const lastValue = lastKey?.valueOf();
if (typeof lastValue === "number") lastKey = toKey(lastValue);
else lastKey = String(lastKey);
return get(parent, lastKey)?.apply(parent, args);
}
//#endregion
export { invoke };

View file

@ -0,0 +1,34 @@
//#region src/compat/util/iteratee.d.ts
/**
* Returns the provided function as-is when it is a function type.
*
* @template F - The function type
* @param func - The function to return
* @returns Returns the provided function unchanged
*
* @example
* const fn = (x: number) => x * 2;
* const iterateeFn = iteratee(fn);
* iterateeFn(4); // => 8
*/
declare function iteratee<F extends (...args: any[]) => any>(func: F): F;
/**
* Creates an iteratee function based on the provided property key or object.
* If given a property key, returns a function that gets that property from objects.
* If given an object, returns a function that matches objects against the provided one.
*
* @param func - The value to convert to an iteratee
* @returns Returns the iteratee function
*
* @example
* // With property key
* const getLength = iteratee('length');
* getLength([1,2,3]); // => 3
*
* // With object
* const matchObj = iteratee({ x: 1, y: 2 });
* matchObj({ x: 1, y: 2, z: 3 }); // => true
*/
declare function iteratee(func: PropertyKey | object): (...args: any[]) => any;
//#endregion
export { iteratee };

View file

@ -0,0 +1,34 @@
//#region src/compat/util/iteratee.d.ts
/**
* Returns the provided function as-is when it is a function type.
*
* @template F - The function type
* @param func - The function to return
* @returns Returns the provided function unchanged
*
* @example
* const fn = (x: number) => x * 2;
* const iterateeFn = iteratee(fn);
* iterateeFn(4); // => 8
*/
declare function iteratee<F extends (...args: any[]) => any>(func: F): F;
/**
* Creates an iteratee function based on the provided property key or object.
* If given a property key, returns a function that gets that property from objects.
* If given an object, returns a function that matches objects against the provided one.
*
* @param func - The value to convert to an iteratee
* @returns Returns the iteratee function
*
* @example
* // With property key
* const getLength = iteratee('length');
* getLength([1,2,3]); // => 3
*
* // With object
* const matchObj = iteratee({ x: 1, y: 2 });
* matchObj({ x: 1, y: 2, z: 3 }); // => true
*/
declare function iteratee(func: PropertyKey | object): (...args: any[]) => any;
//#endregion
export { iteratee };

View file

@ -0,0 +1,49 @@
const require_identity = require("../../function/identity.js");
const require_property = require("../object/property.js");
const require_matches = require("../predicate/matches.js");
const require_matchesProperty = require("../predicate/matchesProperty.js");
//#region src/compat/util/iteratee.ts
/**
* Creates a function that returns a value from an element in a collection.
*
* You can call `iteratee` with the following types of arguments:
*
* - **Function**: Returns the function as-is, which will be called with the element from the collection.
* - **Property name**: Returns the value of the specified property from the element.
* - **Property-value pair**: Returns a boolean indicating whether the element's property matches the given value.
* - **Partial object**: Returns a boolean indicating whether the element matches the properties of the partial object.
*
* If you don't provide any arguments or pass `null`, this function will return a function that simply returns its input unchanged.
*
* @param value - The value to convert to an iteratee.
* @returns Returns the new iteratee function.
* @example
* const func = iteratee();
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [{ a: 1 }, { a: 2 }, { a: 3 }]
*
* const func = iteratee((object) => object.a);
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
*
* const func = iteratee('a');
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
*
* const func = iteratee({ a: 1 });
* [{ a: 1 }, { a: 2 }, { a: 3 }].find(func) // => { a: 1 }
*
* const func = iteratee(['a', 1]);
* [{ a: 1 }, { a: 2 }, { a: 3 }].find(func) // => { a: 1 }
*/
function iteratee(value) {
if (value == null) return require_identity.identity;
switch (typeof value) {
case "function": return value;
case "object":
if (Array.isArray(value) && value.length === 2) return require_matchesProperty.matchesProperty(value[0], value[1]);
return require_matches.matches(value);
case "string":
case "symbol":
case "number": return require_property.property(value);
}
}
//#endregion
exports.iteratee = iteratee;

View file

@ -0,0 +1,49 @@
import { identity } from "../../function/identity.mjs";
import { property } from "../object/property.mjs";
import { matches } from "../predicate/matches.mjs";
import { matchesProperty } from "../predicate/matchesProperty.mjs";
//#region src/compat/util/iteratee.ts
/**
* Creates a function that returns a value from an element in a collection.
*
* You can call `iteratee` with the following types of arguments:
*
* - **Function**: Returns the function as-is, which will be called with the element from the collection.
* - **Property name**: Returns the value of the specified property from the element.
* - **Property-value pair**: Returns a boolean indicating whether the element's property matches the given value.
* - **Partial object**: Returns a boolean indicating whether the element matches the properties of the partial object.
*
* If you don't provide any arguments or pass `null`, this function will return a function that simply returns its input unchanged.
*
* @param value - The value to convert to an iteratee.
* @returns Returns the new iteratee function.
* @example
* const func = iteratee();
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [{ a: 1 }, { a: 2 }, { a: 3 }]
*
* const func = iteratee((object) => object.a);
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
*
* const func = iteratee('a');
* [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
*
* const func = iteratee({ a: 1 });
* [{ a: 1 }, { a: 2 }, { a: 3 }].find(func) // => { a: 1 }
*
* const func = iteratee(['a', 1]);
* [{ a: 1 }, { a: 2 }, { a: 3 }].find(func) // => { a: 1 }
*/
function iteratee(value) {
if (value == null) return identity;
switch (typeof value) {
case "function": return value;
case "object":
if (Array.isArray(value) && value.length === 2) return matchesProperty(value[0], value[1]);
return matches(value);
case "string":
case "symbol":
case "number": return property(value);
}
}
//#endregion
export { iteratee };

View file

@ -0,0 +1,16 @@
//#region src/compat/util/lt.d.ts
/**
* Checks if value is less than other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is less than other, else `false`.
*
* @example
* lt(1, 3); // true
* lt(3, 3); // false
* lt(3, 1); // false
*/
declare function lt(value: any, other: any): boolean;
//#endregion
export { lt };

View file

@ -0,0 +1,16 @@
//#region src/compat/util/lt.d.ts
/**
* Checks if value is less than other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is less than other, else `false`.
*
* @example
* lt(1, 3); // true
* lt(3, 3); // false
* lt(3, 1); // false
*/
declare function lt(value: any, other: any): boolean;
//#endregion
export { lt };

View file

@ -0,0 +1,20 @@
const require_toNumber = require("./toNumber.js");
//#region src/compat/util/lt.ts
/**
* Checks if value is less than other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is less than other, else `false`.
*
* @example
* lt(1, 3); // true
* lt(3, 3); // false
* lt(3, 1); // false
*/
function lt(value, other) {
if (typeof value === "string" && typeof other === "string") return value < other;
return require_toNumber.toNumber(value) < require_toNumber.toNumber(other);
}
//#endregion
exports.lt = lt;

View file

@ -0,0 +1,20 @@
import { toNumber } from "./toNumber.mjs";
//#region src/compat/util/lt.ts
/**
* Checks if value is less than other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is less than other, else `false`.
*
* @example
* lt(1, 3); // true
* lt(3, 3); // false
* lt(3, 1); // false
*/
function lt(value, other) {
if (typeof value === "string" && typeof other === "string") return value < other;
return toNumber(value) < toNumber(other);
}
//#endregion
export { lt };

View file

@ -0,0 +1,16 @@
//#region src/compat/util/lte.d.ts
/**
* Checks if value is less than or equal to other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is less than or equal to other, else `false`.
*
* @example
* lte(1, 3); // => true
* lte(3, 3); // => true
* lte(3, 1); // => false
*/
declare function lte(value: any, other: any): boolean;
//#endregion
export { lte };

View file

@ -0,0 +1,16 @@
//#region src/compat/util/lte.d.ts
/**
* Checks if value is less than or equal to other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is less than or equal to other, else `false`.
*
* @example
* lte(1, 3); // => true
* lte(3, 3); // => true
* lte(3, 1); // => false
*/
declare function lte(value: any, other: any): boolean;
//#endregion
export { lte };

View file

@ -0,0 +1,20 @@
const require_toNumber = require("./toNumber.js");
//#region src/compat/util/lte.ts
/**
* Checks if value is less than or equal to other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is less than or equal to other, else `false`.
*
* @example
* lte(1, 3); // => true
* lte(3, 3); // => true
* lte(3, 1); // => false
*/
function lte(value, other) {
if (typeof value === "string" && typeof other === "string") return value <= other;
return require_toNumber.toNumber(value) <= require_toNumber.toNumber(other);
}
//#endregion
exports.lte = lte;

View file

@ -0,0 +1,20 @@
import { toNumber } from "./toNumber.mjs";
//#region src/compat/util/lte.ts
/**
* Checks if value is less than or equal to other.
*
* @param value The value to compare.
* @param other The other value to compare.
* @returns Returns `true` if value is less than or equal to other, else `false`.
*
* @example
* lte(1, 3); // => true
* lte(3, 3); // => true
* lte(3, 1); // => false
*/
function lte(value, other) {
if (typeof value === "string" && typeof other === "string") return value <= other;
return toNumber(value) <= toNumber(other);
}
//#endregion
export { lte };

View file

@ -0,0 +1,23 @@
//#region src/compat/util/method.d.ts
/**
* Creates a function that invokes the method at `path` of a given object with the provided arguments.
*
* @param path - The path of the method to invoke.
* @param args - The arguments to invoke the method with.
* @returns Returns a new function that takes an object and invokes the method at `path` with `args`.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* const add = method('a.b', 1, 2);
* console.log(add(object)); // => 3
*/
declare function method(path: PropertyKey | readonly PropertyKey[], ...args: any[]): (object: any) => any;
//#endregion
export { method };

View file

@ -0,0 +1,23 @@
//#region src/compat/util/method.d.ts
/**
* Creates a function that invokes the method at `path` of a given object with the provided arguments.
*
* @param path - The path of the method to invoke.
* @param args - The arguments to invoke the method with.
* @returns Returns a new function that takes an object and invokes the method at `path` with `args`.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* const add = method('a.b', 1, 2);
* console.log(add(object)); // => 3
*/
declare function method(path: PropertyKey | readonly PropertyKey[], ...args: any[]): (object: any) => any;
//#endregion
export { method };

View file

@ -0,0 +1,28 @@
const require_invoke = require("./invoke.js");
//#region src/compat/util/method.ts
/**
* Creates a function that invokes the method at `path` of a given object with the provided arguments.
*
* @param path - The path of the method to invoke.
* @param args - The arguments to invoke the method with.
* @returns Returns a new function that takes an object and invokes the method at `path` with `args`.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* const add = method('a.b', 1, 2);
* console.log(add(object)); // => 3
*/
function method(path, ...args) {
return function(object) {
return require_invoke.invoke(object, path, args);
};
}
//#endregion
exports.method = method;

View file

@ -0,0 +1,28 @@
import { invoke } from "./invoke.mjs";
//#region src/compat/util/method.ts
/**
* Creates a function that invokes the method at `path` of a given object with the provided arguments.
*
* @param path - The path of the method to invoke.
* @param args - The arguments to invoke the method with.
* @returns Returns a new function that takes an object and invokes the method at `path` with `args`.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* const add = method('a.b', 1, 2);
* console.log(add(object)); // => 3
*/
function method(path, ...args) {
return function(object) {
return invoke(object, path, args);
};
}
//#endregion
export { method };

View file

@ -0,0 +1,23 @@
//#region src/compat/util/methodOf.d.ts
/**
* Creates a function that invokes the method at a given path of `object` with the provided arguments.
*
* @param object - The object to query.
* @param args - The arguments to invoke the method with.
* @returns Returns a new function that takes a path and invokes the method at `path` with `args`.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* const add = methodOf(object, 1, 2);
* console.log(add('a.b')); // => 3
*/
declare function methodOf(object: object, ...args: any[]): (path: PropertyKey | readonly PropertyKey[]) => any;
//#endregion
export { methodOf };

View file

@ -0,0 +1,23 @@
//#region src/compat/util/methodOf.d.ts
/**
* Creates a function that invokes the method at a given path of `object` with the provided arguments.
*
* @param object - The object to query.
* @param args - The arguments to invoke the method with.
* @returns Returns a new function that takes a path and invokes the method at `path` with `args`.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* const add = methodOf(object, 1, 2);
* console.log(add('a.b')); // => 3
*/
declare function methodOf(object: object, ...args: any[]): (path: PropertyKey | readonly PropertyKey[]) => any;
//#endregion
export { methodOf };

View file

@ -0,0 +1,28 @@
const require_invoke = require("./invoke.js");
//#region src/compat/util/methodOf.ts
/**
* Creates a function that invokes the method at a given path of `object` with the provided arguments.
*
* @param object - The object to query.
* @param args - The arguments to invoke the method with.
* @returns Returns a new function that takes a path and invokes the method at `path` with `args`.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* const add = methodOf(object, 1, 2);
* console.log(add('a.b')); // => 3
*/
function methodOf(object, ...args) {
return function(path) {
return require_invoke.invoke(object, path, args);
};
}
//#endregion
exports.methodOf = methodOf;

View file

@ -0,0 +1,28 @@
import { invoke } from "./invoke.mjs";
//#region src/compat/util/methodOf.ts
/**
* Creates a function that invokes the method at a given path of `object` with the provided arguments.
*
* @param object - The object to query.
* @param args - The arguments to invoke the method with.
* @returns Returns a new function that takes a path and invokes the method at `path` with `args`.
*
* @example
* const object = {
* a: {
* b: function (x, y) {
* return x + y;
* }
* }
* };
*
* const add = methodOf(object, 1, 2);
* console.log(add('a.b')); // => 3
*/
function methodOf(object, ...args) {
return function(path) {
return invoke(object, path, args);
};
}
//#endregion
export { methodOf };

View file

@ -0,0 +1,19 @@
//#region src/compat/util/now.d.ts
/**
* Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
*
* @returns The current time in milliseconds.
*
* @example
* const currentTime = now();
* console.log(currentTime); // Outputs the current time in milliseconds
*
* @example
* const startTime = now();
* // Some time-consuming operation
* const endTime = now();
* console.log(`Operation took ${endTime - startTime} milliseconds`);
*/
declare function now(): number;
//#endregion
export { now };

View file

@ -0,0 +1,19 @@
//#region src/compat/util/now.d.ts
/**
* Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
*
* @returns The current time in milliseconds.
*
* @example
* const currentTime = now();
* console.log(currentTime); // Outputs the current time in milliseconds
*
* @example
* const startTime = now();
* // Some time-consuming operation
* const endTime = now();
* console.log(`Operation took ${endTime - startTime} milliseconds`);
*/
declare function now(): number;
//#endregion
export { now };

View file

@ -0,0 +1,21 @@
//#region src/compat/util/now.ts
/**
* Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
*
* @returns The current time in milliseconds.
*
* @example
* const currentTime = now();
* console.log(currentTime); // Outputs the current time in milliseconds
*
* @example
* const startTime = now();
* // Some time-consuming operation
* const endTime = now();
* console.log(`Operation took ${endTime - startTime} milliseconds`);
*/
function now() {
return Date.now();
}
//#endregion
exports.now = now;

View file

@ -0,0 +1,21 @@
//#region src/compat/util/now.ts
/**
* Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
*
* @returns The current time in milliseconds.
*
* @example
* const currentTime = now();
* console.log(currentTime); // Outputs the current time in milliseconds
*
* @example
* const startTime = now();
* // Some time-consuming operation
* const endTime = now();
* console.log(`Operation took ${endTime - startTime} milliseconds`);
*/
function now() {
return Date.now();
}
//#endregion
export { now };

View file

@ -0,0 +1,30 @@
//#region src/compat/util/over.d.ts
/**
* Creates a function that invokes given functions and returns their results as an array.
*
* @param iteratees - The iteratees to invoke.
* @returns Returns the new function.
*
* @example
* const func = over([Math.max, Math.min]);
* const func2 = over(Math.max, Math.min); // same as above
* func(1, 2, 3, 4);
* // => [4, 1]
* func2(1, 2, 3, 4);
* // => [4, 1]
*
* const func = over(['a', 'b']);
* func({ a: 1, b: 2 });
* // => [1, 2]
*
* const func = over([{ a: 1 }, { b: 2 }]);
* func({ a: 1, b: 2 });
* // => [true, true]
*
* const func = over([['a', 1], ['b', 2]]);
* func({ a: 1, b: 2 });
* // => [true, true]
*/
declare function over<T>(...iteratees: Array<((...args: any[]) => T) | ReadonlyArray<(...args: any[]) => T>>): (...args: any[]) => T[];
//#endregion
export { over };

View file

@ -0,0 +1,30 @@
//#region src/compat/util/over.d.ts
/**
* Creates a function that invokes given functions and returns their results as an array.
*
* @param iteratees - The iteratees to invoke.
* @returns Returns the new function.
*
* @example
* const func = over([Math.max, Math.min]);
* const func2 = over(Math.max, Math.min); // same as above
* func(1, 2, 3, 4);
* // => [4, 1]
* func2(1, 2, 3, 4);
* // => [4, 1]
*
* const func = over(['a', 'b']);
* func({ a: 1, b: 2 });
* // => [1, 2]
*
* const func = over([{ a: 1 }, { b: 2 }]);
* func({ a: 1, b: 2 });
* // => [true, true]
*
* const func = over([['a', 1], ['b', 2]]);
* func({ a: 1, b: 2 });
* // => [true, true]
*/
declare function over<T>(...iteratees: Array<((...args: any[]) => T) | ReadonlyArray<(...args: any[]) => T>>): (...args: any[]) => T[];
//#endregion
export { over };

View file

@ -0,0 +1,37 @@
const require_iteratee = require("./iteratee.js");
//#region src/compat/util/over.ts
/**
* Creates a function that invokes given functions and returns their results as an array.
*
* @param iteratees - The iteratees to invoke.
* @returns Returns the new function.
*
* @example
* const func = over([Math.max, Math.min]);
* const func2 = over(Math.max, Math.min); // same as above
* func(1, 2, 3, 4);
* // => [4, 1]
* func2(1, 2, 3, 4);
* // => [4, 1]
*
* const func = over(['a', 'b']);
* func({ a: 1, b: 2 });
* // => [1, 2]
*
* const func = over([{ a: 1 }, { b: 2 }]);
* func({ a: 1, b: 2 });
* // => [true, true]
*
* const func = over([['a', 1], ['b', 2]]);
* func({ a: 1, b: 2 });
* // => [true, true]
*/
function over(...iteratees) {
if (iteratees.length === 1 && Array.isArray(iteratees[0])) iteratees = iteratees[0];
const funcs = iteratees.map((item) => require_iteratee.iteratee(item));
return function(...args) {
return funcs.map((func) => func.apply(this, args));
};
}
//#endregion
exports.over = over;

View file

@ -0,0 +1,37 @@
import { iteratee } from "./iteratee.mjs";
//#region src/compat/util/over.ts
/**
* Creates a function that invokes given functions and returns their results as an array.
*
* @param iteratees - The iteratees to invoke.
* @returns Returns the new function.
*
* @example
* const func = over([Math.max, Math.min]);
* const func2 = over(Math.max, Math.min); // same as above
* func(1, 2, 3, 4);
* // => [4, 1]
* func2(1, 2, 3, 4);
* // => [4, 1]
*
* const func = over(['a', 'b']);
* func({ a: 1, b: 2 });
* // => [1, 2]
*
* const func = over([{ a: 1 }, { b: 2 }]);
* func({ a: 1, b: 2 });
* // => [true, true]
*
* const func = over([['a', 1], ['b', 2]]);
* func({ a: 1, b: 2 });
* // => [true, true]
*/
function over(...iteratees) {
if (iteratees.length === 1 && Array.isArray(iteratees[0])) iteratees = iteratees[0];
const funcs = iteratees.map((item) => iteratee(item));
return function(...args) {
return funcs.map((func) => func.apply(this, args));
};
}
//#endregion
export { over };

View file

@ -0,0 +1,68 @@
//#region src/compat/util/overEvery.d.ts
/**
* Creates a predicate function that checks if a value satisfies all of the given predicates.
*
* @template T - The type of the value to be checked.
* @template U - The first possible type that the value could match.
* @template V - The second possible type that the value could match.
*
* @param predicate1 - A function that checks if the value matches type `U`.
* @param predicate2 - A function that checks if the value matches type `V`.
*
* @returns A function that takes a value and returns `true` if all predicates return truthy.
*
* @example
* const func = overEvery(
* (value) => typeof value === 'string',
* (value) => value === 'hello'
* );
*
* func("hello"); // true
* func("world"); // false
* func(42); // false
*/
declare function overEvery<T, U extends T, V extends T>(predicate1: (value: T) => value is U, predicate2: (value: T) => value is V): (value: T) => value is U & V;
/**
* Creates a function that checks if all of the given predicates return truthy for the provided values.
*
* @template T - The type of the values to be checked.
*
* @param predicates -
* A list of predicates or arrays of predicates. Each predicate is a function that takes one or more values of
* type `T` and returns a boolean indicating whether the condition is satisfied for those values.
*
* @returns A function that takes a list of values and returns `true` if all of the
* predicates return truthy for the provided values, and `false` otherwise.
*
* @example
* const func = overEvery(
* (value) => typeof value === 'string',
* (value) => value.length > 3
* );
*
* func("hello"); // true
* func("hi"); // false
* func(42); // false
*
* @example
* const func = overEvery([
* (value) => value.a > 0,
* (value) => value.b > 0
* ]);
*
* func({ a: 1, b: 2 }); // true
* func({ a: 0, b: 2 }); // false
*
* @example
* const func = overEvery(
* (a, b) => typeof a === 'string' && typeof b === 'string',
* (a, b) => a.length > 3 && b.length > 3
* );
*
* func("hello", "world"); // true
* func("hi", "world"); // false
* func(1, 10); // false
*/
declare function overEvery<T>(...predicates: Array<((...args: T[]) => boolean) | ReadonlyArray<(...args: T[]) => boolean>>): (...args: T[]) => boolean;
//#endregion
export { overEvery };

View file

@ -0,0 +1,68 @@
//#region src/compat/util/overEvery.d.ts
/**
* Creates a predicate function that checks if a value satisfies all of the given predicates.
*
* @template T - The type of the value to be checked.
* @template U - The first possible type that the value could match.
* @template V - The second possible type that the value could match.
*
* @param predicate1 - A function that checks if the value matches type `U`.
* @param predicate2 - A function that checks if the value matches type `V`.
*
* @returns A function that takes a value and returns `true` if all predicates return truthy.
*
* @example
* const func = overEvery(
* (value) => typeof value === 'string',
* (value) => value === 'hello'
* );
*
* func("hello"); // true
* func("world"); // false
* func(42); // false
*/
declare function overEvery<T, U extends T, V extends T>(predicate1: (value: T) => value is U, predicate2: (value: T) => value is V): (value: T) => value is U & V;
/**
* Creates a function that checks if all of the given predicates return truthy for the provided values.
*
* @template T - The type of the values to be checked.
*
* @param predicates -
* A list of predicates or arrays of predicates. Each predicate is a function that takes one or more values of
* type `T` and returns a boolean indicating whether the condition is satisfied for those values.
*
* @returns A function that takes a list of values and returns `true` if all of the
* predicates return truthy for the provided values, and `false` otherwise.
*
* @example
* const func = overEvery(
* (value) => typeof value === 'string',
* (value) => value.length > 3
* );
*
* func("hello"); // true
* func("hi"); // false
* func(42); // false
*
* @example
* const func = overEvery([
* (value) => value.a > 0,
* (value) => value.b > 0
* ]);
*
* func({ a: 1, b: 2 }); // true
* func({ a: 0, b: 2 }); // false
*
* @example
* const func = overEvery(
* (a, b) => typeof a === 'string' && typeof b === 'string',
* (a, b) => a.length > 3 && b.length > 3
* );
*
* func("hello", "world"); // true
* func("hi", "world"); // false
* func(1, 10); // false
*/
declare function overEvery<T>(...predicates: Array<((...args: T[]) => boolean) | ReadonlyArray<(...args: T[]) => boolean>>): (...args: T[]) => boolean;
//#endregion
export { overEvery };

View file

@ -0,0 +1,61 @@
const require_iteratee = require("./iteratee.js");
//#region src/compat/util/overEvery.ts
/**
* Creates a function that checks if all of the given predicates return truthy for the provided values.
*
* This function takes multiple predicates, which can either be individual predicate functions or arrays of predicates,
* and returns a new function that checks if all of the predicates return truthy when called with the provided values.
*
* @template T - The type of the values to be checked.
*
* @param predicates -
* A list of predicates or arrays of predicates. Each predicate is a function that takes one or more values of
* type `T` and returns a boolean indicating whether the condition is satisfied for those values.
*
* @returns A function that takes a list of values and returns `true` if all of the
* predicates return truthy for the provided values, and `false` otherwise.
*
* @example
* const func = overEvery(
* (value) => typeof value === 'string',
* (value) => value.length > 3
* );
*
* func("hello"); // true
* func("hi"); // false
* func(42); // false
*
* @example
* const func = overEvery([
* (value) => value.a > 0,
* (value) => value.b > 0
* ]);
*
* func({ a: 1, b: 2 }); // true
* func({ a: 0, b: 2 }); // false
*
* @example
* const func = overEvery(
* (a, b) => typeof a === 'string' && typeof b === 'string',
* (a, b) => a.length > 3 && b.length > 3
* );
*
* func("hello", "world"); // true
* func("hi", "world"); // false
* func(1, 10); // false
*/
function overEvery(...predicates) {
return function(...values) {
for (let i = 0; i < predicates.length; ++i) {
const predicate = predicates[i];
if (!Array.isArray(predicate)) {
if (!require_iteratee.iteratee(predicate).apply(this, values)) return false;
continue;
}
for (let j = 0; j < predicate.length; ++j) if (!require_iteratee.iteratee(predicate[j]).apply(this, values)) return false;
}
return true;
};
}
//#endregion
exports.overEvery = overEvery;

View file

@ -0,0 +1,61 @@
import { iteratee } from "./iteratee.mjs";
//#region src/compat/util/overEvery.ts
/**
* Creates a function that checks if all of the given predicates return truthy for the provided values.
*
* This function takes multiple predicates, which can either be individual predicate functions or arrays of predicates,
* and returns a new function that checks if all of the predicates return truthy when called with the provided values.
*
* @template T - The type of the values to be checked.
*
* @param predicates -
* A list of predicates or arrays of predicates. Each predicate is a function that takes one or more values of
* type `T` and returns a boolean indicating whether the condition is satisfied for those values.
*
* @returns A function that takes a list of values and returns `true` if all of the
* predicates return truthy for the provided values, and `false` otherwise.
*
* @example
* const func = overEvery(
* (value) => typeof value === 'string',
* (value) => value.length > 3
* );
*
* func("hello"); // true
* func("hi"); // false
* func(42); // false
*
* @example
* const func = overEvery([
* (value) => value.a > 0,
* (value) => value.b > 0
* ]);
*
* func({ a: 1, b: 2 }); // true
* func({ a: 0, b: 2 }); // false
*
* @example
* const func = overEvery(
* (a, b) => typeof a === 'string' && typeof b === 'string',
* (a, b) => a.length > 3 && b.length > 3
* );
*
* func("hello", "world"); // true
* func("hi", "world"); // false
* func(1, 10); // false
*/
function overEvery(...predicates) {
return function(...values) {
for (let i = 0; i < predicates.length; ++i) {
const predicate = predicates[i];
if (!Array.isArray(predicate)) {
if (!iteratee(predicate).apply(this, values)) return false;
continue;
}
for (let j = 0; j < predicate.length; ++j) if (!iteratee(predicate[j]).apply(this, values)) return false;
}
return true;
};
}
//#endregion
export { overEvery };

View file

@ -0,0 +1,70 @@
//#region src/compat/util/overSome.d.ts
/**
* Creates a predicate function that checks if a value satisfies at least one of the given predicates.
*
* @template T - The type of the value to be checked.
* @template U - The first possible type that the value could match.
* @template V - The second possible type that the value could match.
*
* @param predicate1 - A function that checks if the value matches type `U`.
* @param predicate2 - A function that checks if the value matches type `V`.
*
* @returns A function that takes a value and returns `true` if any predicates return truthy.
*
* @example
* const func = overSome(
* (value) => typeof value === 'string',
* (value) => typeof value === 'number'
* );
*
* func("hello"); // true
* func(42); // true
* func([]); // false
*/
declare function overSome<T, U extends T, V extends T>(predicate1: (value: T) => value is U, predicate2: (value: T) => value is V): (value: T) => value is U | V;
/**
* Creates a function that checks if any of the given predicates return truthy for the provided values.
*
* @template T - The type of the values to be checked.
*
* @param predicates -
* A list of predicates or arrays of predicates. Each predicate is a function that takes one or more values of
* type `T` and returns a boolean indicating whether the condition is satisfied for those values.
*
* @returns A function that takes a list of values and returns `true` if any of the
* predicates return truthy for the provided values, and `false` otherwise.
*
* @example
* const func = overSome(
* (value) => typeof value === 'string',
* (value) => typeof value === 'number',
* (value) => typeof value === 'symbol'
* );
*
* func("hello"); // true
* func(42); // true
* func(Symbol()); // true
* func([]); // false
*
* @example
* const func = overSome([
* (value) => value.a > 0,
* (value) => value.b > 0
* ]);
*
* func({ a: 0, b: 2 }); // true
* func({ a: 0, b: 0 }); // false
*
* @example
* const func = overSome(
* (a, b) => typeof a === 'string' && typeof b === 'string',
* (a, b) => a > 0 && b > 0
* );
*
* func("hello", "world"); // true
* func(1, 10); // true
* func(0, 2); // false
*/
declare function overSome<T>(...predicates: Array<((...values: T[]) => boolean) | ReadonlyArray<(...values: T[]) => boolean>>): (...values: T[]) => boolean;
//#endregion
export { overSome };

View file

@ -0,0 +1,70 @@
//#region src/compat/util/overSome.d.ts
/**
* Creates a predicate function that checks if a value satisfies at least one of the given predicates.
*
* @template T - The type of the value to be checked.
* @template U - The first possible type that the value could match.
* @template V - The second possible type that the value could match.
*
* @param predicate1 - A function that checks if the value matches type `U`.
* @param predicate2 - A function that checks if the value matches type `V`.
*
* @returns A function that takes a value and returns `true` if any predicates return truthy.
*
* @example
* const func = overSome(
* (value) => typeof value === 'string',
* (value) => typeof value === 'number'
* );
*
* func("hello"); // true
* func(42); // true
* func([]); // false
*/
declare function overSome<T, U extends T, V extends T>(predicate1: (value: T) => value is U, predicate2: (value: T) => value is V): (value: T) => value is U | V;
/**
* Creates a function that checks if any of the given predicates return truthy for the provided values.
*
* @template T - The type of the values to be checked.
*
* @param predicates -
* A list of predicates or arrays of predicates. Each predicate is a function that takes one or more values of
* type `T` and returns a boolean indicating whether the condition is satisfied for those values.
*
* @returns A function that takes a list of values and returns `true` if any of the
* predicates return truthy for the provided values, and `false` otherwise.
*
* @example
* const func = overSome(
* (value) => typeof value === 'string',
* (value) => typeof value === 'number',
* (value) => typeof value === 'symbol'
* );
*
* func("hello"); // true
* func(42); // true
* func(Symbol()); // true
* func([]); // false
*
* @example
* const func = overSome([
* (value) => value.a > 0,
* (value) => value.b > 0
* ]);
*
* func({ a: 0, b: 2 }); // true
* func({ a: 0, b: 0 }); // false
*
* @example
* const func = overSome(
* (a, b) => typeof a === 'string' && typeof b === 'string',
* (a, b) => a > 0 && b > 0
* );
*
* func("hello", "world"); // true
* func(1, 10); // true
* func(0, 2); // false
*/
declare function overSome<T>(...predicates: Array<((...values: T[]) => boolean) | ReadonlyArray<(...values: T[]) => boolean>>): (...values: T[]) => boolean;
//#endregion
export { overSome };

View file

@ -0,0 +1,63 @@
const require_iteratee = require("./iteratee.js");
//#region src/compat/util/overSome.ts
/**
* Creates a function that checks if any of the given predicates return truthy for the provided values.
*
* This function takes multiple predicates, which can either be individual predicate functions or arrays of predicates,
* and returns a new function that checks if any of the predicates return truthy when called with the provided values.
*
* @template T - The type of the values to be checked.
*
* @param predicates -
* A list of predicates or arrays of predicates. Each predicate is a function that takes one or more values of
* type `T` and returns a boolean indicating whether the condition is satisfied for those values.
*
* @returns A function that takes a list of values and returns `true` if any of the
* predicates return truthy for the provided values, and `false` otherwise.
*
* @example
* const func = overSome(
* (value) => typeof value === 'string',
* (value) => typeof value === 'number',
* (value) => typeof value === 'symbol'
* );
*
* func("hello"); // true
* func(42); // true
* func(Symbol()); // true
* func([]); // false
*
* @example
* const func = overSome([
* (value) => value.a > 0,
* (value) => value.b > 0
* ]);
*
* func({ a: 0, b: 2 }); // true
* func({ a: 0, b: 0 }); // false
*
* @example
* const func = overSome(
* (a, b) => typeof a === 'string' && typeof b === 'string',
* (a, b) => a > 0 && b > 0
* );
*
* func("hello", "world"); // true
* func(1, 10); // true
* func(0, 2); // false
*/
function overSome(...predicates) {
return function(...values) {
for (let i = 0; i < predicates.length; ++i) {
const predicate = predicates[i];
if (!Array.isArray(predicate)) {
if (require_iteratee.iteratee(predicate).apply(this, values)) return true;
continue;
}
for (let j = 0; j < predicate.length; ++j) if (require_iteratee.iteratee(predicate[j]).apply(this, values)) return true;
}
return false;
};
}
//#endregion
exports.overSome = overSome;

View file

@ -0,0 +1,63 @@
import { iteratee } from "./iteratee.mjs";
//#region src/compat/util/overSome.ts
/**
* Creates a function that checks if any of the given predicates return truthy for the provided values.
*
* This function takes multiple predicates, which can either be individual predicate functions or arrays of predicates,
* and returns a new function that checks if any of the predicates return truthy when called with the provided values.
*
* @template T - The type of the values to be checked.
*
* @param predicates -
* A list of predicates or arrays of predicates. Each predicate is a function that takes one or more values of
* type `T` and returns a boolean indicating whether the condition is satisfied for those values.
*
* @returns A function that takes a list of values and returns `true` if any of the
* predicates return truthy for the provided values, and `false` otherwise.
*
* @example
* const func = overSome(
* (value) => typeof value === 'string',
* (value) => typeof value === 'number',
* (value) => typeof value === 'symbol'
* );
*
* func("hello"); // true
* func(42); // true
* func(Symbol()); // true
* func([]); // false
*
* @example
* const func = overSome([
* (value) => value.a > 0,
* (value) => value.b > 0
* ]);
*
* func({ a: 0, b: 2 }); // true
* func({ a: 0, b: 0 }); // false
*
* @example
* const func = overSome(
* (a, b) => typeof a === 'string' && typeof b === 'string',
* (a, b) => a > 0 && b > 0
* );
*
* func("hello", "world"); // true
* func(1, 10); // true
* func(0, 2); // false
*/
function overSome(...predicates) {
return function(...values) {
for (let i = 0; i < predicates.length; ++i) {
const predicate = predicates[i];
if (!Array.isArray(predicate)) {
if (iteratee(predicate).apply(this, values)) return true;
continue;
}
for (let j = 0; j < predicate.length; ++j) if (iteratee(predicate[j]).apply(this, values)) return true;
}
return false;
};
}
//#endregion
export { overSome };

View file

@ -0,0 +1,11 @@
//#region src/compat/util/stubArray.d.ts
/**
* Returns a new empty array.
*
* @returns A new empty array.
* @example
* stubArray() // Returns []
*/
declare function stubArray(): any[];
//#endregion
export { stubArray };

View file

@ -0,0 +1,11 @@
//#region src/compat/util/stubArray.d.ts
/**
* Returns a new empty array.
*
* @returns A new empty array.
* @example
* stubArray() // Returns []
*/
declare function stubArray(): any[];
//#endregion
export { stubArray };

View file

@ -0,0 +1,6 @@
//#region src/compat/util/stubArray.ts
function stubArray() {
return [];
}
//#endregion
exports.stubArray = stubArray;

View file

@ -0,0 +1,6 @@
//#region src/compat/util/stubArray.ts
function stubArray() {
return [];
}
//#endregion
export { stubArray };

View file

@ -0,0 +1,19 @@
//#region src/compat/util/stubFalse.d.ts
/**
* Returns false.
*
* @returns false.
* @example
* stubFalse() // Returns false
*/
declare function stubFalse(): false;
/**
* Returns false.
*
* @returns false.
* @example
* stubFalse() // Returns false
*/
declare function stubFalse(): false;
//#endregion
export { stubFalse };

View file

@ -0,0 +1,19 @@
//#region src/compat/util/stubFalse.d.ts
/**
* Returns false.
*
* @returns false.
* @example
* stubFalse() // Returns false
*/
declare function stubFalse(): false;
/**
* Returns false.
*
* @returns false.
* @example
* stubFalse() // Returns false
*/
declare function stubFalse(): false;
//#endregion
export { stubFalse };

View file

@ -0,0 +1,6 @@
//#region src/compat/util/stubFalse.ts
function stubFalse() {
return false;
}
//#endregion
exports.stubFalse = stubFalse;

View file

@ -0,0 +1,6 @@
//#region src/compat/util/stubFalse.ts
function stubFalse() {
return false;
}
//#endregion
export { stubFalse };

View file

@ -0,0 +1,11 @@
//#region src/compat/util/stubObject.d.ts
/**
* Returns an empty object.
*
* @returns An empty object.
* @example
* stubObject() // Returns {}
*/
declare function stubObject(): any;
//#endregion
export { stubObject };

View file

@ -0,0 +1,11 @@
//#region src/compat/util/stubObject.d.ts
/**
* Returns an empty object.
*
* @returns An empty object.
* @example
* stubObject() // Returns {}
*/
declare function stubObject(): any;
//#endregion
export { stubObject };

View file

@ -0,0 +1,13 @@
//#region src/compat/util/stubObject.ts
/**
* Returns an empty object.
*
* @returns An empty object.
* @example
* stubObject() // Returns {}
*/
function stubObject() {
return {};
}
//#endregion
exports.stubObject = stubObject;

View file

@ -0,0 +1,13 @@
//#region src/compat/util/stubObject.ts
/**
* Returns an empty object.
*
* @returns An empty object.
* @example
* stubObject() // Returns {}
*/
function stubObject() {
return {};
}
//#endregion
export { stubObject };

View file

@ -0,0 +1,11 @@
//#region src/compat/util/stubString.d.ts
/**
* Returns an empty string.
*
* @returns An empty string.
* @example
* stubString() // Returns ''
*/
declare function stubString(): string;
//#endregion
export { stubString };

View file

@ -0,0 +1,11 @@
//#region src/compat/util/stubString.d.ts
/**
* Returns an empty string.
*
* @returns An empty string.
* @example
* stubString() // Returns ''
*/
declare function stubString(): string;
//#endregion
export { stubString };

View file

@ -0,0 +1,6 @@
//#region src/compat/util/stubString.ts
function stubString() {
return "";
}
//#endregion
exports.stubString = stubString;

View file

@ -0,0 +1,6 @@
//#region src/compat/util/stubString.ts
function stubString() {
return "";
}
//#endregion
export { stubString };

View file

@ -0,0 +1,19 @@
//#region src/compat/util/stubTrue.d.ts
/**
* Returns true.
*
* @returns true.
* @example
* stubTrue() // Returns true
*/
declare function stubTrue(): true;
/**
* Returns true.
*
* @returns true.
* @example
* stubTrue() // Returns true
*/
declare function stubTrue(): true;
//#endregion
export { stubTrue };

View file

@ -0,0 +1,19 @@
//#region src/compat/util/stubTrue.d.ts
/**
* Returns true.
*
* @returns true.
* @example
* stubTrue() // Returns true
*/
declare function stubTrue(): true;
/**
* Returns true.
*
* @returns true.
* @example
* stubTrue() // Returns true
*/
declare function stubTrue(): true;
//#endregion
export { stubTrue };

View file

@ -0,0 +1,6 @@
//#region src/compat/util/stubTrue.ts
function stubTrue() {
return true;
}
//#endregion
exports.stubTrue = stubTrue;

View file

@ -0,0 +1,6 @@
//#region src/compat/util/stubTrue.ts
function stubTrue() {
return true;
}
//#endregion
export { stubTrue };

View file

@ -0,0 +1,24 @@
//#region src/compat/util/times.d.ts
/**
* Invokes the iteratee function n times, returning an array of the results.
*
* @template T The return type of the iteratee function.
* @param n - The number of times to invoke iteratee.
* @param iteratee - The function to invoke for each index.
* @returns An array containing the results of invoking iteratee n times.
* @example
* times(3, (i) => i * 2); // => [0, 2, 4]
* times(2, () => 'es-toolkit'); // => ['es-toolkit', 'es-toolkit']
*/
declare function times<T>(n: number, iteratee: (num: number) => T): T[];
/**
* Invokes the default iteratee function n times, returning an array of indices.
*
* @param n - The number of times to invoke the default iteratee.
* @returns An array containing indices from 0 to n-1.
* @example
* times(3); // => [0, 1, 2]
*/
declare function times(n: number): number[];
//#endregion
export { times };

View file

@ -0,0 +1,24 @@
//#region src/compat/util/times.d.ts
/**
* Invokes the iteratee function n times, returning an array of the results.
*
* @template T The return type of the iteratee function.
* @param n - The number of times to invoke iteratee.
* @param iteratee - The function to invoke for each index.
* @returns An array containing the results of invoking iteratee n times.
* @example
* times(3, (i) => i * 2); // => [0, 2, 4]
* times(2, () => 'es-toolkit'); // => ['es-toolkit', 'es-toolkit']
*/
declare function times<T>(n: number, iteratee: (num: number) => T): T[];
/**
* Invokes the default iteratee function n times, returning an array of indices.
*
* @param n - The number of times to invoke the default iteratee.
* @returns An array containing indices from 0 to n-1.
* @example
* times(3); // => [0, 1, 2]
*/
declare function times(n: number): number[];
//#endregion
export { times };

View file

@ -0,0 +1,22 @@
const require_toInteger = require("./toInteger.js");
//#region src/compat/util/times.ts
/**
* Invokes the getValue function n times, returning an array of the results.
*
* @template R The return type of the getValue function.
* @param n - The number of times to invoke getValue.
* @param getValue - The function to invoke for each index.
* @returns An array containing the results of invoking getValue n times.
* @example
* times(3, (i) => i * 2); // => [0, 2, 4]
* times(2, () => 'es-toolkit'); // => ['es-toolkit', 'es-toolkit']
*/
function times(n, getValue) {
n = require_toInteger.toInteger(n);
if (n < 1 || !Number.isSafeInteger(n)) return [];
const result = new Array(n);
for (let i = 0; i < n; i++) result[i] = typeof getValue === "function" ? getValue(i) : i;
return result;
}
//#endregion
exports.times = times;

View file

@ -0,0 +1,22 @@
import { toInteger } from "./toInteger.mjs";
//#region src/compat/util/times.ts
/**
* Invokes the getValue function n times, returning an array of the results.
*
* @template R The return type of the getValue function.
* @param n - The number of times to invoke getValue.
* @param getValue - The function to invoke for each index.
* @returns An array containing the results of invoking getValue n times.
* @example
* times(3, (i) => i * 2); // => [0, 2, 4]
* times(2, () => 'es-toolkit'); // => ['es-toolkit', 'es-toolkit']
*/
function times(n, getValue) {
n = toInteger(n);
if (n < 1 || !Number.isSafeInteger(n)) return [];
const result = new Array(n);
for (let i = 0; i < n; i++) result[i] = typeof getValue === "function" ? getValue(i) : i;
return result;
}
//#endregion
export { times };

View file

@ -0,0 +1,36 @@
//#region src/compat/util/toArray.d.ts
/**
* Converts a record or null/undefined to an array of its values.
*
* @template T
* @param value - The record or null/undefined to convert.
* @returns Returns an array of the record's values or an empty array if null/undefined.
*
* @example
* toArray({ 'a': 1, 'b': 2 }) // => returns [1, 2]
* toArray(null) // => returns []
*/
declare function toArray<T>(value: Record<string, T> | Record<number, T> | null | undefined): T[];
/**
* Converts a value to an array of its values.
*
* @template T
* @param value - The value to convert.
* @returns Returns an array of the value's values.
*
* @example
* toArray({ x: 10, y: 20 }) // => returns [10, 20]
* toArray('abc') // => returns ['a', 'b', 'c']
*/
declare function toArray<T>(value: T): Array<T[keyof T]>;
/**
* Converts an undefined value to an empty array.
*
* @returns Returns an empty array.
*
* @example
* toArray() // => returns []
*/
declare function toArray(): any[];
//#endregion
export { toArray };

View file

@ -0,0 +1,36 @@
//#region src/compat/util/toArray.d.ts
/**
* Converts a record or null/undefined to an array of its values.
*
* @template T
* @param value - The record or null/undefined to convert.
* @returns Returns an array of the record's values or an empty array if null/undefined.
*
* @example
* toArray({ 'a': 1, 'b': 2 }) // => returns [1, 2]
* toArray(null) // => returns []
*/
declare function toArray<T>(value: Record<string, T> | Record<number, T> | null | undefined): T[];
/**
* Converts a value to an array of its values.
*
* @template T
* @param value - The value to convert.
* @returns Returns an array of the value's values.
*
* @example
* toArray({ x: 10, y: 20 }) // => returns [10, 20]
* toArray('abc') // => returns ['a', 'b', 'c']
*/
declare function toArray<T>(value: T): Array<T[keyof T]>;
/**
* Converts an undefined value to an empty array.
*
* @returns Returns an empty array.
*
* @example
* toArray() // => returns []
*/
declare function toArray(): any[];
//#endregion
export { toArray };

View file

@ -0,0 +1,23 @@
const require_isArrayLike = require("../predicate/isArrayLike.js");
const require_isMap = require("../predicate/isMap.js");
//#region src/compat/util/toArray.ts
/**
* Converts a value to an array.
*
* @param value - The value to convert.
* @returns Returns the converted array.
*
* @example
* toArray({ 'a': 1, 'b': 2 }) // => returns [1,2]
* toArray('abc') // => returns ['a', 'b', 'c']
* toArray(1) // => returns []
* toArray(null) // => returns []
*/
function toArray(value) {
if (value == null) return [];
if (require_isArrayLike.isArrayLike(value) || require_isMap.isMap(value)) return Array.from(value);
if (typeof value === "object") return Object.values(value);
return [];
}
//#endregion
exports.toArray = toArray;

View file

@ -0,0 +1,23 @@
import { isArrayLike } from "../predicate/isArrayLike.mjs";
import { isMap } from "../predicate/isMap.mjs";
//#region src/compat/util/toArray.ts
/**
* Converts a value to an array.
*
* @param value - The value to convert.
* @returns Returns the converted array.
*
* @example
* toArray({ 'a': 1, 'b': 2 }) // => returns [1,2]
* toArray('abc') // => returns ['a', 'b', 'c']
* toArray(1) // => returns []
* toArray(null) // => returns []
*/
function toArray(value) {
if (value == null) return [];
if (isArrayLike(value) || isMap(value)) return Array.from(value);
if (typeof value === "object") return Object.values(value);
return [];
}
//#endregion
export { toArray };

View file

@ -0,0 +1,18 @@
//#region src/compat/util/toFinite.d.ts
/**
* Converts `value` to a finite number.
*
* @param value - The value to convert.
* @returns Returns the number.
*
* @example
* toFinite(3.2); // => 3.2
* toFinite(Number.MIN_VALUE); // => 5e-324
* toFinite(Infinity); // => 1.7976931348623157e+308
* toFinite('3.2'); // => 3.2
* toFinite(Symbol.iterator); // => 0
* toFinite(NaN); // => 0
*/
declare function toFinite(value: any): number;
//#endregion
export { toFinite };

View file

@ -0,0 +1,18 @@
//#region src/compat/util/toFinite.d.ts
/**
* Converts `value` to a finite number.
*
* @param value - The value to convert.
* @returns Returns the number.
*
* @example
* toFinite(3.2); // => 3.2
* toFinite(Number.MIN_VALUE); // => 5e-324
* toFinite(Infinity); // => 1.7976931348623157e+308
* toFinite('3.2'); // => 3.2
* toFinite(Symbol.iterator); // => 0
* toFinite(NaN); // => 0
*/
declare function toFinite(value: any): number;
//#endregion
export { toFinite };

View file

@ -0,0 +1,24 @@
const require_toNumber = require("./toNumber.js");
//#region src/compat/util/toFinite.ts
/**
* Converts `value` to a finite number.
*
* @param value - The value to convert.
* @returns Returns the number.
*
* @example
* toFinite(3.2); // => 3.2
* toFinite(Number.MIN_VALUE); // => 5e-324
* toFinite(Infinity); // => 1.7976931348623157e+308
* toFinite('3.2'); // => 3.2
* toFinite(Symbol.iterator); // => 0
* toFinite(NaN); // => 0
*/
function toFinite(value) {
if (!value) return value === 0 ? value : 0;
value = require_toNumber.toNumber(value);
if (value === Infinity || value === -Infinity) return (value < 0 ? -1 : 1) * Number.MAX_VALUE;
return value === value ? value : 0;
}
//#endregion
exports.toFinite = toFinite;

View file

@ -0,0 +1,24 @@
import { toNumber } from "./toNumber.mjs";
//#region src/compat/util/toFinite.ts
/**
* Converts `value` to a finite number.
*
* @param value - The value to convert.
* @returns Returns the number.
*
* @example
* toFinite(3.2); // => 3.2
* toFinite(Number.MIN_VALUE); // => 5e-324
* toFinite(Infinity); // => 1.7976931348623157e+308
* toFinite('3.2'); // => 3.2
* toFinite(Symbol.iterator); // => 0
* toFinite(NaN); // => 0
*/
function toFinite(value) {
if (!value) return value === 0 ? value : 0;
value = toNumber(value);
if (value === Infinity || value === -Infinity) return (value < 0 ? -1 : 1) * Number.MAX_VALUE;
return value === value ? value : 0;
}
//#endregion
export { toFinite };

Some files were not shown because too many files have changed in this diff Show more