"use strict"; const VERSION = "Celestra v6.7.0 node"; (function (global) { if (!global.globalThis) { if (Object.defineProperty) { Object.defineProperty(global, "globalThis", { configurable: true, enumerable: false, value: global, writable: true }); } else { global.globalThis = global; } } })(typeof this === "object" ? this : Function("return this")()); if (!("sumPrecise" in Math)) { Math.sumPrecise = function sumPrecise([...array]) { if (array.length === 0) { return -0; } if (array.every((value) => typeof value === "number")) { let inf = array.indexOf(Infinity) > -1; let negInf = array.indexOf(-Infinity) > -1; if (array.some((value) => value !== value) || (inf && negInf)) { return NaN; } if (inf) { return Infinity; } if (negInf) { return -Infinity; } let hi = array.filter((value) => (value === 1e20 || value === -1e20)) .reduce((acc, value) => acc + value, 0); let lo = 0.0; let c = 0.0; for (let item of array.filter((value) => (value !== 1e20 && value !== -1e20))) { let y = item - c; let t = lo + y; c = (t - lo) - y; lo = t; } if ((lo === 0 && hi !== 0) || (lo > 0 && hi > 0) || (lo < 0 && hi < 0)) { return hi; } if ((lo > 0 && hi < 0) || (lo < 0 && hi > 0)) { return lo + hi; } return lo; } throw new TypeError("values passed to Math.sumPrecise must be numbers"); }; } if (!("isError" in Error)) { Error.isError = function isError(value) { let className = Object.prototype.toString.call(value).slice(8, -1).toLowerCase(); return (className === "error" || className === "domexception"); }; } if (("crypto" in globalThis) && !("randomUUID" in globalThis.crypto)) { globalThis.crypto.randomUUID = function randomUUID() { return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)); }; } if (!globalThis.GeneratorFunction) { globalThis.GeneratorFunction = Object.getPrototypeOf(function* () { }).constructor; } if (!globalThis.AsyncFunction) { globalThis.AsyncFunction = Object.getPrototypeOf(async function () { }).constructor; } if (!globalThis.AsyncGeneratorFunction) { globalThis.AsyncGeneratorFunction = Object.getPrototypeOf(async function* () { }).constructor; } const BASE16 = "0123456789ABCDEF"; const BASE32 = "234567ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const BASE36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const BASE58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; const WORDSAFEALPHABET = "23456789CFGHJMPQRVWXcfghjmpqvwx"; function assert(condition, message) { if (!condition) { if (Error.isError(message)) { throw message; } let errorMessage = `[assert] Assertion failed: ${condition} should be truly${message ? ` - ${message}` : ""}`; throw new Error(errorMessage, { cause: errorMessage }); } } const eq = (value1, value2) => value1 === value2 || (value1 !== value1 && value2 !== value2); const gt = (value1, value2) => typeOf(value1) === typeOf(value2) && value1 > value2; const gte = (value1, value2) => gt(value1, value2) || eq(value1, value2); const lt = (value1, value2) => typeOf(value1) === typeOf(value2) && value1 < value2; const lte = (value1, value2) => lt(value1, value2) || eq(value1, value2); const tap = (callback) => function (value) { callback(value); return value; }; function once(callback) { let called = false; let result; return function (...args) { if (!called) { called = true; result = callback(...args); } return result; }; } function curry(callback) { const curried = (...args) => args.length >= callback.length ? callback(...args) : (...rest) => curried(...args, ...rest); return curried; } const pipe = (...functions) => (first) => functions.reduce((value, callback) => callback(value), first); const compose = (...functions) => (first) => functions.reduceRight((value, callback) => callback(value), first); const pick = (obj, keys) => keys.reduce(function (acc, key) { if (key in obj) { acc[key] = obj[key]; } return acc; }, {}); const omit = (obj, keys) => Object.keys(obj).reduce(function (acc, key) { if (!keys.includes(key)) { acc[key] = obj[key]; } return acc; }, {}); const assoc = (obj, key, value) => ({ ...obj, [key]: value }); async function asyncNoop() { return new Promise(function (resolve) { resolve(); }); } async function asyncT() { return true; } async function asyncF() { return false; } function asyncConstant(value) { return async function () { return value; }; } async function asyncIdentity(value) { return value; } function randomUUIDv7(v4 = false) { let ts = Date.now().toString(16).padStart(12, "0") + (v4 ? "4" : "7"); let uuid = Array.from(([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16))); let index = 0; let pos = 0; while (index < 13) { if (pos === 8 || pos === 13) { pos++; } uuid[pos] = ts[index]; pos++; index++; } return uuid.join(""); } const delay = (milisec) => new Promise(resolve => setTimeout(resolve, milisec)); const randomBoolean = () => !Math.round(Math.random()); const getUrlVars = (str = location.search) => [...new URLSearchParams(str).entries()] .reduce(function (obj, item) { obj[item[0]] = item[1]; return obj; }, {}); const obj2string = (obj) => Object.keys(obj).reduce((str, key) => str += encodeURIComponent(key) + "=" + encodeURIComponent(obj[key]) + "&", "").slice(0, -1); function deepAssign(target, ...sources) { function _deepClone(value) { try { return structuredClone(value); } catch { return value; } } if (!sources.length) { return target == null ? target : _deepClone(target); } for (let source of sources) { Object.assign(target, _deepClone(source)); } return target; } const sizeIn = (obj) => Object.getOwnPropertyNames(obj).length + Object.getOwnPropertySymbols(obj).length; const unBind = (callback) => Function.prototype.call.bind(callback); const bind = Function.prototype.call.bind(Function.prototype.bind); const constant = (value) => () => value; const identity = (value) => value; function noop() { } const T = () => true; const F = () => false; function nanoid(size = 21, alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") { let result = ""; let dl = alphabet.length; let pos; let index = size; while (index--) { do { pos = crypto.getRandomValues(new Uint8Array(1))[0]; } while (pos >= dl); result += alphabet[pos]; } return result; } function timestampID(size = 21, alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") { let result = Date.now().toString(36).padStart(10, "0") + "-"; let dl = alphabet.length; let pos; let index = ((size > 11) ? size : 12) - 11; while (index--) { do { pos = crypto.getRandomValues(new Uint8Array(1))[0]; } while (pos >= dl); result += alphabet[pos]; } return result; } function b64Encode(str) { return btoa(encodeURIComponent(String(str)).replace(/%([0-9A-F]{2})/g, function toSolidBytes(_match, p1) { return String.fromCharCode("0x" + p1); })); } function b64Decode(str) { return decodeURIComponent(atob(String(str)).split("").map(function (c) { return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2); }).join("")); } function strCount(str, substr) { let count = (String(str)?.split(String(substr)) ?? []).length - 1; return count < 0 ? 0 : count; } function strTruncate(str, newLength, omission = "") { str = String(str); omission = String(omission); let strUC = Array.from(str); if (newLength >= strUC.length) { return str; } return strUC.slice(0, newLength - Array.from(omission).length).join("") + omission; } const strPropercase = (str) => String(str).trim().split(" ").map(function (value) { let chars = Array.from(value).map((c) => c.toLowerCase()); if (chars.length) { chars[0] = chars[0].toUpperCase(); } return chars.join(""); }).join(" "); const strTitlecase = (str) => String(str).trim().split(" ").map(function (value) { let chars = Array.from(value).map((c) => c.toLowerCase()); if (chars.length) { chars[0] = chars[0].toUpperCase(); } return chars.join(""); }).join(" "); function strCapitalize(str) { let chars = [...String(str).trim().toLowerCase()]; if (chars.length) { chars[0] = chars[0].toUpperCase(); } return chars.join(""); } function strUpFirst(str) { let chars = [...String(str).trim()]; if (chars.length) { chars[0] = chars[0].toUpperCase(); } return chars.join(""); } function strDownFirst(str) { let chars = [...String(str).trim()]; if (chars.length) { chars[0] = chars[0].toLowerCase(); } return chars.join(""); } const strReverse = (str) => Array.from(String(str)).reverse().join(""); const strCodePoints = (str) => Array.from(String(str), (value) => value.codePointAt(0)); const strFromCodePoints = ([...array]) => String.fromCodePoint(...array); function strAt(str, index, newChar) { let chars = Array.from(String(str)); if (newChar == null) { return chars.at(index) || ""; } index = index < 0 ? chars.length + index : index; if (index > chars.length) { return chars.join(""); } chars[index] = newChar; return chars.join(""); } const strSplice = (str, index, count, ...add) => Array.from(str).toSpliced(index, count, add.join("")).join(""); const strHTMLRemoveTags = (str) => String(str).trim().replace(/<[^>]*>/g, " ").replace(/\s{2,}/g, " ").trim(); const strHTMLEscape = (str) => String(str).trim() .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); const strHTMLUnEscape = (str) => String(str).trim() .replace(/&/g, "&").replace(/&/g, "&") .replace(/</g, "<").replace(/</g, "<") .replace(/>/g, ">").replace(/>/g, ">") .replace(/"/g, '"').replace(/"/g, '"') .replace(/'/g, "'").replace(/'/g, "'"); const isNonNullable = (value) => value != null; const isNonNullablePrimitive = (value) => value != null && typeof value !== "object" && typeof value !== "function"; function isArrowFunction(value) { if (typeof value !== "function" || ("prototype" in value && value.prototype !== undefined) || !(value.toString().includes("=>"))) { return false; } try { new value(); return false; } catch (error) { return true; } } const isAsyncIterator = (value) => value != null && typeof value.next === "function" && typeof value[Symbol.asyncIterator] === "function"; function isTypedCollection(iter, expectedType, Throw = false) { if (!isIterator(iter) && !isIterable(iter)) { throw new TypeError(`[isTypedCollection] TypeError: iter must be iterable or iterator. Got ${typeOf(iter)}`); } if (!(["string", "function"].includes(typeof expectedType)) && !Array.isArray(expectedType)) { throw new TypeError(`[isTypedCollection] TypeError: expectedType must be string, function, array. Got ${typeOf(expectedType)}`); } if (typeof Throw !== "boolean") { throw new TypeError(`[isTypedCollection] TypeError: Throw has to be a boolean. Got ${typeOf(Throw)}`); } let expectedArray = Array.isArray(expectedType) ? expectedType : [expectedType]; let matched = true; for (let value of iter) { const valueType = typeOf(value); matched = expectedArray.some(function (item) { if (typeof item === "string") { return valueType === item; } if (typeof item === "function") { return value != null && value instanceof item; } throw new TypeError(`[isTypedCollection] TypeError: expectedType array elements have to be a string or function. Got ${typeof item}`); }); if (!matched) { break; } } if (Throw && !matched) { let eNames = expectedArray.map((item) => (typeof item === "string" ? item.toString() : item.name ?? "anonymous")).join(", "); throw new TypeError(`[isTypedCollection] TypeError: one or more items are not ${eNames}`); } return matched; } function is(value, expectedType, Throw = false) { if (!(["string", "function", "undefined"].includes(typeof expectedType)) && !Array.isArray(expectedType)) { throw new TypeError(`[is] TypeError: expectedType must be string, function, array or undefined. Got ${typeOf(expectedType)}`); } if (typeof Throw !== "boolean") { throw new TypeError(`[is] TypeError: Throw has to be a boolean. Got ${typeOf(Throw)}`); } const vType = typeOf(value); if (expectedType == null) { return vType === "object" ? Object.getPrototypeOf(value)?.constructor ?? "object" : vType; } let expectedArray = Array.isArray(expectedType) ? expectedType : [expectedType]; let matched = expectedArray.some(function (item) { if (typeof item === "string") { return vType === item; } if (typeof item === "function") { return value != null && value instanceof item; } throw new TypeError(`[is] TypeError: expectedType array elements have to be a string or function. Got ${typeOf(item)}`); }); if (Throw && !matched) { let vName = value.toString ? value.toString() : Object.prototype.toString.call(value); let eNames = expectedArray.map((item) => (typeof item === "string" ? item.toString() : item.name ?? "anonymous")).join(", "); throw new TypeError(`[is] TypeError: ${vName} is not one of these: ${eNames}`); } return matched; } function toObject(value) { if (value == null) { throw new TypeError(`[toObject] error: ${value}`); } return (["object", "function"].includes(typeof value)) ? value : Object(value); } function toPrimitive(value) { if (value == null || typeof value !== "object") { return value; } const vType = Object.prototype.toString.call(value).slice(8, -1); if (["Boolean", "BigInt", "Number", "String", "Symbol"].includes(vType)) { return value.valueOf(); } return value; } function toSafeString(value) { const seen = new WeakSet(); function replacer(_key, value) { if (typeof value === "function") { return `[Function: ${value.name || "anonymous"}]`; } if (typeof value === "symbol") { return value.toString(); } if (value instanceof Date) { return `Date(${value.toISOString()})`; } if (value instanceof Error) { return `${value.name}: ${value.message}, ${value.stack ?? ""}`; } if (value && typeof value === "object") { if (seen.has(value)) { return "[Circular]"; } ; seen.add(value); } return value; } if (["undefined", "null", "string", "number", "boolean", "bigint"] .includes(typeOf(value))) { return String(value); } if (Array.isArray(value)) { return `[${value.map(v => toSafeString(v)).join(", ")}]`; } if (value instanceof Map) { return `Map(${value.size}){${Array.from(value.entries()).map(([k, v]) => `${toSafeString(k)} => ${toSafeString(v)}`).join(", ")}}`; } if (value instanceof Set) { return `Set(${value.size}){${Array.from(value.values()).map(v => toSafeString(v)).join(", ")}}`; } try { return JSON.stringify(value, replacer) ?? String(value); } catch (_e) { return String(value); } } const isPropertyKey = (value) => typeof value === "string" || typeof value === "symbol"; const toPropertyKey = (value) => typeof value === "symbol" ? value : String(value); const isIndex = (value) => Number.isSafeInteger(value) && value >= 0 && value <= Number.MAX_SAFE_INTEGER && 1 / value !== 1 / -0; const isLength = (value) => Number.isSafeInteger(value) && value >= 0 && value <= Number.MAX_SAFE_INTEGER && 1 / value !== 1 / -0; function toIndex(value) { value = ((value = Math.trunc(+value)) !== value || value === 0) ? 0 : value; if (value < 0 || value > Number.MAX_SAFE_INTEGER) { throw new RangeError(`[toIndex] RangeError: ${value}`); } return value; } function toLength(value) { value = ((value = Math.trunc(+value)) !== value || value === 0) ? 0 : value; return Math.min(Math.max(value, 0), Number.MAX_SAFE_INTEGER); } const typeOf = (value) => value === null ? "null" : typeof value; const isSameType = (value1, value2) => typeOf(value1) === typeOf(value2); const isSameInstance = (value1, value2, Contructor) => value1 instanceof Contructor && value2 instanceof Contructor; function isCoercedObject(value) { if (typeOf(value) === "object") { if (value instanceof Number) { return Number; } if (value instanceof String) { return String; } if (value instanceof Boolean) { return Boolean; } if (value instanceof BigInt) { return BigInt; } if (typeof value.valueOf?.() === "symbol") { return Symbol; } } return false; } function isDeepStrictEqual(value1, value2) { const _deepTypeOf = (value) => (value === null) ? "null" : (value !== value) ? "NaN" : (typeof value); const _classOf = (value) => Object.prototype.toString.call(value).slice(8, -1).toLowerCase(); if (Object.is(value1, value2)) { return true; } if (_deepTypeOf(value1) === "object" && isPrimitive(value2) && _classOf(value1) === typeof value2) { return Object.is(value1.valueOf(), value2); } if (isPrimitive(value1) && _deepTypeOf(value2) === "object" && typeof value1 === _classOf(value2)) { return Object.is(value1, value2.valueOf()); } if (_deepTypeOf(value1) !== _deepTypeOf(value2)) { return false; } if (_deepTypeOf(value1) === "object" && _deepTypeOf(value2) === "object") { if (Object.is(value1, value2)) { return true; } if (Object.getPrototypeOf(value1).constructor !== Object.getPrototypeOf(value2).constructor) { return false; } if (isSameInstance(value1, value2, WeakMap) || isSameInstance(value1, value2, WeakSet)) { return Object.is(value1, value2); } if (isSameInstance(value1, value2, Number) || isSameInstance(value1, value2, Boolean) || isSameInstance(value1, value2, String) || isSameInstance(value1, value2, BigInt)) { return Object.is(value1.valueOf(), value2.valueOf()); } if (Array.isArray(value1) && Array.isArray(value2)) { if (value1.length !== value2.length) { return false; } if (value1.length === 0) { return true; } return value1.every((value, index) => isDeepStrictEqual(value, value2[index])); } if ((ArrayBuffer.isView(value1) && !(value1 instanceof DataView)) && (ArrayBuffer.isView(value2) && !(value2 instanceof DataView)) && _classOf(value1) === _classOf(value2)) { if (value1.length !== value2.length) { return false; } if (value1.length === 0) { return true; } return value1.every((value, index) => Object.is(value, value2[index])); } if (isSameInstance(value1, value2, ArrayBuffer)) { if (value1.byteLength !== value2.byteLength) { return false; } if (value1.byteLength === 0) { return true; } let xTA = new Int8Array(value1), yTA = new Int8Array(value2); return xTA.every((value, index) => Object.is(value, yTA[index])); } if (isSameInstance(value1, value2, DataView)) { if (value1.byteLength !== value2.byteLength) { return false; } if (value1.byteLength === 0) { return true; } for (let index = 0; index < value1.byteLength; index++) { if (!Object.is(value1.getUint8(index), value2.getUint8(index))) { return false; } } return true; } if (isSameInstance(value1, value2, Map)) { if (value1.size !== value2.size) { return false; } if (value1.size === 0) { return true; } return [...value1.keys()].every((value) => isDeepStrictEqual(value1.get(value), value2.get(value))); } if (isSameInstance(value1, value2, Set)) { if (value1.size !== value2.size) { return false; } if (value1.size === 0) { return true; } return [...value1.keys()].every((value) => value2.has(value)); } if (isSameInstance(value1, value2, RegExp)) { return Object.is(value1.lastIndex, value2.lastIndex) && Object.is(value1.flags, value2.flags) && Object.is(value1.source, value2.source); } if (isSameInstance(value1, value2, Error)) { return isDeepStrictEqual(Object.getOwnPropertyNames(value1) .reduce(function (acc, k) { acc[k] = value1[k]; return acc; }, {}), Object.getOwnPropertyNames(value2) .reduce(function (acc, k) { acc[k] = value2[k]; return acc; }, {})); } if (isSameInstance(value1, value2, Date)) { return Object.is(+value1, +value2); } let value1Keys = Reflect.ownKeys(value1); let value2Keys = Reflect.ownKeys(value2); if (value1Keys.length !== value2Keys.length) { return false; } if (value1Keys.length === 0) { return true; } return value1Keys.every((key) => isDeepStrictEqual(value1[key], value2[key])); } return false; } function isEmpty(value) { if (value == null || Number.isNaN(value)) { return true; } if (Array.isArray(value) || (ArrayBuffer.isView(value) && !(value instanceof DataView)) || typeof value === "string" || value instanceof String) { return value.length === 0; } if (value instanceof Map || value instanceof Set) { return value.size === 0; } if (value instanceof ArrayBuffer || value instanceof DataView) { return value.byteLength === 0; } if (typeof value[Symbol.iterator] === "function") { const it = value[Symbol.iterator](); return it.next().done; } if ("Iterator" in globalThis ? (value instanceof Iterator) : (typeOf(value) === "object" && typeof value.next === "function")) { try { for (let _item of value) { return false; } return true; } catch { } } if (typeOf(value) === "object") { const keys = Reflect.ownKeys(value); if (keys.length === 0) { return true; } if (keys.length === 1 && keys[0] === "length" && value.length === 0) { return true; } } return false; } const isProxy = (value) => Boolean(value != null && value.__isProxy); const isAsyncGeneratorFunction = (value) => Object.getPrototypeOf(value).constructor === Object.getPrototypeOf(async function* () { }).constructor; function isPlainObject(value) { if (value === null || typeof value !== "object") { return false; } const proto = Object.getPrototypeOf(value); return proto === Object.prototype || proto === null; } const isObject = (value) => value !== null && typeof value === "object"; const isFunction = (value) => typeof value === "function"; function isArraylike(value) { if (value == null || (typeof value !== "object" && typeof value !== "string")) { return false; } const maybe = value; if (typeof maybe.length !== "number") { return false; } const len = maybe.length; return len >= 0 && Number.isFinite(len); } const isNull = (value) => value === null; const isUndefined = (value) => value === undefined; const isNullish = (value) => value == null; const isPrimitive = (value) => value == null || (typeof value !== "object" && typeof value !== "function"); const isIterator = (value) => "Iterator" in globalThis ? value instanceof Iterator : (typeOf(value) === "object" && typeof value.next === "function"); const isRegexp = (value) => value instanceof RegExp; const isElement = (value) => typeOf(value) === "object" && value.nodeType === 1; const isIterable = (value) => value != null && typeof value[Symbol.iterator] === "function"; const isAsyncIterable = (value) => value != null && typeof value[Symbol.asyncIterator] === "function"; const isTypedArray = (value) => ArrayBuffer.isView(value) && !(value instanceof DataView); const isGeneratorFunction = (value) => Object.getPrototypeOf(value).constructor === Object.getPrototypeOf(function* () { }).constructor; const isAsyncFunction = (value) => Object.getPrototypeOf(value).constructor === Object.getPrototypeOf(async function () { }).constructor; const castArray = (value) => typeof value === "undefined" ? [] : (Array.isArray(value) ? value : [value]); const compact = (iter) => Array.from(iter).filter((value) => value != null); function unique(iter, resolver) { if (resolver == null) { return [...new Set(iter)]; } if (typeof resolver === "string") { return Array.from(iter).reduce(function (acc, item) { if (acc.every((item2) => item2[resolver] !== item[resolver])) { acc.push(item); } return acc; }, []); } if (typeof resolver === "function") { let cache = new Map(); for (let item of iter) { let key = resolver(item); if (!cache.has(key)) { cache.set(key, item); } } return [...cache.values()]; } } function count(iter, callback) { let index = 0; let result = 0; for (let item of iter) { if (callback(item, index++)) { result++; } } return result; } function arrayDeepClone([...array]) { const _ADC = (value) => Array.isArray(value) ? Array.from(value, _ADC) : value; return _ADC(array); } const initial = ([...array]) => array.slice(0, -1); function shuffle([...array]) { for (let index = array.length - 1; index > 0; index--) { let pos = Math.floor(Math.random() * (index + 1)); [array[index], array[pos]] = [array[pos], array[index]]; } return array; } const partition = ([...array], callback) => [array.filter(callback), array.filter((value, index, a) => !(callback(value, index, a)))]; const min = (...args) => args.reduce((acc, value) => (value < acc ? value : acc), args[0]); const max = (...args) => args.reduce((acc, value) => (value > acc ? value : acc), args[0]); const arrayRepeat = (value, num = 100) => Array(num).fill(value); const arrayCycle = ([...array], num = 100) => Array(num).fill(array).flat(); const arrayRange = (start = 0, end = 99, step = 1) => Array.from({ length: (end - start) / step + 1 }, (_v, i) => start + (i * step)); function zip(...args) { args = args.map((value) => Array.from(value)); return Array.from({ length: Math.min(...args.map(v => v.length)) }) .map((_, i) => args.map(v => v[i])); } const unzip = ([...array]) => array.map((iter) => Array.from(iter)) .reduce(function (acc, value) { value.forEach(function (item, index) { if (!Array.isArray(acc[index])) { acc[index] = []; } acc[index].push(item); }); return acc; }, []); function zipObj([...array1], [...array2]) { let result = {}; let length = Math.min(array1.length, array2.length); for (let index = 0; index < length; index++) { result[array1[index]] = array2[index]; } return result; } const arrayAdd = (array, value) => !array.includes(value) ? !!array.push(value) : false; function arrayClear(array) { array.length = 0; return array; } function arrayRemove(array, value, all = false) { let found = array.indexOf(value) > -1; if (!all) { let pos = array.indexOf(value); if (pos > -1) { array.splice(pos, 1); } } else { let pos = -1; while ((pos = array.indexOf(value)) > -1) { array.splice(pos, 1); } } return found; } function arrayRemoveBy(array, callback, all = false) { let found = array.findIndex(callback) > -1; if (!all) { let pos = array.findIndex(callback); if (pos > -1) { array.splice(pos, 1); } } else { let pos = -1; while ((pos = array.findIndex(callback)) > -1) { array.splice(pos, 1); } } return found; } function arrayMerge(target, ...sources) { target.push(...[].concat(...sources)); return target; } function* iterRange(start = 0, step = 1, end = Infinity) { let index = start; while (index <= end) { yield index; index += step; } } function* iterCycle([...array], num = Infinity) { let index = 0; while (index++ < num) { yield* array; } } function* iterRepeat(value, num = Infinity) { let index = 0; while (index++ < num) { yield value; } } function* takeWhile(iter, callback) { let iterator; if (typeof iter.next === "function") { iterator = iter; } else { iterator = iter[Symbol.iterator](); } while (true) { const { value, done } = iterator.next(); if (done || !callback(value)) { break; } yield value; } } function* dropWhile(iter, callback) { let iterator; if (typeof iter.next === "function") { iterator = iter; } else { iterator = iter[Symbol.iterator](); } let skip = true; while (true) { const { value, done } = iterator.next(); if (done) { break; } if (skip) { skip = callback(value); } if (!skip) { yield value; } } } function* take(iter, num = 1) { if (num <= 0) { return; } let iterator; if (typeof iter.next === "function") { iterator = iter; } else { iterator = iter[Symbol.iterator](); } for (let index = 0; index < num; index++) { const { value, done } = iterator.next(); if (done) { break; } ; yield value; } } function* drop(iter, num = 1) { if (num <= 0) { yield* (typeof iter.next === "function" ? { [Symbol.iterator]: () => iter } : iter); return; } let iterator; if (typeof iter.next === "function") { iterator = iter; } else { iterator = iter[Symbol.iterator](); } for (let index = 0; index < num; index++) { const { done } = iterator.next(); if (done) { return; } ; } while (true) { const { value, done } = iterator.next(); if (done) { break; } ; yield value; } } function forEach(iter, callback) { let index = 0; for (let item of iter) { callback(item, index++); } } function forEachRight([...array], callback) { let index = array.length; while (index--) { callback(array[index], index); } } function* map(iter, callback) { let index = 0; for (let item of iter) { yield callback(item, index++); } } function* filter(iter, callback) { let index = 0; for (let item of iter) { if (callback(item, index++)) { yield item; } } } function* reject(iter, callback) { let index = 0; for (let item of iter) { if (!callback(item, index++)) { yield item; } } } function* slice(iter, begin = 0, end = Infinity) { if (begin < 0) { begin = 0; } if (end <= begin) { return; } let iterator; if (typeof iter.next === "function") { iterator = iter; } else { iterator = iter[Symbol.iterator](); } let index = 0; while (true) { const { value, done } = iterator.next(); if (done) { break; } ; if (index >= begin && index <= end) { yield value; } if (index > end - 1) break; index++; } } function* tail(input) { let iterator; if (typeof input.next === "function") { iterator = input; } else { iterator = input[Symbol.iterator](); } const first = iterator.next(); if (first.done) { return; } while (true) { const { value, done } = iterator.next(); if (done) { break; } yield value; } } function item(iter, pos) { if (pos < 0) { return undefined; } let iterator; if (typeof iter.next === "function") { iterator = iter; } else { iterator = iter[Symbol.iterator](); } let index = 0; while (true) { const { value, done } = iterator.next(); if (done) { return undefined; } if (index === pos) { return value; } index++; } } function nth(iter, pos) { if (pos < 0) { return undefined; } let iterator; if (typeof iter.next === "function") { iterator = iter; } else { iterator = iter[Symbol.iterator](); } let index = 0; while (true) { const { value, done } = iterator.next(); if (done) { return undefined; } if (index === pos) { return value; } index++; } } function size(value) { if (Array.isArray(value)) { return value.length; } if (value instanceof Map || value instanceof Set) { return value.size; } if (value instanceof ArrayBuffer || value instanceof DataView) { return value.byteLength; } if (typeof value.size === "number") { return value.size; } let iterator; if (typeof value.next === "function") { iterator = value; } else { iterator = value[Symbol.iterator](); } let index = 0; for (let _item of iterator) { index++; } return index; } function first(input) { let iterator; if (typeof input.next === "function") { iterator = input; } else { iterator = input[Symbol.iterator](); } const result = iterator.next(); return result.done ? undefined : result.value; } function head(input) { let iterator; if (typeof input.next === "function") { iterator = input; } else { iterator = input[Symbol.iterator](); } const result = iterator?.next() ?? { value: undefined, done: true }; return result.done ? undefined : result.value; } const last = ([...array]) => array[array.length - 1]; function* reverse([...array]) { let index = array.length; while (index--) { yield array[index]; } } const sort = ([...array], numbers = false) => array.sort(numbers ? (value1, value2) => value1 - value2 : undefined); function includes(collection, value, comparator) { if (comparator !== undefined && typeof comparator !== "function") { throw new TypeError(`[includes] TypeError: comparator is not a function or undefined. Got ${typeof comparator}`); } const _isEqual = comparator ?? ((value1, value2) => value1 === value2 || (value1 !== value1 && value2 !== value2)); const cType = (typeOf(collection)); if (collection == null || !(["object", "function", "string"].includes(cType)) || collection instanceof WeakMap || collection instanceof WeakSet) { return false; } if (typeof collection === "string" || collection instanceof String) { return collection.includes(String(value)); } if (collection instanceof Map) { if ([...collection.keys()].findIndex((item) => _isEqual(item, value)) > -1) { return true; } if ([...collection.values()].findIndex((item) => _isEqual(item, value)) > -1) { return true; } return false; } if (isIterator(collection) || isIterable(collection)) { if ([...collection].findIndex((item) => _isEqual(item, value)) > -1) { return true; } return false; } if (["object", "function"].includes(cType)) { if (Object.keys(collection).findIndex((item) => _isEqual(item, value)) > -1) { return true; } if (Object.values(collection).findIndex((item) => _isEqual(item, value)) > -1) { return true; } if (Object.getOwnPropertySymbols(collection) .findIndex((item) => _isEqual(item, value)) > -1) { return true; } return false; } return false; } const find = ([...array], callback) => array.find((value, index) => callback(value, index)); const findLast = ([...array], callback) => array.findLast((value, index) => callback(value, index)); const every = ([...array], callback) => array.length ? array.every((value, index) => callback(value, index)) : false; const some = ([...array], callback) => array.length ? array.some((value, index) => callback(value, index)) : false; const none = ([...array], callback) => !array.some((value, index) => callback(value, index)); const takeRight = ([...array], num = 1) => array.reverse().slice(0, num); function* takeRightWhile([...array], callback) { if (!array.length) { return; } let index = array.length; while (index--) { let item = array[index]; if (!callback(item, index)) { break; } yield item; } } const dropRight = ([...array], num = 1) => array.reverse().slice(num); function* dropRightWhile([...array], callback) { if (!array.length) { return; } let index = array.length; let skip = true; while (index--) { let item = array[index]; if (skip) { skip = callback(item, index); } if (!skip) { yield item; } } } function* concat(...args) { for (let item of args) { if (typeof item[Symbol.iterator] === "function" || ("Iterator" in globalThis ? (item instanceof Iterator) : (typeOf(item) === "object" && typeof item.next === "function"))) { yield* item; } else { yield item; } } } function reduce(iter, callback, initialvalue) { let acc = initialvalue; let index = 0; for (let item of iter) { if (index === 0 && acc === undefined) { acc = item; } else { acc = callback(acc, item, index++); } } return acc; } function* enumerate(iter, offset = 0) { let index = offset; for (let item of iter) { yield [index++, item]; } } function* flat(iter) { for (let item of iter) { if (typeof item[Symbol.iterator] === "function" || ("Iterator" in globalThis ? (item instanceof Iterator) : (typeof item === "object" && typeof item.next === "function"))) { yield* item; } else { yield item; } } } function join(iter, separator = ",") { separator = String(separator); let result = ""; for (let item of iter) { result += separator + item; } return result.slice(separator.length); } const withOut = ([...array], [...filterValues]) => array.filter((value) => !filterValues.includes(value)); function add(value1, value2) { if (typeof value1 !== typeof value2 || (typeof value1 !== "number" && typeof value1 !== "bigint")) { throw new TypeError(`[add] value1 and value2 must be of the same type and either number or bigint. Got: ${typeof value1} and ${typeof value2}`); } if (typeof value1 === "number" && typeof value2 === "number") { return Math.sumPrecise([value1, value2]); } return value1 + value2; } function sub(value1, value2) { if (typeof value1 !== typeof value2 || (typeof value1 !== "number" && typeof value1 !== "bigint")) { throw new TypeError(`[sub] value1 and value2 must be of the same type and either number or bigint. Got: ${typeof value1} and ${typeof value2}`); } if (typeof value1 === "number" && typeof value2 === "number") { Math.sumPrecise([value1, -value2]); } return value1 - value2; } function mul(value1, value2) { if (typeof value1 !== typeof value2 || (typeof value1 !== "number" && typeof value1 !== "bigint")) { throw new TypeError(`[mul] value1 and value2 must be of the same type and either number or bigint. Got: ${typeof value1} and ${typeof value2}`); } if (typeof value1 === "number" && typeof value2 === "number") { return value1 * value2; } return value1 * value2; } function div(value1, value2) { if (typeof value1 !== typeof value2 || (typeof value1 !== "number" && typeof value1 !== "bigint")) { throw new TypeError(`[div] value1 and value2 must be of the same type and either number or bigint. Got: ${typeof value1} and ${typeof value2}`); } if (value2 === 0 || value2 === 0n) { throw new RangeError("[div] Cannot divide by zero"); } if (typeof value1 === "number" && typeof value2 === "number") { return value1 / value2; } return value1 / value2; } function divMod(value1, value2) { if (typeof value1 !== typeof value2 || (typeof value1 !== "number" && typeof value1 !== "bigint")) { throw new TypeError(`[divMod] value1 and value2 must be of the same type and either number or bigint. Got: ${typeof value1} and ${typeof value2}`); } if (value2 === 0 || value2 === 0n) { throw new RangeError("[divMod] Cannot divide by zero"); } if (typeof value1 === "number" && typeof value2 === "number") { return Math.trunc(value1 / value2); } return value1 / value2; } function mod(value1, value2) { if (typeof value1 !== typeof value2 || (typeof value1 !== "number" && typeof value1 !== "bigint")) { throw new TypeError(`[mod] value1 and value2 must be of the same type and either number or bigint. Got: ${typeof value1} and ${typeof value2}`); } if (value2 === 0 || value2 === 0n) { throw new RangeError("[mod] Cannot divide by zero"); } if (typeof value1 === "number" && typeof value2 === "number") { return Math.trunc(value1 % value2); } return value1 % value2; } const isFloat = (value) => typeof value === "number" && value === value && Boolean(value % 1); function toInteger(value) { value = ((value = Math.trunc(Number(value))) !== value || value === 0) ? 0 : value; return Math.min(Math.max(value, Number.MIN_SAFE_INTEGER), Number.MAX_SAFE_INTEGER); } const toIntegerOrInfinity = (value) => ((value = Math.trunc(Number(value))) !== value || value === 0) ? 0 : value; function sum(...args) { if (!args.every((value) => typeof value === "number") && !args.every((value) => typeof value === "bigint")) { throw new TypeError(`[sum] all arguments must be of the same type and either number or bigint. Got: ${args.map((v) => typeOf(v)).join(", ")}`); } return args.every((value) => typeof value === "number") ? Math.sumPrecise(args) : args.slice(1).reduce((acc, value) => acc + value, args[0]); } const avg = (...args) => Math.sumPrecise(args) / args.length; function product(first, ...args) { if (typeof first === "bigint") { return args .reduce((acc, v) => acc * v, first); } return args .reduce((acc, v) => acc * v, first); } function pow(base, power) { if (typeOf(base) !== typeOf(power) || (typeof base !== "number" && typeof base !== "bigint")) { throw new TypeError(`[pow] base and power must be of the same type and either number or bigint. Got: ${typeOf(base)} and ${typeOf(power)}`); } if (typeof base === "bigint" && typeof power === "bigint") { return base ** power; } return Math.pow(base, power); } function clamp(value, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) { function _numberNormalize(value) { if (typeof value !== "bigint" && typeof value !== "number") { value = Number(value); } if (value === -Infinity) { return Number.MIN_SAFE_INTEGER; } if (value === Infinity) { return Number.MAX_SAFE_INTEGER; } if (value === 0) { return 0; } return value; } if (typeof value !== "bigint" && typeof min !== "bigint" && typeof min !== "bigint") { value = _numberNormalize(value); min = _numberNormalize(min); max = _numberNormalize(max); } if (value !== value) { return value; } if (min !== min || max !== max) { throw new RangeError("[clamp] RangeError: minimum and maximum should not to be NaN"); } if (min > max) { throw new RangeError("[clamp] RangeError: minimum should be lower than maximum"); } return (value < min) ? min : ((value > max) ? max : value); } function minmax(value, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) { function _numberNormalize(value) { if (typeof value !== "bigint" && typeof value !== "number") { value = Number(value); } if (value === -Infinity) { return Number.MIN_SAFE_INTEGER; } if (value === Infinity) { return Number.MAX_SAFE_INTEGER; } if (value === 0) { return 0; } return value; } if (typeof value !== "bigint" && typeof min !== "bigint" && typeof min !== "bigint") { value = _numberNormalize(value); min = _numberNormalize(min); max = _numberNormalize(max); } if (value !== value) { return value; } if (min !== min || max !== max) { throw new RangeError("[minmax] RangeError: minimum and maximum should not to be NaN"); } if (min > max) { throw new RangeError("[minmax] RangeError: minimum should be lower than maximum"); } return (value < min) ? min : ((value > max) ? max : value); } function isEven(value) { if (typeof value === "number" && Number.isSafeInteger(value)) { return value % 2 === 0; } if (typeof value === "bigint") { return value % 2n === 0n; } return false; } function isOdd(value) { if (typeof value === "number" && Number.isSafeInteger(value)) { return value % 2 !== 0; } if (typeof value === "bigint") { return value % 2n !== 0n; } return false; } const toInt8 = (value) => ((value = Math.min(Math.max(-128, Math.trunc(Number(value))), 127)) === value) ? value : 0; const toUInt8 = (value) => ((value = Math.min(Math.max(0, Math.trunc(Number(value))), 255)) === value) ? value : 0; const toInt16 = (value) => ((value = Math.min(Math.max(-32768, Math.trunc(Number(value))), 32767)) === value) ? value : 0; const toUInt16 = (value) => ((value = Math.min(Math.max(0, Math.trunc(Number(value))), 65535)) === value) ? value : 0; const toInt32 = (value) => ((value = Math.min(Math.max(-2147483648, Math.trunc(Number(value))), 2147483647)) === value) ? value : 0; const toUInt32 = (value) => ((value = Math.min(Math.max(0, Math.trunc(Number(value))), 4294967295)) === value) ? value : 0; const toBigInt64 = (value) => BigInt(typeof value === "bigint" ? (value > Math.pow(2, 63) - 1 ? Math.pow(2, 63) - 1 : value < Math.pow(-2, 63) ? Math.pow(-2, 63) : value) : ((value = Math.min(Math.max(Math.pow(-2, 63), Math.trunc(Number(value))), Math.pow(2, 63) - 1)) === value) ? value : 0); const toBigUInt64 = (value) => BigInt(typeof value === "bigint" ? (value > Math.pow(2, 64) - 1 ? Math.pow(2, 64) - 1 : value < 0 ? 0 : value) : ((value = Math.min(Math.max(0, Math.trunc(Number(value))), Math.pow(2, 64) - 1)) === value) ? value : 0); const toFloat32 = (value) => ((value = Math.min(Math.max(-3.4e38, Number(value)), 3.4e38)) === value) ? value : 0; const isInt8 = (value) => Number.isInteger(value) && value >= -128 && value <= 127; const isUInt8 = (value) => Number.isInteger(value) && value >= 0 && value <= 255; const isInt16 = (value) => Number.isInteger(value) && value >= -32768 && value <= 32767; const isUInt16 = (value) => Number.isInteger(value) && value >= 0 && value <= 65535; const isInt32 = (value) => Number.isInteger(value) && value >= -2147483648 && value <= 2147483647; const isUInt32 = (value) => Number.isInteger(value) && value >= 0 && value <= 4294967295; const isBigInt64 = (value) => typeof value === "bigint" && value >= Math.pow(-2, 63) && value <= Math.pow(2, 63) - 1; const isBigUInt64 = (value) => typeof value === "bigint" && value >= 0 && value <= Math.pow(2, 64) - 1; const toFloat16 = (value) => ((value = Math.min(Math.max(-65504, Number(value)), 65504)) === value) ? value : 0; const isFloat16 = (value) => typeof value === "number" && value === value && value >= -65504 && value <= 65504; const signbit = (value) => ((value = Number(value)) !== value) ? false : (Object.is(value, -0) || (typeof value === "number" && value < 0 || typeof value === "bigint" && value < 0n)); function randomInt(min = 100, max) { if (max == null) { max = min; min = 0; } min = Math.ceil(Number(min)); return Math.floor(Math.random() * (Math.floor(Number(max)) - min + 1) + min); } function randomFloat(min = 100, max) { if (max == null) { max = min; min = 0; } let result = (Math.random() * (max - min + 1)) + min; return result > max ? max : result; } function inRange(value, min, max) { if ((typeof value === "number" && typeof min === "number" && typeof max === "number") || (typeof value === "bigint" && typeof min === "bigint" && typeof max === "bigint")) { return value >= min && value <= max; } return false; } export default { VERSION, BASE16, BASE32, BASE36, BASE58, BASE62, WORDSAFEALPHABET, assert, eq, gt, gte, lt, lte, tap, once, curry, pipe, compose, pick, omit, assoc, asyncNoop, asyncT, asyncF, asyncConstant, asyncIdentity, randomUUIDv7, delay, randomBoolean, getUrlVars, obj2string, deepAssign, sizeIn, unBind, bind, constant, identity, noop, T, F, nanoid, timestampID, b64Encode, b64Decode, strCount, strTruncate, strPropercase, strTitlecase, strCapitalize, strUpFirst, strDownFirst, strReverse, strCodePoints, strFromCodePoints, strAt, strSplice, strHTMLRemoveTags, strHTMLEscape, strHTMLUnEscape, isNonNullable, isNonNullablePrimitive, isArrowFunction, isAsyncIterator, isTypedCollection, is, toObject, toPrimitive, toSafeString, isPropertyKey, toPropertyKey, isIndex, isLength, toIndex, toLength, typeOf, isSameType, isSameInstance, isCoercedObject, isDeepStrictEqual, isEmpty, isProxy, isAsyncGeneratorFunction, isPlainObject, isObject, isFunction, isArraylike, isNull, isUndefined, isNullish, isPrimitive, isIterator, isRegexp, isElement, isIterable, isAsyncIterable, isTypedArray, isGeneratorFunction, isAsyncFunction, castArray, compact, unique, count, arrayDeepClone, initial, shuffle, partition, min, max, arrayRepeat, arrayCycle, arrayRange, zip, unzip, zipObj, arrayAdd, arrayClear, arrayRemove, arrayRemoveBy, arrayMerge, iterRange, iterCycle, iterRepeat, takeWhile, dropWhile, take, drop, forEach, forEachRight, map, filter, reject, slice, tail, item, nth, size, first, head, last, reverse, sort, includes, find, findLast, every, some, none, takeRight, takeRightWhile, dropRight, dropRightWhile, concat, reduce, enumerate, flat, join, withOut, add, sub, mul, div, divMod, mod, isFloat, toInteger, toIntegerOrInfinity, sum, avg, product, pow, clamp, minmax, isEven, isOdd, toInt8, toUInt8, toInt16, toUInt16, toInt32, toUInt32, toBigInt64, toBigUInt64, toFloat32, isInt8, isUInt8, isInt16, isUInt16, isInt32, isUInt32, isBigInt64, isBigUInt64, toFloat16, isFloat16, signbit, randomInt, randomFloat, inRange }; export { VERSION, BASE16, BASE32, BASE36, BASE58, BASE62, WORDSAFEALPHABET, assert, eq, gt, gte, lt, lte, tap, once, curry, pipe, compose, pick, omit, assoc, asyncNoop, asyncT, asyncF, asyncConstant, asyncIdentity, randomUUIDv7, delay, randomBoolean, getUrlVars, obj2string, deepAssign, sizeIn, unBind, bind, constant, identity, noop, T, F, nanoid, timestampID, b64Encode, b64Decode, strCount, strTruncate, strPropercase, strTitlecase, strCapitalize, strUpFirst, strDownFirst, strReverse, strCodePoints, strFromCodePoints, strAt, strSplice, strHTMLRemoveTags, strHTMLEscape, strHTMLUnEscape, isNonNullable, isNonNullablePrimitive, isArrowFunction, isAsyncIterator, isTypedCollection, is, toObject, toPrimitive, toSafeString, isPropertyKey, toPropertyKey, isIndex, isLength, toIndex, toLength, typeOf, isSameType, isSameInstance, isCoercedObject, isDeepStrictEqual, isEmpty, isProxy, isAsyncGeneratorFunction, isPlainObject, isObject, isFunction, isArraylike, isNull, isUndefined, isNullish, isPrimitive, isIterator, isRegexp, isElement, isIterable, isAsyncIterable, isTypedArray, isGeneratorFunction, isAsyncFunction, castArray, compact, unique, count, arrayDeepClone, initial, shuffle, partition, min, max, arrayRepeat, arrayCycle, arrayRange, zip, unzip, zipObj, arrayAdd, arrayClear, arrayRemove, arrayRemoveBy, arrayMerge, iterRange, iterCycle, iterRepeat, takeWhile, dropWhile, take, drop, forEach, forEachRight, map, filter, reject, slice, tail, item, nth, size, first, head, last, reverse, sort, includes, find, findLast, every, some, none, takeRight, takeRightWhile, dropRight, dropRightWhile, concat, reduce, enumerate, flat, join, withOut, add, sub, mul, div, divMod, mod, isFloat, toInteger, toIntegerOrInfinity, sum, avg, product, pow, clamp, minmax, isEven, isOdd, toInt8, toUInt8, toInt16, toUInt16, toInt32, toUInt32, toBigInt64, toBigUInt64, toFloat32, isInt8, isUInt8, isInt16, isUInt16, isInt32, isUInt32, isBigInt64, isBigUInt64, toFloat16, isFloat16, signbit, randomInt, randomFloat, inRange };