UNPKG

@utilify/core

Version:

Modern, strongly typed, and safe utility function library for JavaScript and TypeScript. Includes type checking, manipulation of arrays, objects, strings, dates, colors, numbers, regular expressions, and more. Compatible with Browser, Node.js, Deno, and B

1 lines 50.9 kB
"use strict";function e(e){return e!=e}function r(e){if("number"!=typeof e)throw new TypeError("Expected a number for 'value'");return e===1/0||e===-1/0}function t(e){return"[object Array]"===Object.prototype.toString.call(e)}function n(e){return null===e}function o(e){return"function"==typeof e}function i(e){return e instanceof Date}function a(e){return e instanceof Map}function f(e){return null==e}function s(e){return"object"==typeof e&&!n(e)&&!t(e)}function u(e){return e instanceof RegExp}function c(e){return e instanceof Set}function p(e){return"string"==typeof e}function l(e,r=1){if(!t(e)&&!p(e))throw new TypeError("Expected an array for 'array'");if("number"!=typeof r||r<=0)throw new TypeError("Expected a non-zero integer number for 'size'");const n=[];for(let t=0;t<e.length;t+=r)n.push(e.slice(t,t+r));return n}function d(e,r=(e,r)=>r){if(!t(e))throw new TypeError("Expected an array for 'array'");if("function"!=typeof r)throw new TypeError("Expected a function for 'keySelector'");const n={};for(let t=0;t<e.length;t++){const o=e[t],i=r(o,t);i in n||(n[i]=[]),n[i].push(o)}return n}function y(e){return structuredClone(e)}function w(e){if("[object Object]"!==Object.prototype.toString.call(e))return!1;const r=Object.getPrototypeOf(e);return null===r||r===Object.prototype}function h(e){return"object"==typeof e&&null!==e}function x(e,r){function n(e,r,o=new WeakMap){return!!Object.is(e,r)||!(!h(e)||!h(r))&&(t(e)&&t(r)?function(e,r,t){const o=Object.keys(e),i=Object.keys(r);if(o.length!==i.length)return!1;for(let o=0;o<e.length;o++)if(!n(e[o],r[o],t))return!1;return!0}(e,r,o):i(e)&&i(r)?function(e,r){return e.getTime()===r.getTime()}(e,r):u(e)&&u(r)?function(e,r){return e.source===r.source&&e.flags===r.flags}(e,r):a(e)&&a(r)?function(e,r,t){if(e.size!==r.size)return!1;for(const[o,i]of e)if(!r.has(o)||!n(i,r.get(o),t))return!1;return!0}(e,r,o):c(e)&&c(r)?function(e,r){if(e.size!==r.size)return!1;for(const t of e)if(!r.has(t))return!1;return!0}(e,r):ArrayBuffer.isView(e)&&ArrayBuffer.isView(r)?function(e,r){if(Object.getPrototypeOf(e)!==Object.getPrototypeOf(r)||e.byteLength!==r.byteLength)return!1;const t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0}(e,r):e instanceof ArrayBuffer&&r instanceof ArrayBuffer?function(e,r){if(e.byteLength!==r.byteLength)return!1;const t=new Uint8Array(e),n=new Uint8Array(r);for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0}(e,r):!(!w(e)||!w(r))&&function(e,r,t){if(t.has(e)&&t.has(r))return!0;t.set(e,!0),t.set(r,!0);const o=Reflect.ownKeys(e),i=Reflect.ownKeys(r);if(o.length!==i.length)return!1;for(const a of o)if(!i.includes(a)||!n(e[a],r[a],t))return!1;return!0}(e,r,o))}return n(e,r)}function E(e){const r=[];let t="",n=!1;for(let o=0;o<e.length;o++){const i=e[o];"["===i?(t&&(r.push(t),t=""),n=!0,t+=i):"]"===i?(t+=i,r.push(/^\[\d+\]$/.test(t)?t:t.slice(1,-1)),t="",n=!1):"."!==i||n?t+=i:t&&(r.push(t),t="")}return t&&r.push(t),r}function g(e,r){if(!t(e))throw new TypeError("Expected an array for 'array'");for(const t of e)if(x(t,r))return!0;return!1}function m(e){if("function"!=typeof e)throw new TypeError("Expected a function for 'fn'");return(...r)=>!e(...r)}function b(e){if(!t(e))throw new TypeError("Expected an array for 'array'");const r=[];for(const t of e)r.includes(t)||r.push(t);return r}function T(){return"object"==typeof Deno&&Object.hasOwn(Deno,"version")}function v(e,r){let t;return t=T()?Deno.env.get(e):process.env[e],t??r}function A(e,r){const t=v(e);return Array.isArray(r)?r.includes(t):t===r}function F(){return"undefined"==typeof window||"undefined"==typeof document}function S(){return"undefined"!=typeof window&&"undefined"!=typeof document}function D(){return"object"==typeof Bun&&Object.hasOwn(Bun,"version")}function M(){return"undefined"!=typeof global&&"undefined"!=typeof process}function $(){return"undefined"!=typeof DedicatedWorkerGlobalScope&&self instanceof DedicatedWorkerGlobalScope}function k(){return"undefined"!=typeof ServiceWorkerGlobalScope&&self instanceof ServiceWorkerGlobalScope}function O(){return"undefined"!=typeof SharedWorkerGlobalScope&&self instanceof SharedWorkerGlobalScope}function j(){if(!F())return!!(document.fullscreenEnabled||document.webkitFullscreenEnabled||document.mozFullScreenEnabled||document.msFullscreenEnabled)}function C(e){return!(F()||!navigator.share)&&(!e||!navigator.canShare||navigator.canShare(e))}function N(e,r,t,n){if(!F())return e.addEventListener(r,t,n),()=>{e.removeEventListener(r,t,n)}}function U(e){return"string"==typeof e&&/^#([A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(e)}function z(e){if(!U(e))throw new Error("Expected a valid hex color string");const r=l(e=e.trim().replace("#",""),e.length>4?2:1),t=r.slice(0,3).map(e=>Number.parseInt(e.padEnd(2,e),16));return 4===r.length&&t.push(Math.trunc(Number.parseInt(r[3],16)/255*100)/100),`rgb${4===r.length?"a":""}(${t.join(", ")})`}function I(e){return"string"==typeof e&&/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$|^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(?:0(?:\.\d+)?|1(?:\.0+)?)\s*\)$/i.test(e)}function R(e){if(!I(e))throw new Error("Expected a valid rgb color string");let[r,t,n,o]=e.trim().replace(/^rgba?\((.*)\)$/,"$1").split(",");r/=255,t/=255,n/=255;const i=Math.max(r,t,n),a=Math.min(r,t,n);let f,s,u=(i+a)/2;if(i===a)f=s=0;else{const e=i-a;switch(s=u>.5?e/(2-i-a):e/(i+a),i){case r:f=(t-n)/e+(t<n?6:0);break;case t:f=(n-r)/e+2;break;case n:f=(r-t)/e+4}f/=6}f=Math.round(360*f*100)/100,s=Math.round(100*s*100)/100+"%",u=Math.round(100*u*100)/100+"%";const c=[f,s,u];return o&&c.push(o),`hsl${o?"a":""}(${c.join(", ")})`}function B(e){if(!I(e))throw new Error("Expected a valid rgb color string");const r=e.trim().replace(/^rgba?\((.*)\)$/,"$1").split(","),t=r.slice(0,3).map(e=>Number(e).toString(16).padStart(2,"0"));return 4===r.length&&t.push(Math.ceil(255*Number.parseFloat(r[3])).toString(16)),`#${t.join("")}`}function L(e){return"string"==typeof e&&/^hsl\(\s*(\d{1,3}(?:\.\d+)?)\s*,\s*(\d{1,3}(?:\.\d+)?)%\s*,\s*(\d{1,3}(?:\.\d+)?)%\s*\)$|^hsla\(\s*(\d{1,3}(?:\.\d+)?)\s*,\s*(\d{1,3}(?:\.\d+)?)%\s*,\s*(\d{1,3}(?:\.\d+)?)%\s*,\s*(?:0(?:\.\d+)?|1(?:\.0+)?)\s*\)$/i.test(e)}function W(e){if(!L(e))throw new Error("Expected a valid hsl color");let[r,t,n,o]=e.trim().replace(/^hsla?\((.*)\)$/,"$1").replace(/%/g,"").split(",");r%=360,t/=100,n/=100;const i=(1-Math.abs(2*n-1))*t,a=i*(1-Math.abs(r/60%2-1)),f=n-i/2;let s=0,u=0,c=0;0<=r&&r<60?(s=i,u=a):60<=r&&r<120?(s=a,u=i):120<=r&&r<180?(u=i,c=a):180<=r&&r<240?(u=a,c=i):240<=r&&r<300?(s=a,c=i):300<=r&&r<360&&(s=i,c=a),s=Math.round(255*(s+f)),u=Math.round(255*(u+f)),c=Math.round(255*(c+f));const p=[s,u,c];return o&&p.push(o),`rgb${o?"a":""}(${p.join(", ")})`}function P(...e){if(!e.every(e=>"number"==typeof e))throw new TypeError("Expected an array of numbers for 'values'");return e.reduce((e,r)=>e+r,0)}function q(e){if(!Array.isArray(e)||!e.every(e=>"number"==typeof e))throw new TypeError("Expected an array of numbers for 'values'");return e.length?P(...e)/e.length:0}function H(e=0,r=10){if("number"!=typeof e)throw new TypeError("Expected a number for 'min'");if("number"!=typeof r)throw new TypeError("Expected a number for 'max'");if(e>r)throw new RangeError(`Expected 'min' (${e}) to be less than or equal to 'max' (${r})`);return Math.floor(Math.random()*(r-e+1)+e)}function Z(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)}function Y(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^[A-Za-z0-9_-]+$/.test(e)}function V(e){return h(e)&&"[object Uint8Array]"===Object.prototype.toString.call(e)}function _(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^[A-Fa-f0-9]+$/.test(e)}function G(r){return i(r)&&!e(r.getTime())}function K(e,r){if(!G(e))throw new TypeError("Expected valid Date for 'date1'");if(!G(r))throw new TypeError("Expected valid Date for 'date2'");return e.getFullYear()===r.getFullYear()&&e.getMonth()===r.getMonth()&&e.getDate()===r.getDate()}function J(e){return i(e)?new Date(e.getTime()):"string"==typeof e||"number"==typeof e?new Date(e):new Date(NaN)}async function Q(e){if("number"!=typeof e)throw new TypeError("Expected a non-negative number for 'timeout'");return new Promise(r=>setTimeout(()=>r(),e))}function X(e,r,t=/{{(.*?)}}/g){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");return e.replace(t,(e,t)=>{const n=t.trim(),o=r[n];return f(o)?e:String(o)})}function ee(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");return/^(?!.*[A-Z]).*[a-z].*$/.test(e.replace(/\s+/g,""))}function re(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");return/^(?!.*[a-z]).*[A-Z].*$/.test(e.replace(/\s+/g,""))}exports.add=P,exports.adjust=function(e,r,n){if(!t(e))throw new TypeError("Expected an array for 'array'");if(0===e.length)return[];if("number"!=typeof r)throw new TypeError("Expected a number for 'index'");if("function"!=typeof n)throw new TypeError("Expected a function for 'fn'");const o=e.length;return e[(r+o)%o]=n(e[(r+o)%o]),e},exports.adjustDate=function(e,r){if(!G(e))throw new TypeError("Expected a valid Date, string, or number for 'date'");if(r.years&&e.setFullYear(e.getFullYear()+r.years),r.months){const o=e.getDate();e.setMonth(e.getMonth()+r.months,1);const i=(t=e.getFullYear(),n=e.getMonth(),new Date(t,n+1,0).getDate());e.setDate(Math.min(o,i))}var t,n;return r.days&&e.setDate(e.getDate()+r.days),r.hours&&e.setHours(e.getHours()+r.hours),r.minutes&&e.setMinutes(e.getMinutes()+r.minutes),r.seconds&&e.setSeconds(e.getSeconds()+r.seconds),r.milliseconds&&e.setMilliseconds(e.getMilliseconds()+r.milliseconds),e},exports.adjustTimezone=function(e,r){if(!G(e))throw new TypeError("Expected a valid date for 'date'");const t=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds());return new Date(t+36e5*r)},exports.after=function(e,r){if(!t(e)&&!p(e))throw new TypeError("Expected an array-like for 'array'");if("number"!=typeof r)throw new TypeError("Expected a number for 'index'");return e.slice(r+1)},exports.aperture=function(e,r=1){if(!t(e))throw new TypeError("Expected an array for 'array'");if("number"!=typeof r||r<=0)throw new TypeError("Expected 'size' to be a number greater than 0");return Array.from({length:e.length-r+1},(t,n)=>e.slice(n,n+r))},exports.append=function(e,r){if(!t(e))throw new TypeError("Expected an array for 'array'");return[...e,r]},exports.arrayToObject=function(e,r=(e,r)=>r,n=e=>e){if(!t(e))throw new TypeError("Expected an array for 'array'");if("function"!=typeof r)throw new TypeError("Expected a function for 'keyFn'");if("function"!=typeof n)throw new TypeError("Expected a function for 'valueFn'");const o={};for(let t=0;t<e.length;t++)o[r(e[t],t,e)]=n(e[t],t,e);return o},exports.backoff=async function(e,{initialDelay:r=500,backoffMode:t="exponential",jitterMode:n="full",maxAttempts:o=5,maxDelay:i=6e4,onRetry:a}={}){if("function"!=typeof e)throw new Error("Expected a function for 'action'");if(r<=0)throw new Error("Expected a positive number for 'initialDelay'");if(o<=0)throw new Error("Expected a positive number for 'maxAttempts'");if(i<=0)throw new Error("Expected a positive number for 'maxDelay'");let f=r;const s=function(e){switch(e){case"fixed":return()=>r;case"linear":return e=>r*e;case"exponential":return e=>r*2**(e-1);default:throw new Error(`Invalid backoff mode: ${e}`)}}(t),u=function(e,r,t){switch(e){case"none":return e=>Math.min(e,t);case"full":return e=>Math.random()*Math.min(e,t);case"equal":return e=>{const r=Math.min(e,t);return r/2+Math.random()*r/2};case"decorrelated":return(e,n)=>Math.min(r+Math.random()*(3*n-r),t);default:throw new Error(`Invalid jitter mode: ${e}`)}}(n,r,i);for(let r=1;r<=o;r++)try{return await e()}catch(e){if(r===o)throw e;f=u(s(r),f),a?.(r,f),await Q(f)}},exports.base64Decode=function(e,r=!1){if(r){if(!Y(e))throw new Error("Expected a valid base64url string for 'input'")}else if(!Z(e))throw new Error("Expected a valid base64 string for 'input'");let t=e;if(r){t=t.replace(/-/g,"+").replace(/_/g,"/");const e=t.length%4;0!==e&&(t+="=".repeat(4-e))}if("undefined"!=typeof Buffer&&"function"==typeof Buffer.from)return new Uint8Array(Buffer.from(t,"base64"));if("function"==typeof atob){const e=atob(t),r=new Uint8Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r}throw new Error("No base64 decoder available in this environment")},exports.base64Encode=function(e,r=!1){const t=V(e)?e:new Uint8Array(e);let n;if("undefined"!=typeof Buffer&&"function"==typeof Buffer.from)n=Buffer.from(t).toString("base64");else{if("function"!=typeof btoa)throw new Error("No base64 encoder available in this environment");n=btoa(String.fromCharCode(...t))}return r&&(n=n.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")),n},exports.before=function(e,r){if(!t(e)&&!p(e))throw new TypeError("Expected an array-like for 'array'");if("number"!=typeof r)throw new TypeError("Expected a number for 'index'");return e.slice(0,r)},exports.benchmark=async function(e,r=1){if("function"!=typeof e)throw new TypeError("Expected a function for 'callback'");if("number"!=typeof r||r<1)throw new TypeError("Expected a number greater than 0 for 'iterations'");const t=[];for(let n=0;n<r;n++){const r=performance.now();await e();const n=performance.now();t.push(n-r)}return q(t)},exports.capitalize=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");return e.charAt(0).toUpperCase().concat(e.slice(1).toLowerCase())},exports.charCount=function(e,r){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");if("string"!=typeof r||1!==r.length)throw new TypeError("Expected a single character string for 'char'");let t=0;for(let n=0;n<e.length;n++)e[n]===r&&t++;return t},exports.chunk=l,exports.clamp=function(e,r,t){if("number"!=typeof e)throw new TypeError("Expected a number for 'value'");if("number"!=typeof r)throw new TypeError("Expected a number for 'min'");if("number"!=typeof t)throw new TypeError("Expected a number for 'max'");if(r>t)throw new RangeError("Expected 'min' to be less than or equal to 'max'");return e>=t?t:e<=r?r:e},exports.clone=y,exports.collectBy=function(e,r){if(!t(e))throw new TypeError("Expected an array for 'array'");if("function"!=typeof r)throw new TypeError("Expected a function for 'keySelector'");const n=d(e,r);return Object.values(n)},exports.compact=function(e){if(!t(e))throw new TypeError("Expected an array for 'array'");return e.filter(Boolean)},exports.compose=function(...e){if(!Array.isArray(e)||!e.every(e=>"function"==typeof e))throw new TypeError("Expected all arguments to be functions");return r=>e.reduceRight((e,r)=>r(e),r)},exports.convertDateTo=function(e,r="iso"){if(!G(e))throw new TypeError("Expected a valid Date for 'date'");return"timestamp"===r?e.getTime():"utc"===r?e.toUTCString():"iso"===r?e.toISOString():e.toString()},exports.convertTimeUnit=function(e,r,t){if("number"!=typeof e)throw new TypeError("Expected a number for 'time'");if("string"!=typeof r)throw new TypeError("Expected a string for 'from'");if("string"!=typeof t)throw new TypeError("Expected a string for 'to'");const n={milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5,years:31536e6},o=e*n[r];return Math.floor(o/n[t])},exports.count=function(e,r){if(!t(e))throw new TypeError("Expected an array for 'array'");if("function"!=typeof r)throw new TypeError("Expected a function for 'predicate'");let n=0;for(const t of e)r(t)&&n++;return n},exports.customError=function(e){return class r extends Error{constructor(t,n){super(t,n),this.name=e,"captureStackTrace"in Error&&Error.captureStackTrace(this,r)}}},exports.cycle=function(e){if(!t(e))throw new TypeError("Expected an array for 'array'");let r=-1;return()=>{if(0!==e.length)return r=(r+1)%e.length,e[r]}},exports.debounce=function(e,r=300,t={}){const{leading:n=!1,trailing:o=!0,maxWait:i}=t;if(!n&&!o)throw new Error("debounce: 'leading' and 'trailing' cannot both be false.");let a=null,f=null,s=null;function u(r){s=r,e(...f),f=null}function c(...e){const t=performance.now();f=e;(n&&!a||null!=i&&(null===s?1/0:t-s)>=i)&&(a&&(clearTimeout(a),a=null),u(t)),a&&clearTimeout(a),a=setTimeout(()=>{a=null,o&&f&&u(performance.now())},r)}return c.cancel=()=>{a&&(clearTimeout(a),a=null),f=null},c.flush=()=>{a&&f&&(clearTimeout(a),a=null,u(performance.now()))},c},exports.defer=function(e){if("function"!=typeof e)throw new TypeError("Expected a function for 'callback'");setTimeout(e,1)},exports.difference=function(e,r){if(!t(e))throw new TypeError("Expected an array for 'array1'");if(!t(r))throw new TypeError("Expected an array for 'array2'");return e.filter(e=>!g(r,e))},exports.divide=function(e,r){if("number"!=typeof e||"number"!=typeof r)throw new TypeError("Expected a number for 'dividend' and 'divisor'");if(0===r)throw new Error("Cannot divide by zero.");return e/r},exports.divisors=function(e){if("number"!=typeof e||!Number.isInteger(e)||e<=0)throw new TypeError("Expected a positive integer for 'value'");const r=[];for(let t=1;t<=e;t++)e%t===0&&r.push(t);return r},exports.djb2=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");let r=5381;for(let t=0;t<e.length;t++)r=(r<<5)+r+e.charCodeAt(t);return r>>>0},exports.elapsedTime=function(e,r=new Date,t){if(!G(e))throw new TypeError("Expected a valid Date for 'from'");if(!G(r))throw new TypeError("Expected a valid Date for 'to'");const n=Math.abs(r.getTime()-e.getTime());switch(t){case"years":return Math.floor(n/31536e6);case"days":return Math.floor(n/864e5);case"hours":return Math.floor(n/36e5);case"minutes":return Math.floor(n/6e4);case"seconds":return Math.floor(n/1e3);case"milliseconds":return n;default:throw new TypeError(`Invalid time unit: ${t}`)}},exports.equalsEnv=A,exports.escapeHtml=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")},exports.exitFullscreen=async function(){if(!F())return j()?document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.msExitFullscreen?document.msExitFullscreen():void 0:Promise.reject(new Error("Fullscreen API is not supported."))},exports.factorial=function(e){if("number"!=typeof e||!Number.isInteger(e)||e<0)throw new TypeError("Expected a non-negative integer for 'value'");let r=1;for(let t=e;t>=1;t--)r*=t;return r},exports.fibonacci=function e(r){if("number"!=typeof r||!Number.isInteger(r)||r<0)throw new TypeError("Expected a non-negative integer for 'num'");return r<=1?r:e(r-1)+e(r-2)},exports.first=function(e,r=1){if(!t(e)&&!p(e))throw new TypeError("Expected an array-like for 'array'");if("number"!=typeof r||r<0)throw new TypeError("Expected 'count' to be a non-negative number");return e.slice(0,r)},exports.flat=function(e,r=1/0){if(!t(e))throw new TypeError("Expected an array for 'array'");if("number"!=typeof r||r<0)throw new TypeError("Expected a non-negative number for 'depth'");return e.flat(r)},exports.flatMap=function(e,r){if(!t(e))throw new TypeError("Expected an array for 'array'");if("function"!=typeof r)throw new TypeError("Expected a function for 'fn'");return e.map(r).flat(1)},exports.flattenObj=function(e){const r={};return function e(n,o=""){t(n)?n.forEach((n,i)=>{const a=o?`${o}[${i}]`:`[${i}]`;w(n)||t(n)?e(n,a):r[a]=n}):w(n)?Object.entries(n).forEach(([n,i])=>{const a=n.includes(".")?`[${n}]`:n,f=o?`${o}.${a}`:a;w(i)||t(i)?e(i,f):r[f]=i}):r[o]=n}(e),r},exports.formatDate=function(e,r,t="/"){if(!G(e))throw new TypeError("Expected a valid Date for 'date'");const n=e.getDate().toString().padStart(2,"0"),o=(e.getMonth()+1).toString().padStart(2,"0"),i=e.getFullYear();switch(r){case"DMY":return`${n}${t}${o}${t}${i}`;case"MDY":return`${o}${t}${n}${t}${i}`;case"YMD":return`${i}${t}${o}${t}${n}`;default:throw new TypeError("Expected a string for 'format'")}},exports.formatDuration=function(e,r="hh:mm:ss",t=!0){if("number"!=typeof e)throw new TypeError("Expected a number for 'ms'");if("string"!=typeof r)throw new TypeError("Expected a string for 'format'");const n=String(Math.floor(e/36e5)),o=String(Math.floor(e%36e5/6e4)).padStart(2,"0"),i=String(Math.floor(e%6e4/1e3)).padStart(2,"0"),a=String(e%1e3).padStart(3,"0");let f=r.toLowerCase();return t&&"0"===n&&(f=f.slice(f.indexOf("mm"))),f.replace("hh",n).replace("mm",o).replace("ss",i).replace("ms",a)},exports.formatTime=function(e,r="hh:mm"){if(!G(e))throw new TypeError("Expected a valid Date for 'date'");const t=-1!==r.search("a"),n=String(t?e.getHours()%12||12:e.getHours()),o=String(e.getMinutes()).padStart(2,"0"),i=String(e.getSeconds()).padStart(2,"0"),a=String(e.getMilliseconds()).padStart(3,"0"),f=e.getHours()>=12?"PM":"AM";return r.toLowerCase().replace("hh",n).replace("mm",o).replace("ss",i).replace("ms",a).replace("a",f)},exports.freeze=function e(r){const t=Object.freeze(r);if(!s(t))return t;for(const r of Reflect.ownKeys(t)){h(t[r])&&e(t[r])}return t},exports.frequency=function(e){if(!Array.isArray(e))throw new TypeError("Expected an array for 'arr'");return e.reduce((e,r)=>(e[String(r)]=(e[String(r)]||0)+1,e),{})},exports.generateNonce=function(e=16){if(e<=0)throw new Error("Expected positive multiple of 8 for 'length'");const r=new Uint8Array(e);return crypto.getRandomValues(r),r},exports.generateUUID=function(){return crypto.randomUUID()},exports.get=function(e,r,t){const n=Array.isArray(r)?r.map(e=>e.replace(/^\[(\d+)\]$/g,"$1")):r.replace(/\[(\d+)\]/g,".$1").split(".");let o=e;for(const e of n){if(!Object.hasOwn(o,e))return t;o=o[e]}return o??t},exports.getEnv=v,exports.getInstanceType=function(e){if(null===e||"object"!=typeof e&&"function"!=typeof e)return null;const r=Object.getPrototypeOf(e)?.constructor;return r?r.name:null},exports.getLanguage=function(){if(!F())return navigator.language.slice(0,2)},exports.getOS=function(){if(!F())return;if("userAgentData"in navigator)return navigator.userAgentData.platform;const e=navigator.userAgent;return/Android/i.test(e)?"Android":/iPhone|iPad|iPod/i.test(e)?"iOS":/Linux/i.test(e)?"Linux":/Windows/i.test(e)?"Windows":/Mac/i.test(e)?"macOS":"Unknown"},exports.getRuntime=function(){return S()?"Browser":T()?"Deno":D()?"Bun":M()?"Node":"Unknown"},exports.getTheme=function(){if(!F())return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"},exports.getType=function(o){const i=typeof o;if("number"===i){if(e(o))return"nan";if(r(o))return"infinity"}else if("object"===i){if(n(o))return"null";if(t(o))return"array"}return i},exports.groupBy=d,exports.has=function(e,r){const t=Array.isArray(r)?r.map(e=>e.replace(/^\[(\d+)\]$/g,"$1")):r.replace(/\[(\d+)\]/g,".$1").split(".");let n=e;for(const e of t){if(!Object.hasOwn(n,e))return!1;n=n[e]}return!0},exports.hasEnv=function(e){let r;return r=T()?Deno.env.get(e):process.env[e],void 0!==r},exports.hexDecode=function(e){if(!_(e)||e.length%2!=0)throw new Error("Invalid hex string");const r=new Uint8Array(e.length/2);for(let t=0;t<e.length;t+=2)r[t/2]=parseInt(e.slice(t,t+2),16);return r},exports.hexEncode=function(e){const r=V(e)?e:new Uint8Array(e);return Array.from(r).map(e=>e.toString(16).padStart(2,"0")).join("")},exports.hexToHsl=function(e){return R(z(e))},exports.hexToRgb=z,exports.hslToHex=function(e){return B(W(e))},exports.hslToRgb=W,exports.identity=function(e){return e},exports.inRange=function(e,r,t){if("number"!=typeof e)throw new TypeError("Expected a number for 'value'");if("number"!=typeof r)throw new TypeError("Expected a number for 'min'");if("number"!=typeof t)throw new TypeError("Expected a number for 'max'");return r<=e&&e<=t},exports.includes=g,exports.interpolate=X,exports.invertCase=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");return e.split("").map(e=>ee(e)?e.toUpperCase():re(e)?e.toLowerCase():e).join("")},exports.isAggregateError=function(e){return"undefined"!=typeof AggregateError&&e instanceof AggregateError},exports.isAlpha=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^\p{L}+$/u.test(e)},exports.isAlphanumeric=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^[a-zA-Z0-9]+$/.test(e)},exports.isArray=t,exports.isArrayBuffer=function(e){return h(e)&&"[object ArrayBuffer]"===Object.prototype.toString.call(e)},exports.isAsyncFunction=function(e){return o(e)&&"AsyncFunction"===e.constructor.name},exports.isAsyncGeneratorFunction=function(e){return o(e)&&"AsyncGeneratorFunction"===e.constructor.name},exports.isBase64=Z,exports.isBase64URL=Y,exports.isBetween=function(e,r,t,n=!0){if(!G(e))throw new TypeError("Expected a valid Date for 'date'");if(!G(r))throw new TypeError("Expected a valid Date for 'start'");if(!G(t))throw new TypeError("Expected a valid Date for 'end'");return n?e.getTime()>=r.getTime()&&e.getTime()<=t.getTime():e.getTime()>r.getTime()&&e.getTime()<t.getTime()},exports.isBigint=function(e){return"bigint"==typeof e},exports.isBoolean=function(e){return"boolean"==typeof e},exports.isBrowser=S,exports.isBun=D,exports.isCookieEnabled=function(){if(!F())return navigator.cookieEnabled},exports.isCreditCard=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/.test(e)},exports.isDOMException=function(e){return e instanceof DOMException},exports.isDate=i,exports.isDedicatedWorker=$,exports.isDeno=T,exports.isDev=function(){return A("NODE_ENV","development")},exports.isEmail=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e)},exports.isEqual=x,exports.isError=function(e){return s(e)&&"string"==typeof e.name&&"string"==typeof e.message},exports.isEvalError=function(e){return e instanceof EvalError},exports.isEven=function(e){if("number"!=typeof e)throw new TypeError("Expected a number for 'value'");return e%2==0},exports.isFalsy=function(e){return[void 0,null,!1,NaN,0,0n,""].includes(e)},exports.isFinite=function(r){if("number"!=typeof r)throw new TypeError("Expected a number for 'value'");return!e(r)&&r!==1/0&&r!==-1/0},exports.isFloat=function(e){if("number"!=typeof e)throw new TypeError("Expected a number for 'value'");return!Number.isInteger(e)&&Number.isFinite(e)},exports.isFrozen=function(e){return Object.isFrozen(e)},exports.isFullscreenEnabled=j,exports.isFunction=o,exports.isGeneratorFunction=function(e){return o(e)&&"GeneratorFunction"===e.constructor.name},exports.isHash=function(e,r="SHA-256"){if("string"!=typeof e)throw new TypeError("Expected a string for 'hash'");if(!/^[0-9a-fA-F]+$/.test(e))return!1;switch(r){case"SHA-1":return 40===e.length;case"SHA-256":return 64===e.length;case"SHA-384":return 96===e.length;case"SHA-512":return 128===e.length;default:throw new Error("Expected a valid hash algorithm for 'algorithm'")}},exports.isHex=_,exports.isHexColor=U,exports.isHslColor=L,exports.isIPV4=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(?::(?:[0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$/.test(e)},exports.isIPV6=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^(?:(?:(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))|\[(?:(?:(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))\](?::(?:[0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$/i.test(e)},exports.isInfinity=r,exports.isInteger=function(e){if("number"!=typeof e)throw new TypeError("Expected a number for 'value'");return Number.isInteger(e)&&e==e&&e!==1/0&&e!==-1/0},exports.isIterable=function(e){return null!=e&&"function"==typeof e[Symbol.iterator]},exports.isJWT=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(e)},exports.isLeapYear=function(e){return(e=Number(e))%4==0&&(e%100!=0||e%400==0)},exports.isLowerCase=ee,exports.isMap=a,exports.isMobile=function(){if(!F())return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)},exports.isNaN=e,exports.isNegative=function(e){if("number"!=typeof e)throw new TypeError("Expected a number for 'value'");return e<0},exports.isNil=f,exports.isNode=M,exports.isNotNullObject=h,exports.isNull=n,exports.isNumber=function(t){return"number"==typeof t&&!r(t)&&!e(t)},exports.isObject=s,exports.isOdd=function(e){if("number"!=typeof e)throw new TypeError("Expected a number for 'value'");return e%2!=0},exports.isOnline=function(){if(!F())return navigator.onLine},exports.isPlainObject=w,exports.isPositive=function(e){if("number"!=typeof e)throw new TypeError("Expected a number for 'value'");return e>0},exports.isPrime=function(e){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("Expected an integer for 'value'");if(e<2)return!1;if(2===e)return!0;if(e%2==0)return!1;const r=Math.sqrt(e);for(let e=3;e<=r;e+=2)if(e%e===0)return!1;return!0},exports.isPrimitive=function(e){return n(e)||"object"!=typeof e&&!o(e)},exports.isProd=function(){return A("NODE_ENV","production")},exports.isPromise=function(e){return e instanceof Promise},exports.isRangeError=function(e){return e instanceof RangeError},exports.isReferenceError=function(e){return e instanceof ReferenceError},exports.isRegExp=u,exports.isRgbColor=I,exports.isSameDay=K,exports.isSealed=function(e){return Object.isSealed(e)},exports.isServer=F,exports.isServiceWorker=k,exports.isSet=c,exports.isShareable=C,exports.isSharedWorker=O,exports.isSlug=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e)},exports.isString=p,exports.isSymbol=function(e){return"symbol"==typeof e},exports.isSyntaxError=function(e){return e instanceof SyntaxError},exports.isTabActive=function(){if(!F())return"visible"===document.visibilityState},exports.isTest=function(){return A("NODE_ENV","test")},exports.isToday=function(e){if(!G(e))throw new TypeError("Expected a valid Date for 'date'");return K(e,new Date)},exports.isTomorrow=function(e){if(!G(e))throw new TypeError("Expected a valid Date for 'date'");const r=new Date;return r.setDate(r.getDate()+1),K(e,r)},exports.isTouchDevice=function(){if(!F())return"ontouchstart"in window||navigator.maxTouchPoints>0},exports.isTypeError=function(e){return e instanceof TypeError},exports.isURIError=function(e){return e instanceof URIError},exports.isURL=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value'");return/^(https?:\/\/)?(www\.)?([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})(:[0-9]{1,5})?(\/[a-zA-Z0-9._~:/?#[\]@!$&'()*+,;=-]*)?$/.test(e)},exports.isUUID=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'value', but received "+typeof e);return/^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$/.test(e)},exports.isUint8Array=V,exports.isUndefined=function(e){return void 0===e},exports.isUpperCase=re,exports.isValidDate=G,exports.isValidDateString=function(e){if("string"!=typeof e)throw new TypeError("Expected a datestring for 'date'");return!isNaN(new Date(e).getTime())},exports.isWeakMap=function(e){return e instanceof WeakMap},exports.isWeakRef=function(e){return e instanceof WeakRef},exports.isWeakSet=function(e){return e instanceof WeakSet},exports.isWebWorker=function(){return $()||O()||k()},exports.isWeekday=function(e){if(!G(e))throw new TypeError("Expected a valid Date for 'date'");const r=e.getDay();return 0!==r&&6!==r},exports.isWeekend=function(e){if(!G(e))throw new TypeError("Expected a valid Date for 'date'");const r=e.getDay();return 0===r||6===r},exports.isYesterday=function(e){if(!G(e))throw new TypeError("Expected a valid Date for 'date'");const r=new Date;return r.setDate(r.getDate()-1),K(e,r)},exports.last=function(e,r=1){if(!t(e)&&!p(e))throw new TypeError("Expected an array-like for 'array'");if("number"!=typeof r||r<0)throw new TypeError("Expected 'count' to be a non-negative number");return e.slice(-r)},exports.lerp=function(e,r,t){if("number"!=typeof e)throw new TypeError("Expected a number for 'start'");if("number"!=typeof r)throw new TypeError("Expected a number for 'end'");if("number"!=typeof t)throw new TypeError("Expected a number for 'amount'");return e+(r-e)*t},exports.lock=function(e,r={queue:!0}){let t=!1;const n=[],o=async()=>{if(0===n.length)return void(t=!1);const e=n.shift();try{await e()}catch(e){throw r.onError?.(e),e}await o()};return async(...i)=>{if(t){if(r.onLocked&&await r.onLocked(),!r.queue)return;return new Promise((r,t)=>{n.push(async()=>{try{r(await e(...i))}catch(e){t(e)}})})}t=!0;try{return await e(...i)}catch(e){throw r.onError?.(e),e}finally{await o()}}},exports.maskString=function(e,r,t,n){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");if("string"!=typeof r)throw new TypeError("Expected a string for 'mask'");if("number"!=typeof t)throw new TypeError("Expected a number for 'maskStart'");if(t<0)throw new RangeError("'maskStart' must be >= 0");if("number"!=typeof n)throw new TypeError("Expected a number for 'maskLength'");if(n<0)throw new RangeError("'maskLength' must be >= 0");if(t>e.length)throw new RangeError("'maskStart' cannot be greater than 'maskLength'");n=Math.min(n,e.length-t);const o=e.slice(0,t),i=e.slice(t+n);return o+r.repeat(n)+i},exports.mean=q,exports.median=function(e){if(!Array.isArray(e)||!e.every(e=>"number"==typeof e))throw new TypeError("Expected an array of numbers for 'arr'");if(0===e.length)throw new Error("Input array cannot be empty.");const r=[...e].sort((e,r)=>e-r),t=Math.floor(r.length/2);return r.length%2==0?(r[t-1]+r[t])/2:r[t]},exports.memo=function(e,{cacheTimeout:r,serializer:t}={serializer:JSON.stringify}){if("function"!=typeof e)throw new TypeError("Expected a function for 'callback'");if(void 0!==r&&"number"!=typeof r)throw new TypeError("Expected a number for 'cacheTimeout'");if("function"!=typeof t)throw new TypeError("Expected a function for 'serializer'");const n=new Map;return(...o)=>{const i=t(o);return n.has(i)||(n.set(i,e(...o)),r&&setTimeout(()=>n.delete(i),r)),n.get(i)}},exports.merge=function e(r,n){if("object"!=typeof r||null===r)return n;const o=t(r);if(o!==t(n))return n;const i=o?[...r]:{...r};for(const r of Reflect.ownKeys(n)){const o=i[r],a=n[r];w(o)&&w(a)||t(o)&&t(a)?i[r]=e(o,a):i[r]=a}return i},exports.mod=function(e,r){if("number"!=typeof e||"number"!=typeof r)throw new TypeError("Expected a number for 'dividend' and 'divisor'");if(0===r)throw new Error("Cannot calculate modulo with zero divisor.");return(e%r+r)%r},exports.mode=function(e){if(!Array.isArray(e)||!e.every(e=>"number"==typeof e))throw new TypeError("Expected an array of numbers for 'arr'");if(0===e.length)return[];const r=new Map;let t=0;for(const n of e){const e=(r.get(n)||0)+1;r.set(n,e),e>t&&(t=e)}const n=[];for(const[e,o]of r.entries())o===t&&n.push(e);return n.sort((e,r)=>e-r)},exports.multiply=function(...e){if(!e.every(e=>"number"==typeof e))throw new TypeError("Expected an array of numbers for 'values'");return e.reduce((e,r)=>e*r,1)},exports.noop=function(){},exports.not=m,exports.omit=function(e,r){const t=y(e);for(const e of r)Object.hasOwn(t,e)&&delete t[e];return t},exports.on=N,exports.onOffline=function(e){return N(window,"offline",e)},exports.onOnline=function(e){return N(window,"online",e)},exports.onVisibilityChange=function(e){return N(document,"visibilitychange",()=>e(document.visibilityState))},exports.once=function(e){if("function"!=typeof e)throw new TypeError("Expected a function for 'callback'");let r,t=!1;return(...n)=>{if(!t){t=!0;try{r=e(...n)}catch(e){throw e}}return r}},exports.parallel=async function(...e){if(!e.every(e=>"function"==typeof e))throw new TypeError("Expect an array of functions for 'callbacks'");return Promise.all(e.map(e=>e()))},exports.parseColor=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'color'");U(e=e.trim())&&(e=z(e));const r=e.match(/^rgba?\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})(?:,\s*([0-1]?\.?\d+))?\)$/i);if(r){const e=parseInt(r[1]),t=parseInt(r[2]),n=parseInt(r[3]),o=void 0!==r[4]?parseFloat(r[4]):1;if(e<=255&&t<=255&&n<=255)return{model:"rgb",values:[e,t,n],alpha:o}}const t=e.match(/^hsla?\((\d{1,3}),\s*(\d{1,3})%,\s*(\d{1,3})%(?:,\s*([0-1]?\.?\d+))?\)$/i);if(t){const e=parseInt(t[1]),r=parseInt(t[2]),n=parseInt(t[3]),o=void 0!==t[4]?parseFloat(t[4]):1;if(e<=360&&r<=100&&n<=100)return{model:"hsl",values:[e,r,n],alpha:o}}return null},exports.parseDate=function(e){const r=J(e);if(!G(r))throw new TypeError("Expected a valid Date for 'date'");return r},exports.partialLeft=function(e,...r){if("function"!=typeof e)throw new TypeError("Expected a function for 'callback'");return(...t)=>e(...r,...t)},exports.partialRight=function(e,...r){if("function"!=typeof e)throw new TypeError("Expected a function for 'callback'");return(...t)=>e(...t,...r)},exports.pick=function(e,r){return r.reduce((r,t)=>(Object.hasOwn(e,t)&&(r[t]=e[t]),r),{})},exports.pipe=function(...e){if(!Array.isArray(e)||!e.every(e=>"function"==typeof e))throw new TypeError("Expected 'callbacks' to be an array of functions");return r=>e.reduce((e,r)=>r(e),r)},exports.pow=function(e,r){if("number"!=typeof e||"number"!=typeof r)throw new TypeError("Expected a number for 'base' and 'exponent'");return Math.pow(e,r)},exports.random=H,exports.randomColor=function(e="rgb",r){if("string"!=typeof e||!["hex","rgb","hsl"].includes(e))throw new Error('Expected "hex", "rgb", or "hsl" for \'format\'');const t=H(0,255),n=H(0,255),o=H(0,255),i=r?H(0,10)/10:void 0,a=`rgb${r?"a":""}(${t}, ${n}, ${o}${r?`,${i}`:""})`;return"hsl"===e?R(a):"hex"===e?B(a):a},exports.range=function(e,r,t=1){if("number"!=typeof e)throw new TypeError("Expected a number for 'start'");if("number"!=typeof r)throw new TypeError("Expected a number for 'end'");if("number"!=typeof t)throw new TypeError("Expected a number for 'step'");if(0===t)throw new Error("step cannot be zero");const n=[];if(t>0)for(let o=e;o<r;o+=t)n.push(Math.trunc(100*o)/100);else for(let o=e;o>r;o+=t)n.push(o);return n},exports.rateLimit=function(e,r,t){if("function"!=typeof e)throw new TypeError("Expected a function for 'callback'");let n=0;if("number"!=typeof r||r<=0)throw new TypeError("Expected 'limit' to be a positive number");if("number"!=typeof t||t<=0)throw new TypeError("Expected 'interval' to be a positive number");return(...o)=>n<r&&(0===n&&setTimeout(()=>{n=0},t),n++,e(...o),!0)},exports.reject=function(e,r){if(!t(e))throw new TypeError("Expected an array for 'array'");if("function"!=typeof r)throw new TypeError("Expected a function for 'fn'");return e.filter(m(r))},exports.removeAccents=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")},exports.repeat=function(e,r){if("number"!=typeof r)throw new TypeError("Expected a number for 'count'");if(r<0)throw new RangeError("Expected a non-negative integer for 'count'");return"string"==typeof e?e.repeat(r):Array(r).fill(e)},exports.requestFullscreen=async function(e){if(!F())return j()?e.requestFullscreen?e.requestFullscreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.msRequestFullscreen?e.msRequestFullscreen():void 0:Promise.reject(new Error("Fullscreen API is not supported."))},exports.requireEnv=function(e){let r;if(r=T()?Deno.env.get(e):process.env[e],void 0===r)throw new Error("Expected a valid value for 'key'");return r},exports.retry=function(e,r){if("function"!=typeof e)throw new TypeError("Expected a function for 'callback'");if("number"!=typeof r||!Number.isInteger(r)||r<1)throw new TypeError("The 'attempts' parameter must be a positive integer. Received: "+typeof r);for(let t=0;t<r;t++)try{return e()}catch(e){if(t===r-1)throw new Error(`Function failed after ${r} attempts: ${e.message}`)}throw new Error("Unexpected error: retry loop completed without success or final throw.")},exports.rgbToHex=B,exports.rgbToHsl=R,exports.rotate=function(e,r){if(!t(e))throw new TypeError("Expected an array for 'array'");if("number"!=typeof r)throw new TypeError("Expected a number for 'offset'");const n=e.length;return r=(r%n+n)%n,e.slice(r).concat(e.slice(0,r))},exports.roundTo=function(e,r=0){if("number"!=typeof e)throw new TypeError("Expected a number for 'value'");if("number"!=typeof r)throw new TypeError("Expected a number for 'precision'");if(!Number.isInteger(r)||r<0)throw new TypeError("Expected a non-negative integer for 'precision'");const t=10**r;return Math.round(e*t)/t},exports.sample=function(e){if(!t(e))throw new TypeError("Expected an array for 'array'");if(0===e.length)return;return e[Math.floor(Math.random()*e.length)]},exports.scrollToElement=function(e,r={behavior:"smooth",block:"start"}){if(!F()){if(!e)throw new Error("Expected an element for 'element'");e.scrollIntoView(r)}},exports.scrollToTop=function(e="smooth"){F()||window.scrollTo({top:0,behavior:e})},exports.seal=function e(r){const t=Object.seal(r);if(!s(t))return t;for(const r of Reflect.ownKeys(t)){const n=t[r];h(n)&&e(n)}return t},exports.set=function(e,r,t){const n=Array.isArray(r)?r:r.replace(/\[(\d+)\]/g,".$1").split(".");let o=e;const i=n.slice(0,-1),a=n[n.length-1];for(const e of i)Object.hasOwn(o,e)||(o[e]={}),o=o[e];return o[a]=t,e},exports.share=function(e){if(!F())return C(e)?navigator.share(e):Promise.reject(new Error("The Web Share API is not available or the data is not shareable."))},exports.shuffle=function(e){if(!t(e))throw new TypeError("Expected an array for 'array'");for(let r=e.length-1;r>0;r--){const t=Math.floor(Math.random()*(r+1));[e[r],e[t]]=[e[t],e[r]]}return e},exports.sleep=Q,exports.slugify=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");return e.trim().replace(/[!@#$%^&*()\-=+[\]{}|\\~;:'",.<>?\/]/g,"").toLowerCase().replace(/\s+/g,"-").normalize("NFD").replace(/[\u0300-\u036f]/g,"")},exports.std=function(e){if(!Array.isArray(e))throw new TypeError("Expect an array for 'arr'");if(e.length<2)throw new Error("Array must contain at least two values.");const r=e.filter(e=>"number"==typeof e&&!isNaN(e));if(r.length<2)throw new Error("Input array must contain at least two numeric values.");const t=r.length,n=r.reduce((e,r)=>e+r,0)/t,o=r.reduce((e,r)=>e+Math.pow(r-n,2),0);return Math.sqrt(o/(t-1))},exports.stripHtml=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'html'");return e.replace(/<[^>]*>/g,"")},exports.stripTime=function(e){if(!G(e))throw new TypeError("Expected a valid Date for 'date'");const r=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),0,0,0,0);return new Date(r)},exports.subtract=function(...e){if(0===e.length||!e.every(e=>"number"==typeof e))throw new TypeError("Expected an array of numbers for 'values'");return e.slice(1).reduce((e,r)=>e-r,e[0])},exports.sumOfDigits=function(e){if("number"!=typeof e)throw new TypeError("Expected a number for 'value'");return e.toString().split("").reduce((e,r)=>e+parseInt(r,10),0)},exports.swap=function(e,r,n){if(!t(e))throw new TypeError("Expected an array for 'array'");if("number"!=typeof r)throw new TypeError("Expected 'fromIndex' to be a number");if(r<0||r>=e.length)throw new RangeError("'fromIndex' is out of bounds");if("number"!=typeof n)throw new TypeError("Expected 'toIndex' to be a number");if(n<0||n>=e.length)throw new RangeError("'toIndex' is out of bounds");return[e[r],e[n]]=[e[n],e[r]],e},exports.template=function(e,r){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");const{pattern:t,escape:n}={pattern:/{{(.*?)}}/g,...r};if(!u(t))throw new TypeError("Expected a RegExp for 'pattern'");if(n&&!o(n))throw new TypeError("Expected a function for 'escape'");return r=>{if(!s(r))throw new TypeError("Expected a plain object for 'data'");let o={...r};if(n)for(const[e,t]of Object.entries(r))o[e]=n(String(t),e);return X(e,o,t)}},exports.throttle=function(e,r,{leading:t=!0,trailing:n=!0,maxWait:o}={}){if("function"!=typeof e)throw new TypeError("Expected a function for 'callback'");let i=null,a=null,f=null,s=0;const u=()=>performance.now();function c(r){s=r,e(...a),a=null}function p(e,r){return setTimeout(e,r)}function l(e){i=null,n&&a&&c(e)}function d(...e){const d=u();var y;null===f&&(f=d),a=e,y=d,null===f||y-f>=r||void 0!==o&&y-s>=o?null===i?t?c(d):n&&(i=p(()=>l(u()),r)):void 0!==o&&d-s>=o&&c(d):null===i&&n&&(i=p(()=>l(u()),function(e){const t=r-(e-(f??0)),n=void 0!==o?o-(e-s):1/0;return Math.min(t,n)}(d))),f=d}return d.cancel=()=>{null!==i&&(clearTimeout(i),i=null),a=null,f=null},d.flush=()=>{null!==i&&a&&(clearTimeout(i),i=null,l(u()))},d},exports.times=function(e,r){if("function"!=typeof e)throw new TypeError("Expected a function for 'callback'");if("number"!=typeof r||!Number.isInteger(r)||r<0)throw new TypeError("Expected a non-negative integer for 'count'");const t=[];for(let n=0;n<r;n++)t.push(e(n));return t},exports.toCamelCase=function(e){if("string"!=typeof e)throw new TypeError("Expected a string, but received "+typeof e);const r=e.trim().toLowerCase().split(" ");return r.shift()+r.map(e=>e[0].toUpperCase().concat(e.slice(1))).join("")},exports.toDate=J,exports.toKebabCase=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");return e.trim().toLowerCase().replace(/\s+/g,"-")},exports.toPascalCase=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");return e.trim().split(" ").map(e=>e[0].toUpperCase().concat(e.slice(1))).join(" ").replace(/\s+/g,"")},exports.toSnakeCase=function(e){if("string"!=typeof e)throw new TypeError("Expected a string for 'str'");return e.trim().toLowerCase().replace(/\s+/g,"_")},exports.truncate=function(e,r){if("string"!=typeof e)throw new TypeError("Expected a string for 'text'");return e.slice(0,r).concat("...")},exports.unflattenObj=function(e){if(!w(e))return e;if(0===Object.keys(e).length)return e;const r=Object.keys(e).every(e=>/^\[\d+\]/.test(e))?[]:{};for(const t in e){if(!Object.hasOwn(e,t))continue;const n=E(t);if(!n)continue;let o=r;for(let e=0;e<n.length-1;e++){const r=n[e],t=r.startsWith("[")&&r.endsWith("]")?+r.slice(1,-1):r,i=n[e+1],a=i?.startsWith?.("[")&&i.endsWith("]");t in o||(o[t]=a?[]:{}),o=o[t]}const i=n[n.length-1];o[i.startsWith("[")&&i.endsWith("]")?+i.slice(1,-1):i]=e[t]}return r},exports.union=function(...e){if(!e.every(t))throw new TypeError("Expected all arguments to be arrays");const r=[];for(const t of e)r.push(...t);return b(r)},exports.unique=b,exports.unzip=function(e){if(!t(e))throw new TypeError("Expected an array for 'zip'");if(!e.every(t))throw new TypeError("Expected all elements in 'zip' to be arrays");if(!e.length)return[];const r=e[0].length,n=Array.from({length:r},()=>[]);for(const r of e)r.forEach((e,r)=>n[r].push(e));return n},exports.utf8Decode=function(e){const r=V(e)?e:new Uint8Array(e);if("undefined"!=typeof TextDecoder)return new TextDecoder("utf-8").decode(r);if("undefined"!=typeof Buffer)return Buffer.from(r).toString("utf8");throw new Error("No UTF-8 decoder available in this environment")},exports.utf8Encode=function(e){if(!p(e))throw new TypeError("Expected a string for 'input'");let r=e;if("undefined"!=typeof TextEncoder)return(new TextEncoder).encode(r);if("undefined"!=typeof Buffer)return new Uint8Array(Buffer.from(r,"utf8"));throw new Error("No UTF-8 encoder available in this environment")},exports.variance=function(e){if(!Array.isArray(e))throw new TypeError("Expect an array for 'arr'");if(e.length<2)throw new Error("Inp