tsu 2.9.0 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var M=(e,n)=>{for(var t in n)d(e,t,{get:n[t],enumerable:!0})},E=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of N(n))!U.call(e,o)&&o!==t&&d(e,o,{get:()=>n[o],enumerable:!(r=C(n,o))||r.enumerable});return e};var S=e=>E(d({},"__esModule",{value:!0}),e);var Le={};M(Le,{capitalise:()=>ke,ceil:()=>F,chars:()=>Oe,clamp:()=>I,clone:()=>m,copyToClipboard:()=>de,debounce:()=>he,deepMerge:()=>O,drop:()=>te,floor:()=>L,groupsOf:()=>re,head:()=>oe,init:()=>ie,isArray:()=>l,isBlank:()=>Ae,isBoolean:()=>_,isBrowser:()=>p,isDefined:()=>$,isEmpty:()=>Ce,isEmptyArray:()=>z,isEmptyObject:()=>J,isEven:()=>q,isFunction:()=>K,isNull:()=>c,isNumber:()=>x,isObject:()=>a,isObjectLike:()=>f,isOdd:()=>R,isString:()=>b,isTouchDevice:()=>Y,isUndefined:()=>Z,isWindow:()=>G,last:()=>ue,max:()=>V,memoize:()=>we,min:()=>D,noop:()=>Q,once:()=>ve,partition:()=>le,product:()=>B,randomChance:()=>P,randomNumber:()=>s,range:()=>se,replaceChar:()=>Ne,round:()=>W,scroll:()=>xe,shuffle:()=>ce,sleep:()=>ee,splitAt:()=>ae,splitStrAt:()=>Ue,sum:()=>X,tail:()=>fe,take:()=>me,throttle:()=>je,toArray:()=>pe,toCamel:()=>Me,toKebab:()=>Ee,toNumber:()=>Se,toOrdinal:()=>Fe,toRomanNumerals:()=>H,truncate:()=>Ie,uniq:()=>T,uuid:()=>ne});module.exports=S(Le);function F(e,n=1){let t=e/n;return Math.ceil(t)*n}function I(e,n,t){return Math.min(t,Math.max(n,e))}function L(e,n=1){let t=e/n;return Math.floor(t)*n}function q(e){return e%2===0}function R(e){return e%2!==0}function V(...e){let n;return e.length===1&&Array.isArray(e[0])?n=e[0]:n=e,Math.max(...n)}function D(...e){let n;return e.length===1&&Array.isArray(e[0])?n=e[0]:n=e,Math.min(...n)}function B(e){let n=1;for(let t=0;t<e.length;t++)n*=e[t];return n}function P(e){return s(e)===0}function s(...e){let n,t;return e.length===1?(n=0,t=e[0]):(n=e[0],t=e[1]),Math.floor(Math.random()*(t-n))+n}function W(e,n=1){let t=e/n;return Math.round(t)*n}function X(e){let n=0;for(let t=0;t<e.length;t++)n+=e[t];return n}var j={1:"I",4:"IV",5:"V",9:"IX",10:"X",40:"XL",50:"L",90:"XC",100:"C",400:"CD",500:"D",900:"CM",1e3:"M"};function H(e,n=!1){let t=e,r="",o=Object.keys(j).map(Number).sort((i,u)=>u-i);for(let i of o)for(;t>=i;)r+=j[i],t-=i;return n?r.toLowerCase():r}function l(e){return Array.isArray(e)}function _(e){return typeof e=="boolean"}function p(){return typeof window<"u"}function $(e){return typeof e<"u"}function z(e){return l(e)&&e.length===0}function J(e){if(!a(e))return!1;for(let n in e)return!1;return!0}function K(e){return typeof e=="function"}function c(e){return Object.prototype.toString.call(e)==="[object Null]"}function x(e){return typeof e=="number"}function a(e){return Object.prototype.toString.call(e)==="[object Object]"}function f(e){return typeof e=="object"}function b(e){return typeof e=="string"}function Y(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function Z(e){return typeof e>"u"}function G(e){return p()&&Object.prototype.toString.call(e)==="[object Window]"}function m(e){if(l(e)){let n=[];for(let t=0;t<e.length;t++)f(e[t])&&!c(e[t])?n[t]=m(e[t]):n[t]=e[t];return n}if(f(e)&&!c(e)){let n={};for(let t in e)f(e[t])&&!c(e[t])?n[t]=m(e[t]):n[t]=e[t];return n}return e}function Q(){}async function ee(e){return e<0&&console.warn("[tsu] warning: a sleep duration less than 0ms will be treated as 0ms."),new Promise(n=>{setTimeout(n,e)})}var k="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";function ne(e=16){let n=k.length,t=e,r="";for(;t--;)r+=k[s(n)];return r}function te(e,n){return e<=0?[...n]:n.slice(e)}function re(e,n){if(e<=0)throw new Error("[tsu] Invalid group size. Is it greater than 0?");if(e>=n.length)return[[...n]];let t=[];for(let r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}function oe(e){return e[0]}function ie(e){return e.slice(0,e.length-1)}function ue(e){return e[e.length-1]}function le(e,n){let t=[],r=[];for(let o=0;o<e.length;o++){let i=e[o];n(i,o,e)?t.push(i):r.push(i)}return[t,r]}function se(...e){let n,t,r;e.length===1?(t=e[0],n=0,r=1):(n=e[0],t=e[1],r=e[2]||1),r<=0&&(console.warn("[tsu] warning: a step less than or equal to 0 will be set to 1."),r=1);let o=[],i=n;for(;i<t;)o.push(i),i+=r||1;return o}function ce(e){let n=m(e),t,r,o;for(t=n.length;t;t-=1)r=s(t),o=n[t-1],n[t-1]=n[r],n[r]=o;return n}function ae(e,n){return e<=0?[[],[...n]]:e>n.length?[[...n],[]]:[n.slice(0,e),n.slice(e)]}function fe(e){return e.slice(1)}function me(e,n){return e<=0?[]:n.slice(0,e)}function pe(e){return e?Array.isArray(e)?e:[e]:[]}function T(e){return Array.from(new Set(e))}function be(e){let n=document.createElement("textarea");n.value=e??"",n.style.position="absolute",n.style.opacity="0",document.body.appendChild(n),n.select(),document.execCommand("copy"),n.remove()}function de(e){p()&&(window.navigator&&"clipboard"in window.navigator?navigator.clipboard.writeText(e):be(e))}function xe({to:e,offset:n=0,duration:t=1e3,container:r=null}){let o=b(e)?document.querySelector(e):e,i=b(r)?document.querySelector(r):r,u=i?.scrollTop||window?.pageYOffset||0,g=(x(o)?o:ye(o,u))+n,A=Date.now();function y(){let h=Date.now()-A,w=h<t,v=w?ge(u,g,h,t):g;w&&requestAnimationFrame(y),i?i.scrollTop=v:window.scrollTo(0,v)}y()}function Te(e){return e<.5?4*Math.pow(e,3):(e-1)*(2*e-2)*(2*e-2)+1}function ge(e,n,t,r){return e+(n-e)*Te(t/r)}function ye(e,n){return e.nodeName==="HTML"?-n:e.getBoundingClientRect().top+n}function he(e,n){n<0&&console.warn("[tsu] warning: a debounce delay less than 0ms will be treated as 0ms.");let t;return function(...r){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),e(...r)},n)}}function we(e){let n={};return function(...t){let r=JSON.stringify(t);if(r in n)return n[r];let o=e(...t);return n[r]=o,o}}function ve(e){let n=!1;return(...t)=>{n||(e(...t),n=!0)}}function je(e,n){n<0&&console.warn("[tsu] warning: a throttle limit less than 0ms will be treated as 0ms.");let t=!1;return function(...r){t||(e(...r),t=!0,setTimeout(()=>{t=!1},n))}}function O(...e){let n={};for(let t=0;t<e.length;t++){let r=e[t],o=Object.keys(r);for(let i=0;i<o.length;i++){let u=o[i];l(n[u])&&l(r[u])?n[u]=T(n[u].concat(r[u])):a(n[u])&&a(r[u])?n[u]=O(n[u],r[u]):n[u]=r[u]}}return n}function ke(e,n=!1,t=" "){return n?e.split(t).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(t):e.charAt(0).toUpperCase()+e.slice(1)}function Oe(e){return e.split("")}function Ae(e){return e.trim().length===0}function Ce(e){return e.length===0}function Ne(e,n,t){return n<0||n>e.length-1?e:e.slice(0,n)+t+e.slice(n+1)}function Ue(e,n){return n<=0?["",e]:n>e.length?[e,""]:[e.slice(0,n),e.slice(n)]}function Me(e){let n=/-(\w)/g;return e.replace(n,(t,r)=>r?r.toUpperCase():"")}function Ee(e){let n=/\B([A-Z])/g;return e.replace(n,"-$1").toLowerCase()}function Se(e){return e.length?Number(e.replace(/[#£€$,%]/g,"")):NaN}function Fe(e){let t=["st","nd","rd"][(e/10%10^1&&e%10)-1]||"th";return`${e}${t}`}function Ie(e,n,t="..."){return n<=0?t:e.slice(0,n)+t}0&&(module.exports={capitalise,ceil,chars,clamp,clone,copyToClipboard,debounce,deepMerge,drop,floor,groupsOf,head,init,isArray,isBlank,isBoolean,isBrowser,isDefined,isEmpty,isEmptyArray,isEmptyObject,isEven,isFunction,isNull,isNumber,isObject,isObjectLike,isOdd,isString,isTouchDevice,isUndefined,isWindow,last,max,memoize,min,noop,once,partition,product,randomChance,randomNumber,range,replaceChar,round,scroll,shuffle,sleep,splitAt,splitStrAt,sum,tail,take,throttle,toArray,toCamel,toKebab,toNumber,toOrdinal,toRomanNumerals,truncate,uniq,uuid});
1
+ "use strict";var x=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var M=(e,r)=>{for(var n in r)x(e,n,{get:r[n],enumerable:!0})},F=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of C(r))!E.call(e,o)&&o!==n&&x(e,o,{get:()=>r[o],enumerable:!(t=N(r,o))||t.enumerable});return e};var S=e=>F(x({},"__esModule",{value:!0}),e);var $e={};M($e,{capitalise:()=>k,capitalize:()=>Ce,ceil:()=>$,chars:()=>Ee,clamp:()=>P,clone:()=>p,copyToClipboard:()=>de,debounce:()=>we,drop:()=>U,es:()=>ue,floor:()=>W,groups:()=>L,head:()=>R,init:()=>q,isArray:()=>f,isBlank:()=>Me,isBoolean:()=>G,isBrowser:()=>m,isDefined:()=>Q,isEmpty:()=>Fe,isEmptyArray:()=>ee,isEmptyObject:()=>re,isEven:()=>X,isFunction:()=>ne,isNull:()=>s,isNumber:()=>d,isObject:()=>b,isObjectLike:()=>l,isOdd:()=>z,isString:()=>a,isTouchDevice:()=>te,isUndefined:()=>oe,isWindow:()=>ie,ks:()=>fe,last:()=>B,max:()=>H,memoise:()=>j,memoize:()=>je,min:()=>_,noop:()=>Oe,once:()=>ve,partition:()=>D,product:()=>V,randomChance:()=>J,randomNumber:()=>u,range:()=>I,replaceChar:()=>Se,round:()=>K,scroll:()=>he,shuffle:()=>se,sleep:()=>Ae,splitArray:()=>le,splitString:()=>Ue,sum:()=>Y,tail:()=>pe,take:()=>ce,throttle:()=>ke,toArray:()=>ae,toCamel:()=>Le,toKebab:()=>Re,toNumber:()=>Z,toOrdinal:()=>qe,toRomanNumerals:()=>Be,truncate:()=>De,unchars:()=>Ie,uniq:()=>xe,uuid:()=>Ne,vs:()=>me});module.exports=S($e);function U(e,r){return e<=0?[...r]:r.slice(e)}function L(e,r){if(r<=0)throw new Error("[tsu] Invalid group size. Is it greater than 0?");if(r>=e.length)return[[...e]];let n=[];for(let t=0;t<e.length;t+=r)n.push(e.slice(t,t+r));return n}function R(e){return e[0]}function q(e){return e.slice(0,e.length-1)}function B(e){return e[e.length-1]}function D(e,r){let n=[],t=[];for(let o=0;o<e.length;o++){let i=e[o];r(i,o,e)?n.push(i):t.push(i)}return[n,t]}function I(...e){let r,n,t;e.length===1?(n=e[0],r=0,t=1):(r=e[0],n=e[1],t=e[2]||1),t<=0&&(console.warn("[tsu] warning: a step less than or equal to 0 will be set to 1."),t=1);let o=[],i=r;for(;i<n;)o.push(i),i+=t||1;return o}function $(e,r=1){let n=e/r;return Math.ceil(n)*r}function P(e,r,n){return Math.min(n,Math.max(r,e))}function W(e,r=1){let n=e/r;return Math.floor(n)*r}function X(e){return e%2===0}function z(e){return e%2!==0}function H(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.max(...r)}function _(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.min(...r)}function V(e){let r=1;for(let n=0;n<e.length;n++)r*=e[n];return r}function u(...e){let r,n;return e.length===1?(r=0,n=e[0]):(r=e[0],n=e[1]),Math.floor(Math.random()*(n-r))+r}function J(e){return u(e)===0}function K(e,r=1){let n=e/r;return Math.round(n)*r}function Y(e){let r=0;for(let n=0;n<e.length;n++)r+=e[n];return r}function Z(e,r=[]){if(!e.length)return NaN;let n=["#","\xA3","\u20AC","$","%",",",...r],t=new RegExp(`[${n.join("")}]`,"g");return Number(e.replace(t,""))}function f(e){return Array.isArray(e)}function G(e){return typeof e=="boolean"}function m(){return typeof window<"u"}function Q(e){return typeof e<"u"}function ee(e){return f(e)&&e.length===0}function re(e){if(!b(e))return!1;for(let r in e)return!1;return!0}function ne(e){return typeof e=="function"}function s(e){return Object.prototype.toString.call(e)==="[object Null]"}function d(e){return typeof e=="number"}function b(e){return Object.prototype.toString.call(e)==="[object Object]"}function l(e){return typeof e=="object"}function a(e){return typeof e=="string"}function te(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function oe(e){return typeof e>"u"}function ie(e){return m()&&Object.prototype.toString.call(e)==="[object Window]"}function p(e){if(f(e)){let r=[];for(let n=0;n<e.length;n++)l(e[n])&&!s(e[n])?r[n]=p(e[n]):r[n]=e[n];return r}if(l(e)&&!s(e)){let r={};for(let n in e)l(e[n])&&!s(e[n])?r[n]=p(e[n]):r[n]=e[n];return r}return e}function ue(e){return Object.entries(e)}function fe(e){return Object.keys(e)}function me(e){return Object.values(e)}function se(e){let r=p(e),n,t,o;for(n=r.length;n;n-=1)t=u(n),o=r[n-1],r[n-1]=r[t],r[t]=o;return r}function le(e,r){return r<=0?[[],[...e]]:r>e.length?[[...e],[]]:[e.slice(0,r),e.slice(r)]}function pe(e){return e.slice(1)}function ce(e,r){return e<=0?[]:r.slice(0,e)}function ae(e){return e?Array.isArray(e)?e:[e]:[]}function xe(e){return Array.from(new Set(e))}function be(e){let r=document.createElement("textarea");r.value=e??"",r.style.position="absolute",r.style.opacity="0",document.body.appendChild(r),r.select(),document.execCommand("copy"),r.remove()}function de(e){m()&&(window.navigator&&"clipboard"in window.navigator?navigator.clipboard.writeText(e):be(e))}function Te(e){return e<.5?4*Math.pow(e,3):(e-1)*(2*e-2)*(2*e-2)+1}function ge(e,r,n,t){return e+(r-e)*Te(n/t)}function ye(e,r){return e.nodeName==="HTML"?-r:e.getBoundingClientRect().top+r}function he({to:e,offset:r=0,duration:n=1e3,container:t=null}){let o=a(e)?document.querySelector(e):e,i=a(t)?document.querySelector(t):t,c=i?.scrollTop||window?.pageYOffset||0,T=(d(o)?o:ye(o,c))+r,A=Date.now();function g(){let y=Date.now()-A,h=y<n,w=h?ge(c,T,y,n):T;h&&requestAnimationFrame(g),i?i.scrollTop=w:window.scrollTo(0,w)}g()}function we(e,r){r<0&&console.warn("[tsu] warning: a debounce delay less than 0ms will be treated as 0ms.");let n;return function(...t){clearTimeout(n),n=setTimeout(()=>{clearTimeout(n),e(...t)},r)}}function j(e){let r={};return function(...n){let t=JSON.stringify(n);if(t in r)return r[t];let o=e(...n);return r[t]=o,o}}var je=j;function ve(e){let r=!1;return(...n)=>{r||(e(...n),r=!0)}}function ke(e,r){r<0&&console.warn("[tsu] warning: a throttle limit less than 0ms will be treated as 0ms.");let n=!1;return function(...t){n||(e(...t),n=!0,setTimeout(()=>{n=!1},r))}}function Oe(){}async function Ae(e){return e<0&&console.warn("[tsu] warning: a sleep duration less than 0ms will be treated as 0ms."),new Promise(r=>{setTimeout(r,e)})}var v="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";function Ne(e=16){let r=v.length,n=e,t="";for(;n--;)t+=v[u(r)];return t}function k(e,r=!1,n=" "){return r?e.split(n).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(n):e.charAt(0).toUpperCase()+e.slice(1)}var Ce=k;function Ee(e){return e.split("")}function Me(e){return e.trim().length===0}function Fe(e){return e.length===0}function Se(e,r,n){return r<0||r>e.length-1?e:e.slice(0,r)+n+e.slice(r+1)}function Ue(e,r){return r<=0?["",e]:r>e.length?[e,""]:[e.slice(0,r),e.slice(r)]}function Le(e){let r=/-(\w)/g;return e.replace(r,(n,t)=>t?t.toUpperCase():"")}function Re(e){let r=/\B([A-Z])/g;return e.replace(r,"-$1").toLowerCase()}function qe(e){let n=["st","nd","rd"][(Math.abs(e)/10%10^1&&Math.abs(e)%10)-1]||"th";return`${e}${n}`}var O={1:"I",4:"IV",5:"V",9:"IX",10:"X",40:"XL",50:"L",90:"XC",100:"C",400:"CD",500:"D",900:"CM",1e3:"M"};function Be(e,r=!1){let n=e,t="",o=Object.keys(O).map(Number).sort((i,c)=>c-i);for(let i of o)for(;n>=i;)t+=O[i],n-=i;return r?t.toLowerCase():t}function De(e,r,n="..."){return r<=0?n:e.slice(0,r)+n}function Ie(e){return e.join("")}0&&(module.exports={capitalise,capitalize,ceil,chars,clamp,clone,copyToClipboard,debounce,drop,es,floor,groups,head,init,isArray,isBlank,isBoolean,isBrowser,isDefined,isEmpty,isEmptyArray,isEmptyObject,isEven,isFunction,isNull,isNumber,isObject,isObjectLike,isOdd,isString,isTouchDevice,isUndefined,isWindow,ks,last,max,memoise,memoize,min,noop,once,partition,product,randomChance,randomNumber,range,replaceChar,round,scroll,shuffle,sleep,splitArray,splitString,sum,tail,take,throttle,toArray,toCamel,toKebab,toNumber,toOrdinal,toRomanNumerals,truncate,unchars,uniq,uuid,vs});
package/dist/index.d.cts CHANGED
@@ -1,9 +1,3 @@
1
- type Arrayable<T> = T | Array<T>;
2
- type Nullable<T> = T | null | undefined;
3
- type Fn<T = any> = (...args: any[]) => T;
4
- type VoidFn = Fn<void>;
5
- type Obj<V = unknown> = Record<string | symbol | number, V>;
6
-
7
1
  /**
8
2
  * Removes the first `n` items of an array.
9
3
  *
@@ -12,14 +6,16 @@ type Obj<V = unknown> = Record<string | symbol | number, V>;
12
6
  * @returns The remaining items.
13
7
  */
14
8
  declare function drop<T>(n: number, array: readonly T[]): T[];
9
+
15
10
  /**
16
11
  * Splits an array into groups of equal size.
17
12
  *
18
- * @param s - The size of each group.
19
13
  * @param array - The array.
14
+ * @param n - The size of each group.
20
15
  * @returns The array split into groups.
21
16
  */
22
- declare function groupsOf<T>(s: number, array: readonly T[]): T[][];
17
+ declare function groups<T>(array: readonly T[], n: number): T[][];
18
+
23
19
  /**
24
20
  * Returns the first item of an array.
25
21
  *
@@ -28,6 +24,7 @@ declare function groupsOf<T>(s: number, array: readonly T[]): T[][];
28
24
  */
29
25
  declare function head(array: readonly []): undefined;
30
26
  declare function head<T>(array: readonly T[]): T;
27
+
31
28
  /**
32
29
  * Returns all but the last item of an array.
33
30
  *
@@ -35,6 +32,7 @@ declare function head<T>(array: readonly T[]): T;
35
32
  * @returns The array without the last item.
36
33
  */
37
34
  declare function init<T>(array: readonly T[]): T[];
35
+
38
36
  /**
39
37
  * Returns the last item of an array.
40
38
  *
@@ -43,6 +41,7 @@ declare function init<T>(array: readonly T[]): T[];
43
41
  */
44
42
  declare function last(array: readonly []): undefined;
45
43
  declare function last<T>(array: readonly T[]): T;
44
+
46
45
  /**
47
46
  * Splits an array into two based on a predicate function.
48
47
  *
@@ -51,6 +50,7 @@ declare function last<T>(array: readonly T[]): T;
51
50
  * @returns The tuple of values that satisfy the predicate and those that don't.
52
51
  */
53
52
  declare function partition<T, U = T>(array: readonly (T | U)[], filter: (current: T | U, idx: number, array: readonly (T | U)[]) => boolean): [T[], U[]];
53
+
54
54
  /**
55
55
  * Generates a range of numbers.
56
56
  *
@@ -61,6 +61,7 @@ declare function partition<T, U = T>(array: readonly (T | U)[], filter: (current
61
61
  */
62
62
  declare function range(stop: number): number[];
63
63
  declare function range(start: number, stop: number, step?: number): number[];
64
+
64
65
  /**
65
66
  * Randomly shuffles items in an array.
66
67
  *
@@ -68,14 +69,16 @@ declare function range(start: number, stop: number, step?: number): number[];
68
69
  * @returns A copy of the array with its items randomly shuffled.
69
70
  */
70
71
  declare function shuffle<T>(array: T[]): T[];
72
+
71
73
  /**
72
74
  * Splits an array into two at a specified index.
73
75
  *
74
- * @param i - The position to split at.
75
76
  * @param array - The array.
77
+ * @param i - The position to split at.
76
78
  * @returns The tuple of values before and after the split.
77
79
  */
78
- declare function splitAt<T>(i: number, array: readonly T[]): [T[], T[]];
80
+ declare function splitArray<T>(array: readonly T[], i: number): [T[], T[]];
81
+
79
82
  /**
80
83
  * Returns all but the first item of an array.
81
84
  *
@@ -83,6 +86,7 @@ declare function splitAt<T>(i: number, array: readonly T[]): [T[], T[]];
83
86
  * @returns The array without the first item.
84
87
  */
85
88
  declare function tail<T>(array: readonly T[]): T[];
89
+
86
90
  /**
87
91
  * Returns the first `n` items of an array.
88
92
  *
@@ -91,6 +95,13 @@ declare function tail<T>(array: readonly T[]): T[];
91
95
  * @returns The first `n` items.
92
96
  */
93
97
  declare function take<T>(n: number, array: readonly T[]): T[];
98
+
99
+ type Arrayable<T> = T | Array<T>;
100
+ type Nullable<T> = T | null | undefined;
101
+ type Fn<T = any> = (...args: any[]) => T;
102
+ type VoidFn = Fn<void>;
103
+ type Obj<V = unknown> = Record<string | symbol | number, V>;
104
+
94
105
  /**
95
106
  * Wraps a single value in an array, if not already an array.
96
107
  *
@@ -98,6 +109,7 @@ declare function take<T>(n: number, array: readonly T[]): T[];
98
109
  * @returns The item wrapped in an array, or the provided array.
99
110
  */
100
111
  declare function toArray<T>(maybeArray: Nullable<Arrayable<T>>): T[];
112
+
101
113
  /**
102
114
  * Removes duplicate primitive values from an array.
103
115
  *
@@ -112,6 +124,7 @@ declare function uniq<T>(array: readonly T[]): T[];
112
124
  * @param str - The string to be copied to the clipboard.
113
125
  */
114
126
  declare function copyToClipboard(str: string): void;
127
+
115
128
  interface ScrollConfig {
116
129
  to: Element | string | number;
117
130
  offset?: number;
@@ -136,21 +149,25 @@ declare function scroll({ to, offset, duration, container }: ScrollConfig): void
136
149
  * @param delay - The time period (in ms).
137
150
  * @returns The debounced function.
138
151
  */
139
- declare function debounce(fn: VoidFn, delay: number): VoidFn;
152
+ declare function debounce(fn: Fn<void>, delay: number): Fn<void>;
153
+
140
154
  /**
141
155
  * Optimises subsequent calls of a function by caching return values.
142
156
  *
143
157
  * @param fn - The function.
144
- * @returns The memoized function.
158
+ * @returns The memoised function.
145
159
  */
146
- declare function memoize<T>(fn: Fn<T>): Fn<T>;
160
+ declare function memoise<T>(fn: Fn<T>): Fn<T>;
161
+ declare const memoize: typeof memoise;
162
+
147
163
  /**
148
164
  * Enforces that a function is only callable one time.
149
165
  *
150
166
  * @param fn - The function.
151
167
  * @returns The one-time callable function.
152
168
  */
153
- declare function once(fn: VoidFn): VoidFn;
169
+ declare function once(fn: Fn<void>): Fn<void>;
170
+
154
171
  /**
155
172
  * Prevents function execution for a specified time period after it was last called.
156
173
  *
@@ -158,7 +175,7 @@ declare function once(fn: VoidFn): VoidFn;
158
175
  * @param limit - The time period.
159
176
  * @returns The throttled function.
160
177
  */
161
- declare function throttle(fn: VoidFn, limit: number): VoidFn;
178
+ declare function throttle(fn: Fn<void>, limit: number): Fn<void>;
162
179
 
163
180
  /**
164
181
  * Identifies if a value is an array.
@@ -167,6 +184,7 @@ declare function throttle(fn: VoidFn, limit: number): VoidFn;
167
184
  * @returns If the value is an array.
168
185
  */
169
186
  declare function isArray(val: unknown): val is any[];
187
+
170
188
  /**
171
189
  * Identifies if a value is a boolean.
172
190
  *
@@ -174,19 +192,22 @@ declare function isArray(val: unknown): val is any[];
174
192
  * @returns If the value is a boolean.
175
193
  */
176
194
  declare function isBoolean(val: unknown): val is boolean;
195
+
177
196
  /**
178
197
  * Identifies if the code is being run in a browser.
179
198
  *
180
199
  * @returns If the code is being run in a browser.
181
200
  */
182
201
  declare function isBrowser(): boolean;
202
+
183
203
  /**
184
204
  * Identifies if a value is defined.
185
205
  *
186
206
  * @param val - The value.
187
207
  * @returns If the value is defined.
188
208
  */
189
- declare function isDefined<T>(val: T): val is T;
209
+ declare function isDefined<T>(val: T): val is Exclude<T, null | undefined>;
210
+
190
211
  /**
191
212
  * Identifies if a value is an empty array.
192
213
  *
@@ -194,13 +215,15 @@ declare function isDefined<T>(val: T): val is T;
194
215
  * @returns If the value is an empty array.
195
216
  */
196
217
  declare function isEmptyArray(val: unknown): val is [];
218
+
197
219
  /**
198
220
  * Identifies if a value is an empty object.
199
221
  *
200
222
  * @param val - The value.
201
223
  * @returns If the value is an empty object.
202
224
  */
203
- declare function isEmptyObject(val: unknown): val is Record<string, never>;
225
+ declare function isEmptyObject(val: unknown): val is Obj<never>;
226
+
204
227
  /**
205
228
  * Identifies if a value is a function.
206
229
  *
@@ -208,6 +231,7 @@ declare function isEmptyObject(val: unknown): val is Record<string, never>;
208
231
  * @returns If the value is a function.
209
232
  */
210
233
  declare function isFunction<T extends Fn>(val: unknown): val is T;
234
+
211
235
  /**
212
236
  * Identifies if a value is null.
213
237
  *
@@ -215,6 +239,7 @@ declare function isFunction<T extends Fn>(val: unknown): val is T;
215
239
  * @returns If the value is null.
216
240
  */
217
241
  declare function isNull(val: unknown): val is null;
242
+
218
243
  /**
219
244
  * Identifies if a value is a number.
220
245
  *
@@ -222,6 +247,7 @@ declare function isNull(val: unknown): val is null;
222
247
  * @returns If the value is a number.
223
248
  */
224
249
  declare function isNumber(val: unknown): val is number;
250
+
225
251
  /**
226
252
  * Identifies if a value is an object.
227
253
  *
@@ -229,6 +255,7 @@ declare function isNumber(val: unknown): val is number;
229
255
  * @returns If the value is an object.
230
256
  */
231
257
  declare function isObject(val: unknown): val is Obj;
258
+
232
259
  /**
233
260
  * Identifies if a value is an array, an object, a date, or null.
234
261
  *
@@ -236,6 +263,7 @@ declare function isObject(val: unknown): val is Obj;
236
263
  * @returns If the value is an array, an object, a date, or null.
237
264
  */
238
265
  declare function isObjectLike(val: unknown): val is object;
266
+
239
267
  /**
240
268
  * Identifies if a value is a string.
241
269
  *
@@ -243,12 +271,14 @@ declare function isObjectLike(val: unknown): val is object;
243
271
  * @returns If the value is a string.
244
272
  */
245
273
  declare function isString(val: unknown): val is string;
274
+
246
275
  /**
247
276
  * Identifies if the code is being run on a touch device.
248
277
  *
249
278
  * @returns If the code is being run on a touch device.
250
279
  */
251
280
  declare function isTouchDevice(): boolean;
281
+
252
282
  /**
253
283
  * Identifies if a value is undefined.
254
284
  *
@@ -256,6 +286,7 @@ declare function isTouchDevice(): boolean;
256
286
  * @returns If the value is undefined.
257
287
  */
258
288
  declare function isUndefined(val: unknown): val is undefined;
289
+
259
290
  /**
260
291
  * Identifies if a value is the global window.
261
292
  *
@@ -264,6 +295,29 @@ declare function isUndefined(val: unknown): val is undefined;
264
295
  */
265
296
  declare function isWindow(val: unknown): val is Window;
266
297
 
298
+ /**
299
+ * Does nothing.
300
+ *
301
+ * @returns Nothing.
302
+ */
303
+ declare function noop(): void;
304
+
305
+ /**
306
+ * Halts thread execution for a specified time period.
307
+ *
308
+ * @param duration - The time period (in ms).
309
+ * @returns The halting promise.
310
+ */
311
+ declare function sleep(duration: number): Promise<void>;
312
+
313
+ /**
314
+ * Generates a random string of a specified length.
315
+ *
316
+ * @param length - The length of the randomly generated string.
317
+ * @returns The randomly generated string.
318
+ */
319
+ declare function uuid(length?: number): string;
320
+
267
321
  /**
268
322
  * Rounds a number up to the nearest multiple of the specified factor.
269
323
  *
@@ -272,6 +326,7 @@ declare function isWindow(val: unknown): val is Window;
272
326
  * @returns The rounded number.
273
327
  */
274
328
  declare function ceil(n: number, factor?: number): number;
329
+
275
330
  /**
276
331
  * Restricts a number between two bounds.
277
332
  *
@@ -281,6 +336,7 @@ declare function ceil(n: number, factor?: number): number;
281
336
  * @returns The number restricted between the specified bounds.
282
337
  */
283
338
  declare function clamp(n: number, min: number, max: number): number;
339
+
284
340
  /**
285
341
  * Rounds a number down to the nearest multiple of the specified factor.
286
342
  *
@@ -289,6 +345,7 @@ declare function clamp(n: number, min: number, max: number): number;
289
345
  * @returns The rounded number.
290
346
  */
291
347
  declare function floor(n: number, factor?: number): number;
348
+
292
349
  /**
293
350
  * Identifies if a number is even.
294
351
  *
@@ -296,6 +353,7 @@ declare function floor(n: number, factor?: number): number;
296
353
  * @returns If the number is even.
297
354
  */
298
355
  declare function isEven(n: number): boolean;
356
+
299
357
  /**
300
358
  * Identifies if a number is odd.
301
359
  *
@@ -303,6 +361,7 @@ declare function isEven(n: number): boolean;
303
361
  * @returns If the number is odd.
304
362
  */
305
363
  declare function isOdd(n: number): boolean;
364
+
306
365
  /**
307
366
  * Returns the maximum number of provided numbers or array of numbers.
308
367
  *
@@ -310,6 +369,7 @@ declare function isOdd(n: number): boolean;
310
369
  * @returns The maximum number.
311
370
  */
312
371
  declare function max(...ns: number[] | [number[]]): number;
372
+
313
373
  /**
314
374
  * Returns the minimum number of provided numbers or array of numbers.
315
375
  *
@@ -317,6 +377,7 @@ declare function max(...ns: number[] | [number[]]): number;
317
377
  * @returns The minimum number.
318
378
  */
319
379
  declare function min(...ns: number[] | [number[]]): number;
380
+
320
381
  /**
321
382
  * Returns the product of a number array.
322
383
  *
@@ -324,6 +385,7 @@ declare function min(...ns: number[] | [number[]]): number;
324
385
  * @returns The product.
325
386
  */
326
387
  declare function product(ns: readonly number[]): number;
388
+
327
389
  /**
328
390
  * Rolls an n-sided die.
329
391
  *
@@ -331,6 +393,7 @@ declare function product(ns: readonly number[]): number;
331
393
  * @returns If the die roll was 0.
332
394
  */
333
395
  declare function randomChance(n: number): boolean;
396
+
334
397
  /**
335
398
  * Generates a random integer between bounds.
336
399
  *
@@ -340,6 +403,7 @@ declare function randomChance(n: number): boolean;
340
403
  */
341
404
  declare function randomNumber(max: number): number;
342
405
  declare function randomNumber(min: number, max: number): number;
406
+
343
407
  /**
344
408
  * Rounds a number to the nearest multiple of the specified factor.
345
409
  *
@@ -348,6 +412,7 @@ declare function randomNumber(min: number, max: number): number;
348
412
  * @returns The rounded number.
349
413
  */
350
414
  declare function round(n: number, factor?: number): number;
415
+
351
416
  /**
352
417
  * Returns the sum of a number array.
353
418
  *
@@ -355,14 +420,15 @@ declare function round(n: number, factor?: number): number;
355
420
  * @returns The sum.
356
421
  */
357
422
  declare function sum(ns: readonly number[]): number;
423
+
358
424
  /**
359
- * Converts a given number to Roman numerals.
425
+ * Converts a string which contains a number into the number itself.
360
426
  *
361
- * @param n - The number to convert to Roman numerals.
362
- * @param lowerCase - If the numerals should be in lowercase.
363
- * @returns - The Roman numeral representation of the given number.
427
+ * @param str - The string.
428
+ * @param extensions - Additional symbols to consider in the conversion.
429
+ * @returns The number.
364
430
  */
365
- declare function toRomanNumerals(n: number, lowerCase?: boolean): string;
431
+ declare function toNumber(str: string, extensions?: string[]): number;
366
432
 
367
433
  /**
368
434
  * Deep clones an array or object.
@@ -371,35 +437,30 @@ declare function toRomanNumerals(n: number, lowerCase?: boolean): string;
371
437
  * @returns A deep clone of the input array or object.
372
438
  */
373
439
  declare function clone<T>(input: T): T;
440
+
374
441
  /**
375
- * Does nothing.
376
- *
377
- * @returns Nothing.
378
- */
379
- declare function noop(): void;
380
- /**
381
- * Halts thread execution for a specified time period.
442
+ * Strict-typed, shorthand `Object.entries`
382
443
  *
383
- * @param duration - The time period (in ms).
384
- * @returns The halting promise.
444
+ * @param obj - The object to extract the entries from.
445
+ * @returns The entries.
385
446
  */
386
- declare function sleep(duration: number): Promise<void>;
447
+ declare function es<T extends object>(obj: T): [keyof T, T[keyof T]][];
448
+
387
449
  /**
388
- * Generates a random string of a specified length.
450
+ * Strict-typed, shorthand `Object.keys`
389
451
  *
390
- * @param length - The length of the randomly generated string.
391
- * @returns The randomly generated string.
452
+ * @param obj - The object to extract the keys from.
453
+ * @returns The keys.
392
454
  */
393
- declare function uuid(length?: number): string;
455
+ declare function ks<T extends object>(obj: T): Array<`${keyof T & (string | number | boolean | null | undefined)}`>;
394
456
 
395
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
396
457
  /**
397
- * Recursively merges multiple objects into one.
458
+ * Shorthand `Object.values`
398
459
  *
399
- * @param objects - The objects to merge.
400
- * @returns The merged object.
460
+ * @param obj - The object to extract the values from.
461
+ * @returns The values.
401
462
  */
402
- declare function deepMerge<T extends Obj<any>[]>(...objects: T): UnionToIntersection<T[number]>;
463
+ declare function vs<T>(obj: Obj<T>): T[];
403
464
 
404
465
  /**
405
466
  * Capitalises the first letter of one word, or all words, in a string.
@@ -410,6 +471,8 @@ declare function deepMerge<T extends Obj<any>[]>(...objects: T): UnionToIntersec
410
471
  * @returns The capitalised string.
411
472
  */
412
473
  declare function capitalise(str: string, allWords?: boolean, delimiter?: string): string;
474
+ declare const capitalize: typeof capitalise;
475
+
413
476
  /**
414
477
  * Separates a string into an array of characters.
415
478
  *
@@ -417,6 +480,7 @@ declare function capitalise(str: string, allWords?: boolean, delimiter?: string)
417
480
  * @returns The string's characters.
418
481
  */
419
482
  declare function chars(str: string): string[];
483
+
420
484
  /**
421
485
  * Identifies strings which only contain whitespace.
422
486
  *
@@ -424,6 +488,7 @@ declare function chars(str: string): string[];
424
488
  * @returns If the string is blank.
425
489
  */
426
490
  declare function isBlank(str: string): boolean;
491
+
427
492
  /**
428
493
  * Identifies empty strings.
429
494
  *
@@ -431,15 +496,17 @@ declare function isBlank(str: string): boolean;
431
496
  * @returns If the string is empty.
432
497
  */
433
498
  declare function isEmpty(str: string): boolean;
499
+
434
500
  /**
435
501
  * Replaces a character at a specified index in a string with a new character.
436
502
  *
437
503
  * @param str - The string.
438
504
  * @param i - The index of the character to replace.
439
505
  * @param char - The character to replace with.
440
- * @returns - The modified string with the character replaced.
506
+ * @returns The modified string with the character replaced.
441
507
  */
442
508
  declare function replaceChar(str: string, i: number, char: string): string;
509
+
443
510
  /**
444
511
  * Splits a string into two at a specified index.
445
512
  *
@@ -447,7 +514,8 @@ declare function replaceChar(str: string, i: number, char: string): string;
447
514
  * @param i - The position to split at.
448
515
  * @returns The tuple of strings before and after the split.
449
516
  */
450
- declare function splitStrAt(str: string, i: number): [string, string];
517
+ declare function splitString(str: string, i: number): [string, string];
518
+
451
519
  /**
452
520
  * Converts a kebab case string to camel case.
453
521
  *
@@ -455,6 +523,7 @@ declare function splitStrAt(str: string, i: number): [string, string];
455
523
  * @returns The camel case string.
456
524
  */
457
525
  declare function toCamel(str: string): string;
526
+
458
527
  /**
459
528
  * Converts a camel case string to kebab case.
460
529
  *
@@ -462,13 +531,7 @@ declare function toCamel(str: string): string;
462
531
  * @returns The kebab case string.
463
532
  */
464
533
  declare function toKebab(str: string): string;
465
- /**
466
- * Converts a string which contains a number into the number itself.
467
- *
468
- * @param str - The string.
469
- * @returns The number.
470
- */
471
- declare function toNumber(str: string): number;
534
+
472
535
  /**
473
536
  * Adds the respective ordinal suffix (-st, -nd, -rd or -th) to a number.
474
537
  *
@@ -476,6 +539,16 @@ declare function toNumber(str: string): number;
476
539
  * @returns The number with the ordinal suffix appended.
477
540
  */
478
541
  declare function toOrdinal(n: number): string;
542
+
543
+ /**
544
+ * Converts a given number to Roman numerals.
545
+ *
546
+ * @param n - The number to convert to Roman numerals.
547
+ * @param lowerCase - If the numerals should be in lowercase.
548
+ * @returns The Roman numeral representation of the given number.
549
+ */
550
+ declare function toRomanNumerals(n: number, lowerCase?: boolean): string;
551
+
479
552
  /**
480
553
  * Truncates a string to a provided length.
481
554
  *
@@ -486,4 +559,12 @@ declare function toOrdinal(n: number): string;
486
559
  */
487
560
  declare function truncate(str: string, length: number, suffix?: string): string;
488
561
 
489
- export { type Arrayable, type Fn, type Nullable, type Obj, type VoidFn, capitalise, ceil, chars, clamp, clone, copyToClipboard, debounce, deepMerge, drop, floor, groupsOf, head, init, isArray, isBlank, isBoolean, isBrowser, isDefined, isEmpty, isEmptyArray, isEmptyObject, isEven, isFunction, isNull, isNumber, isObject, isObjectLike, isOdd, isString, isTouchDevice, isUndefined, isWindow, last, max, memoize, min, noop, once, partition, product, randomChance, randomNumber, range, replaceChar, round, scroll, shuffle, sleep, splitAt, splitStrAt, sum, tail, take, throttle, toArray, toCamel, toKebab, toNumber, toOrdinal, toRomanNumerals, truncate, uniq, uuid };
562
+ /**
563
+ * Joins an array of characters into a string.
564
+ *
565
+ * @param chars - The characters.
566
+ * @returns The string.
567
+ */
568
+ declare function unchars(chars: string[]): string;
569
+
570
+ export { type Arrayable, type Fn, type Nullable, type Obj, type VoidFn, capitalise, capitalize, ceil, chars, clamp, clone, copyToClipboard, debounce, drop, es, floor, groups, head, init, isArray, isBlank, isBoolean, isBrowser, isDefined, isEmpty, isEmptyArray, isEmptyObject, isEven, isFunction, isNull, isNumber, isObject, isObjectLike, isOdd, isString, isTouchDevice, isUndefined, isWindow, ks, last, max, memoise, memoize, min, noop, once, partition, product, randomChance, randomNumber, range, replaceChar, round, scroll, shuffle, sleep, splitArray, splitString, sum, tail, take, throttle, toArray, toCamel, toKebab, toNumber, toOrdinal, toRomanNumerals, truncate, unchars, uniq, uuid, vs };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,3 @@
1
- type Arrayable<T> = T | Array<T>;
2
- type Nullable<T> = T | null | undefined;
3
- type Fn<T = any> = (...args: any[]) => T;
4
- type VoidFn = Fn<void>;
5
- type Obj<V = unknown> = Record<string | symbol | number, V>;
6
-
7
1
  /**
8
2
  * Removes the first `n` items of an array.
9
3
  *
@@ -12,14 +6,16 @@ type Obj<V = unknown> = Record<string | symbol | number, V>;
12
6
  * @returns The remaining items.
13
7
  */
14
8
  declare function drop<T>(n: number, array: readonly T[]): T[];
9
+
15
10
  /**
16
11
  * Splits an array into groups of equal size.
17
12
  *
18
- * @param s - The size of each group.
19
13
  * @param array - The array.
14
+ * @param n - The size of each group.
20
15
  * @returns The array split into groups.
21
16
  */
22
- declare function groupsOf<T>(s: number, array: readonly T[]): T[][];
17
+ declare function groups<T>(array: readonly T[], n: number): T[][];
18
+
23
19
  /**
24
20
  * Returns the first item of an array.
25
21
  *
@@ -28,6 +24,7 @@ declare function groupsOf<T>(s: number, array: readonly T[]): T[][];
28
24
  */
29
25
  declare function head(array: readonly []): undefined;
30
26
  declare function head<T>(array: readonly T[]): T;
27
+
31
28
  /**
32
29
  * Returns all but the last item of an array.
33
30
  *
@@ -35,6 +32,7 @@ declare function head<T>(array: readonly T[]): T;
35
32
  * @returns The array without the last item.
36
33
  */
37
34
  declare function init<T>(array: readonly T[]): T[];
35
+
38
36
  /**
39
37
  * Returns the last item of an array.
40
38
  *
@@ -43,6 +41,7 @@ declare function init<T>(array: readonly T[]): T[];
43
41
  */
44
42
  declare function last(array: readonly []): undefined;
45
43
  declare function last<T>(array: readonly T[]): T;
44
+
46
45
  /**
47
46
  * Splits an array into two based on a predicate function.
48
47
  *
@@ -51,6 +50,7 @@ declare function last<T>(array: readonly T[]): T;
51
50
  * @returns The tuple of values that satisfy the predicate and those that don't.
52
51
  */
53
52
  declare function partition<T, U = T>(array: readonly (T | U)[], filter: (current: T | U, idx: number, array: readonly (T | U)[]) => boolean): [T[], U[]];
53
+
54
54
  /**
55
55
  * Generates a range of numbers.
56
56
  *
@@ -61,6 +61,7 @@ declare function partition<T, U = T>(array: readonly (T | U)[], filter: (current
61
61
  */
62
62
  declare function range(stop: number): number[];
63
63
  declare function range(start: number, stop: number, step?: number): number[];
64
+
64
65
  /**
65
66
  * Randomly shuffles items in an array.
66
67
  *
@@ -68,14 +69,16 @@ declare function range(start: number, stop: number, step?: number): number[];
68
69
  * @returns A copy of the array with its items randomly shuffled.
69
70
  */
70
71
  declare function shuffle<T>(array: T[]): T[];
72
+
71
73
  /**
72
74
  * Splits an array into two at a specified index.
73
75
  *
74
- * @param i - The position to split at.
75
76
  * @param array - The array.
77
+ * @param i - The position to split at.
76
78
  * @returns The tuple of values before and after the split.
77
79
  */
78
- declare function splitAt<T>(i: number, array: readonly T[]): [T[], T[]];
80
+ declare function splitArray<T>(array: readonly T[], i: number): [T[], T[]];
81
+
79
82
  /**
80
83
  * Returns all but the first item of an array.
81
84
  *
@@ -83,6 +86,7 @@ declare function splitAt<T>(i: number, array: readonly T[]): [T[], T[]];
83
86
  * @returns The array without the first item.
84
87
  */
85
88
  declare function tail<T>(array: readonly T[]): T[];
89
+
86
90
  /**
87
91
  * Returns the first `n` items of an array.
88
92
  *
@@ -91,6 +95,13 @@ declare function tail<T>(array: readonly T[]): T[];
91
95
  * @returns The first `n` items.
92
96
  */
93
97
  declare function take<T>(n: number, array: readonly T[]): T[];
98
+
99
+ type Arrayable<T> = T | Array<T>;
100
+ type Nullable<T> = T | null | undefined;
101
+ type Fn<T = any> = (...args: any[]) => T;
102
+ type VoidFn = Fn<void>;
103
+ type Obj<V = unknown> = Record<string | symbol | number, V>;
104
+
94
105
  /**
95
106
  * Wraps a single value in an array, if not already an array.
96
107
  *
@@ -98,6 +109,7 @@ declare function take<T>(n: number, array: readonly T[]): T[];
98
109
  * @returns The item wrapped in an array, or the provided array.
99
110
  */
100
111
  declare function toArray<T>(maybeArray: Nullable<Arrayable<T>>): T[];
112
+
101
113
  /**
102
114
  * Removes duplicate primitive values from an array.
103
115
  *
@@ -112,6 +124,7 @@ declare function uniq<T>(array: readonly T[]): T[];
112
124
  * @param str - The string to be copied to the clipboard.
113
125
  */
114
126
  declare function copyToClipboard(str: string): void;
127
+
115
128
  interface ScrollConfig {
116
129
  to: Element | string | number;
117
130
  offset?: number;
@@ -136,21 +149,25 @@ declare function scroll({ to, offset, duration, container }: ScrollConfig): void
136
149
  * @param delay - The time period (in ms).
137
150
  * @returns The debounced function.
138
151
  */
139
- declare function debounce(fn: VoidFn, delay: number): VoidFn;
152
+ declare function debounce(fn: Fn<void>, delay: number): Fn<void>;
153
+
140
154
  /**
141
155
  * Optimises subsequent calls of a function by caching return values.
142
156
  *
143
157
  * @param fn - The function.
144
- * @returns The memoized function.
158
+ * @returns The memoised function.
145
159
  */
146
- declare function memoize<T>(fn: Fn<T>): Fn<T>;
160
+ declare function memoise<T>(fn: Fn<T>): Fn<T>;
161
+ declare const memoize: typeof memoise;
162
+
147
163
  /**
148
164
  * Enforces that a function is only callable one time.
149
165
  *
150
166
  * @param fn - The function.
151
167
  * @returns The one-time callable function.
152
168
  */
153
- declare function once(fn: VoidFn): VoidFn;
169
+ declare function once(fn: Fn<void>): Fn<void>;
170
+
154
171
  /**
155
172
  * Prevents function execution for a specified time period after it was last called.
156
173
  *
@@ -158,7 +175,7 @@ declare function once(fn: VoidFn): VoidFn;
158
175
  * @param limit - The time period.
159
176
  * @returns The throttled function.
160
177
  */
161
- declare function throttle(fn: VoidFn, limit: number): VoidFn;
178
+ declare function throttle(fn: Fn<void>, limit: number): Fn<void>;
162
179
 
163
180
  /**
164
181
  * Identifies if a value is an array.
@@ -167,6 +184,7 @@ declare function throttle(fn: VoidFn, limit: number): VoidFn;
167
184
  * @returns If the value is an array.
168
185
  */
169
186
  declare function isArray(val: unknown): val is any[];
187
+
170
188
  /**
171
189
  * Identifies if a value is a boolean.
172
190
  *
@@ -174,19 +192,22 @@ declare function isArray(val: unknown): val is any[];
174
192
  * @returns If the value is a boolean.
175
193
  */
176
194
  declare function isBoolean(val: unknown): val is boolean;
195
+
177
196
  /**
178
197
  * Identifies if the code is being run in a browser.
179
198
  *
180
199
  * @returns If the code is being run in a browser.
181
200
  */
182
201
  declare function isBrowser(): boolean;
202
+
183
203
  /**
184
204
  * Identifies if a value is defined.
185
205
  *
186
206
  * @param val - The value.
187
207
  * @returns If the value is defined.
188
208
  */
189
- declare function isDefined<T>(val: T): val is T;
209
+ declare function isDefined<T>(val: T): val is Exclude<T, null | undefined>;
210
+
190
211
  /**
191
212
  * Identifies if a value is an empty array.
192
213
  *
@@ -194,13 +215,15 @@ declare function isDefined<T>(val: T): val is T;
194
215
  * @returns If the value is an empty array.
195
216
  */
196
217
  declare function isEmptyArray(val: unknown): val is [];
218
+
197
219
  /**
198
220
  * Identifies if a value is an empty object.
199
221
  *
200
222
  * @param val - The value.
201
223
  * @returns If the value is an empty object.
202
224
  */
203
- declare function isEmptyObject(val: unknown): val is Record<string, never>;
225
+ declare function isEmptyObject(val: unknown): val is Obj<never>;
226
+
204
227
  /**
205
228
  * Identifies if a value is a function.
206
229
  *
@@ -208,6 +231,7 @@ declare function isEmptyObject(val: unknown): val is Record<string, never>;
208
231
  * @returns If the value is a function.
209
232
  */
210
233
  declare function isFunction<T extends Fn>(val: unknown): val is T;
234
+
211
235
  /**
212
236
  * Identifies if a value is null.
213
237
  *
@@ -215,6 +239,7 @@ declare function isFunction<T extends Fn>(val: unknown): val is T;
215
239
  * @returns If the value is null.
216
240
  */
217
241
  declare function isNull(val: unknown): val is null;
242
+
218
243
  /**
219
244
  * Identifies if a value is a number.
220
245
  *
@@ -222,6 +247,7 @@ declare function isNull(val: unknown): val is null;
222
247
  * @returns If the value is a number.
223
248
  */
224
249
  declare function isNumber(val: unknown): val is number;
250
+
225
251
  /**
226
252
  * Identifies if a value is an object.
227
253
  *
@@ -229,6 +255,7 @@ declare function isNumber(val: unknown): val is number;
229
255
  * @returns If the value is an object.
230
256
  */
231
257
  declare function isObject(val: unknown): val is Obj;
258
+
232
259
  /**
233
260
  * Identifies if a value is an array, an object, a date, or null.
234
261
  *
@@ -236,6 +263,7 @@ declare function isObject(val: unknown): val is Obj;
236
263
  * @returns If the value is an array, an object, a date, or null.
237
264
  */
238
265
  declare function isObjectLike(val: unknown): val is object;
266
+
239
267
  /**
240
268
  * Identifies if a value is a string.
241
269
  *
@@ -243,12 +271,14 @@ declare function isObjectLike(val: unknown): val is object;
243
271
  * @returns If the value is a string.
244
272
  */
245
273
  declare function isString(val: unknown): val is string;
274
+
246
275
  /**
247
276
  * Identifies if the code is being run on a touch device.
248
277
  *
249
278
  * @returns If the code is being run on a touch device.
250
279
  */
251
280
  declare function isTouchDevice(): boolean;
281
+
252
282
  /**
253
283
  * Identifies if a value is undefined.
254
284
  *
@@ -256,6 +286,7 @@ declare function isTouchDevice(): boolean;
256
286
  * @returns If the value is undefined.
257
287
  */
258
288
  declare function isUndefined(val: unknown): val is undefined;
289
+
259
290
  /**
260
291
  * Identifies if a value is the global window.
261
292
  *
@@ -264,6 +295,29 @@ declare function isUndefined(val: unknown): val is undefined;
264
295
  */
265
296
  declare function isWindow(val: unknown): val is Window;
266
297
 
298
+ /**
299
+ * Does nothing.
300
+ *
301
+ * @returns Nothing.
302
+ */
303
+ declare function noop(): void;
304
+
305
+ /**
306
+ * Halts thread execution for a specified time period.
307
+ *
308
+ * @param duration - The time period (in ms).
309
+ * @returns The halting promise.
310
+ */
311
+ declare function sleep(duration: number): Promise<void>;
312
+
313
+ /**
314
+ * Generates a random string of a specified length.
315
+ *
316
+ * @param length - The length of the randomly generated string.
317
+ * @returns The randomly generated string.
318
+ */
319
+ declare function uuid(length?: number): string;
320
+
267
321
  /**
268
322
  * Rounds a number up to the nearest multiple of the specified factor.
269
323
  *
@@ -272,6 +326,7 @@ declare function isWindow(val: unknown): val is Window;
272
326
  * @returns The rounded number.
273
327
  */
274
328
  declare function ceil(n: number, factor?: number): number;
329
+
275
330
  /**
276
331
  * Restricts a number between two bounds.
277
332
  *
@@ -281,6 +336,7 @@ declare function ceil(n: number, factor?: number): number;
281
336
  * @returns The number restricted between the specified bounds.
282
337
  */
283
338
  declare function clamp(n: number, min: number, max: number): number;
339
+
284
340
  /**
285
341
  * Rounds a number down to the nearest multiple of the specified factor.
286
342
  *
@@ -289,6 +345,7 @@ declare function clamp(n: number, min: number, max: number): number;
289
345
  * @returns The rounded number.
290
346
  */
291
347
  declare function floor(n: number, factor?: number): number;
348
+
292
349
  /**
293
350
  * Identifies if a number is even.
294
351
  *
@@ -296,6 +353,7 @@ declare function floor(n: number, factor?: number): number;
296
353
  * @returns If the number is even.
297
354
  */
298
355
  declare function isEven(n: number): boolean;
356
+
299
357
  /**
300
358
  * Identifies if a number is odd.
301
359
  *
@@ -303,6 +361,7 @@ declare function isEven(n: number): boolean;
303
361
  * @returns If the number is odd.
304
362
  */
305
363
  declare function isOdd(n: number): boolean;
364
+
306
365
  /**
307
366
  * Returns the maximum number of provided numbers or array of numbers.
308
367
  *
@@ -310,6 +369,7 @@ declare function isOdd(n: number): boolean;
310
369
  * @returns The maximum number.
311
370
  */
312
371
  declare function max(...ns: number[] | [number[]]): number;
372
+
313
373
  /**
314
374
  * Returns the minimum number of provided numbers or array of numbers.
315
375
  *
@@ -317,6 +377,7 @@ declare function max(...ns: number[] | [number[]]): number;
317
377
  * @returns The minimum number.
318
378
  */
319
379
  declare function min(...ns: number[] | [number[]]): number;
380
+
320
381
  /**
321
382
  * Returns the product of a number array.
322
383
  *
@@ -324,6 +385,7 @@ declare function min(...ns: number[] | [number[]]): number;
324
385
  * @returns The product.
325
386
  */
326
387
  declare function product(ns: readonly number[]): number;
388
+
327
389
  /**
328
390
  * Rolls an n-sided die.
329
391
  *
@@ -331,6 +393,7 @@ declare function product(ns: readonly number[]): number;
331
393
  * @returns If the die roll was 0.
332
394
  */
333
395
  declare function randomChance(n: number): boolean;
396
+
334
397
  /**
335
398
  * Generates a random integer between bounds.
336
399
  *
@@ -340,6 +403,7 @@ declare function randomChance(n: number): boolean;
340
403
  */
341
404
  declare function randomNumber(max: number): number;
342
405
  declare function randomNumber(min: number, max: number): number;
406
+
343
407
  /**
344
408
  * Rounds a number to the nearest multiple of the specified factor.
345
409
  *
@@ -348,6 +412,7 @@ declare function randomNumber(min: number, max: number): number;
348
412
  * @returns The rounded number.
349
413
  */
350
414
  declare function round(n: number, factor?: number): number;
415
+
351
416
  /**
352
417
  * Returns the sum of a number array.
353
418
  *
@@ -355,14 +420,15 @@ declare function round(n: number, factor?: number): number;
355
420
  * @returns The sum.
356
421
  */
357
422
  declare function sum(ns: readonly number[]): number;
423
+
358
424
  /**
359
- * Converts a given number to Roman numerals.
425
+ * Converts a string which contains a number into the number itself.
360
426
  *
361
- * @param n - The number to convert to Roman numerals.
362
- * @param lowerCase - If the numerals should be in lowercase.
363
- * @returns - The Roman numeral representation of the given number.
427
+ * @param str - The string.
428
+ * @param extensions - Additional symbols to consider in the conversion.
429
+ * @returns The number.
364
430
  */
365
- declare function toRomanNumerals(n: number, lowerCase?: boolean): string;
431
+ declare function toNumber(str: string, extensions?: string[]): number;
366
432
 
367
433
  /**
368
434
  * Deep clones an array or object.
@@ -371,35 +437,30 @@ declare function toRomanNumerals(n: number, lowerCase?: boolean): string;
371
437
  * @returns A deep clone of the input array or object.
372
438
  */
373
439
  declare function clone<T>(input: T): T;
440
+
374
441
  /**
375
- * Does nothing.
376
- *
377
- * @returns Nothing.
378
- */
379
- declare function noop(): void;
380
- /**
381
- * Halts thread execution for a specified time period.
442
+ * Strict-typed, shorthand `Object.entries`
382
443
  *
383
- * @param duration - The time period (in ms).
384
- * @returns The halting promise.
444
+ * @param obj - The object to extract the entries from.
445
+ * @returns The entries.
385
446
  */
386
- declare function sleep(duration: number): Promise<void>;
447
+ declare function es<T extends object>(obj: T): [keyof T, T[keyof T]][];
448
+
387
449
  /**
388
- * Generates a random string of a specified length.
450
+ * Strict-typed, shorthand `Object.keys`
389
451
  *
390
- * @param length - The length of the randomly generated string.
391
- * @returns The randomly generated string.
452
+ * @param obj - The object to extract the keys from.
453
+ * @returns The keys.
392
454
  */
393
- declare function uuid(length?: number): string;
455
+ declare function ks<T extends object>(obj: T): Array<`${keyof T & (string | number | boolean | null | undefined)}`>;
394
456
 
395
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
396
457
  /**
397
- * Recursively merges multiple objects into one.
458
+ * Shorthand `Object.values`
398
459
  *
399
- * @param objects - The objects to merge.
400
- * @returns The merged object.
460
+ * @param obj - The object to extract the values from.
461
+ * @returns The values.
401
462
  */
402
- declare function deepMerge<T extends Obj<any>[]>(...objects: T): UnionToIntersection<T[number]>;
463
+ declare function vs<T>(obj: Obj<T>): T[];
403
464
 
404
465
  /**
405
466
  * Capitalises the first letter of one word, or all words, in a string.
@@ -410,6 +471,8 @@ declare function deepMerge<T extends Obj<any>[]>(...objects: T): UnionToIntersec
410
471
  * @returns The capitalised string.
411
472
  */
412
473
  declare function capitalise(str: string, allWords?: boolean, delimiter?: string): string;
474
+ declare const capitalize: typeof capitalise;
475
+
413
476
  /**
414
477
  * Separates a string into an array of characters.
415
478
  *
@@ -417,6 +480,7 @@ declare function capitalise(str: string, allWords?: boolean, delimiter?: string)
417
480
  * @returns The string's characters.
418
481
  */
419
482
  declare function chars(str: string): string[];
483
+
420
484
  /**
421
485
  * Identifies strings which only contain whitespace.
422
486
  *
@@ -424,6 +488,7 @@ declare function chars(str: string): string[];
424
488
  * @returns If the string is blank.
425
489
  */
426
490
  declare function isBlank(str: string): boolean;
491
+
427
492
  /**
428
493
  * Identifies empty strings.
429
494
  *
@@ -431,15 +496,17 @@ declare function isBlank(str: string): boolean;
431
496
  * @returns If the string is empty.
432
497
  */
433
498
  declare function isEmpty(str: string): boolean;
499
+
434
500
  /**
435
501
  * Replaces a character at a specified index in a string with a new character.
436
502
  *
437
503
  * @param str - The string.
438
504
  * @param i - The index of the character to replace.
439
505
  * @param char - The character to replace with.
440
- * @returns - The modified string with the character replaced.
506
+ * @returns The modified string with the character replaced.
441
507
  */
442
508
  declare function replaceChar(str: string, i: number, char: string): string;
509
+
443
510
  /**
444
511
  * Splits a string into two at a specified index.
445
512
  *
@@ -447,7 +514,8 @@ declare function replaceChar(str: string, i: number, char: string): string;
447
514
  * @param i - The position to split at.
448
515
  * @returns The tuple of strings before and after the split.
449
516
  */
450
- declare function splitStrAt(str: string, i: number): [string, string];
517
+ declare function splitString(str: string, i: number): [string, string];
518
+
451
519
  /**
452
520
  * Converts a kebab case string to camel case.
453
521
  *
@@ -455,6 +523,7 @@ declare function splitStrAt(str: string, i: number): [string, string];
455
523
  * @returns The camel case string.
456
524
  */
457
525
  declare function toCamel(str: string): string;
526
+
458
527
  /**
459
528
  * Converts a camel case string to kebab case.
460
529
  *
@@ -462,13 +531,7 @@ declare function toCamel(str: string): string;
462
531
  * @returns The kebab case string.
463
532
  */
464
533
  declare function toKebab(str: string): string;
465
- /**
466
- * Converts a string which contains a number into the number itself.
467
- *
468
- * @param str - The string.
469
- * @returns The number.
470
- */
471
- declare function toNumber(str: string): number;
534
+
472
535
  /**
473
536
  * Adds the respective ordinal suffix (-st, -nd, -rd or -th) to a number.
474
537
  *
@@ -476,6 +539,16 @@ declare function toNumber(str: string): number;
476
539
  * @returns The number with the ordinal suffix appended.
477
540
  */
478
541
  declare function toOrdinal(n: number): string;
542
+
543
+ /**
544
+ * Converts a given number to Roman numerals.
545
+ *
546
+ * @param n - The number to convert to Roman numerals.
547
+ * @param lowerCase - If the numerals should be in lowercase.
548
+ * @returns The Roman numeral representation of the given number.
549
+ */
550
+ declare function toRomanNumerals(n: number, lowerCase?: boolean): string;
551
+
479
552
  /**
480
553
  * Truncates a string to a provided length.
481
554
  *
@@ -486,4 +559,12 @@ declare function toOrdinal(n: number): string;
486
559
  */
487
560
  declare function truncate(str: string, length: number, suffix?: string): string;
488
561
 
489
- export { type Arrayable, type Fn, type Nullable, type Obj, type VoidFn, capitalise, ceil, chars, clamp, clone, copyToClipboard, debounce, deepMerge, drop, floor, groupsOf, head, init, isArray, isBlank, isBoolean, isBrowser, isDefined, isEmpty, isEmptyArray, isEmptyObject, isEven, isFunction, isNull, isNumber, isObject, isObjectLike, isOdd, isString, isTouchDevice, isUndefined, isWindow, last, max, memoize, min, noop, once, partition, product, randomChance, randomNumber, range, replaceChar, round, scroll, shuffle, sleep, splitAt, splitStrAt, sum, tail, take, throttle, toArray, toCamel, toKebab, toNumber, toOrdinal, toRomanNumerals, truncate, uniq, uuid };
562
+ /**
563
+ * Joins an array of characters into a string.
564
+ *
565
+ * @param chars - The characters.
566
+ * @returns The string.
567
+ */
568
+ declare function unchars(chars: string[]): string;
569
+
570
+ export { type Arrayable, type Fn, type Nullable, type Obj, type VoidFn, capitalise, capitalize, ceil, chars, clamp, clone, copyToClipboard, debounce, drop, es, floor, groups, head, init, isArray, isBlank, isBoolean, isBrowser, isDefined, isEmpty, isEmptyArray, isEmptyObject, isEven, isFunction, isNull, isNumber, isObject, isObjectLike, isOdd, isString, isTouchDevice, isUndefined, isWindow, ks, last, max, memoise, memoize, min, noop, once, partition, product, randomChance, randomNumber, range, replaceChar, round, scroll, shuffle, sleep, splitArray, splitString, sum, tail, take, throttle, toArray, toCamel, toKebab, toNumber, toOrdinal, toRomanNumerals, truncate, unchars, uniq, uuid, vs };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function M(e,n=1){let t=e/n;return Math.ceil(t)*n}function E(e,n,t){return Math.min(t,Math.max(n,e))}function S(e,n=1){let t=e/n;return Math.floor(t)*n}function F(e){return e%2===0}function I(e){return e%2!==0}function L(...e){let n;return e.length===1&&Array.isArray(e[0])?n=e[0]:n=e,Math.max(...n)}function q(...e){let n;return e.length===1&&Array.isArray(e[0])?n=e[0]:n=e,Math.min(...n)}function R(e){let n=1;for(let t=0;t<e.length;t++)n*=e[t];return n}function V(e){return s(e)===0}function s(...e){let n,t;return e.length===1?(n=0,t=e[0]):(n=e[0],t=e[1]),Math.floor(Math.random()*(t-n))+n}function D(e,n=1){let t=e/n;return Math.round(t)*n}function B(e){let n=0;for(let t=0;t<e.length;t++)n+=e[t];return n}var h={1:"I",4:"IV",5:"V",9:"IX",10:"X",40:"XL",50:"L",90:"XC",100:"C",400:"CD",500:"D",900:"CM",1e3:"M"};function P(e,n=!1){let t=e,r="",o=Object.keys(h).map(Number).sort((i,u)=>u-i);for(let i of o)for(;t>=i;)r+=h[i],t-=i;return n?r.toLowerCase():r}function l(e){return Array.isArray(e)}function X(e){return typeof e=="boolean"}function p(){return typeof window<"u"}function H(e){return typeof e<"u"}function _(e){return l(e)&&e.length===0}function $(e){if(!a(e))return!1;for(let n in e)return!1;return!0}function z(e){return typeof e=="function"}function c(e){return Object.prototype.toString.call(e)==="[object Null]"}function w(e){return typeof e=="number"}function a(e){return Object.prototype.toString.call(e)==="[object Object]"}function f(e){return typeof e=="object"}function b(e){return typeof e=="string"}function J(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function K(e){return typeof e>"u"}function Y(e){return p()&&Object.prototype.toString.call(e)==="[object Window]"}function m(e){if(l(e)){let n=[];for(let t=0;t<e.length;t++)f(e[t])&&!c(e[t])?n[t]=m(e[t]):n[t]=e[t];return n}if(f(e)&&!c(e)){let n={};for(let t in e)f(e[t])&&!c(e[t])?n[t]=m(e[t]):n[t]=e[t];return n}return e}function ee(){}async function ne(e){return e<0&&console.warn("[tsu] warning: a sleep duration less than 0ms will be treated as 0ms."),new Promise(n=>{setTimeout(n,e)})}var v="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";function te(e=16){let n=v.length,t=e,r="";for(;t--;)r+=v[s(n)];return r}function ue(e,n){return e<=0?[...n]:n.slice(e)}function le(e,n){if(e<=0)throw new Error("[tsu] Invalid group size. Is it greater than 0?");if(e>=n.length)return[[...n]];let t=[];for(let r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}function se(e){return e[0]}function ce(e){return e.slice(0,e.length-1)}function ae(e){return e[e.length-1]}function fe(e,n){let t=[],r=[];for(let o=0;o<e.length;o++){let i=e[o];n(i,o,e)?t.push(i):r.push(i)}return[t,r]}function me(...e){let n,t,r;e.length===1?(t=e[0],n=0,r=1):(n=e[0],t=e[1],r=e[2]||1),r<=0&&(console.warn("[tsu] warning: a step less than or equal to 0 will be set to 1."),r=1);let o=[],i=n;for(;i<t;)o.push(i),i+=r||1;return o}function pe(e){let n=m(e),t,r,o;for(t=n.length;t;t-=1)r=s(t),o=n[t-1],n[t-1]=n[r],n[r]=o;return n}function be(e,n){return e<=0?[[],[...n]]:e>n.length?[[...n],[]]:[n.slice(0,e),n.slice(e)]}function de(e){return e.slice(1)}function xe(e,n){return e<=0?[]:n.slice(0,e)}function Te(e){return e?Array.isArray(e)?e:[e]:[]}function j(e){return Array.from(new Set(e))}function O(e){let n=document.createElement("textarea");n.value=e??"",n.style.position="absolute",n.style.opacity="0",document.body.appendChild(n),n.select(),document.execCommand("copy"),n.remove()}function he(e){p()&&(window.navigator&&"clipboard"in window.navigator?navigator.clipboard.writeText(e):O(e))}function we({to:e,offset:n=0,duration:t=1e3,container:r=null}){let o=b(e)?document.querySelector(e):e,i=b(r)?document.querySelector(r):r,u=i?.scrollTop||window?.pageYOffset||0,d=(w(o)?o:N(o,u))+n,k=Date.now();function x(){let T=Date.now()-k,g=T<t,y=g?C(u,d,T,t):d;g&&requestAnimationFrame(x),i?i.scrollTop=y:window.scrollTo(0,y)}x()}function A(e){return e<.5?4*Math.pow(e,3):(e-1)*(2*e-2)*(2*e-2)+1}function C(e,n,t,r){return e+(n-e)*A(t/r)}function N(e,n){return e.nodeName==="HTML"?-n:e.getBoundingClientRect().top+n}function je(e,n){n<0&&console.warn("[tsu] warning: a debounce delay less than 0ms will be treated as 0ms.");let t;return function(...r){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),e(...r)},n)}}function ke(e){let n={};return function(...t){let r=JSON.stringify(t);if(r in n)return n[r];let o=e(...t);return n[r]=o,o}}function Oe(e){let n=!1;return(...t)=>{n||(e(...t),n=!0)}}function Ae(e,n){n<0&&console.warn("[tsu] warning: a throttle limit less than 0ms will be treated as 0ms.");let t=!1;return function(...r){t||(e(...r),t=!0,setTimeout(()=>{t=!1},n))}}function U(...e){let n={};for(let t=0;t<e.length;t++){let r=e[t],o=Object.keys(r);for(let i=0;i<o.length;i++){let u=o[i];l(n[u])&&l(r[u])?n[u]=j(n[u].concat(r[u])):a(n[u])&&a(r[u])?n[u]=U(n[u],r[u]):n[u]=r[u]}}return n}function Ee(e,n=!1,t=" "){return n?e.split(t).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(t):e.charAt(0).toUpperCase()+e.slice(1)}function Se(e){return e.split("")}function Fe(e){return e.trim().length===0}function Ie(e){return e.length===0}function Le(e,n,t){return n<0||n>e.length-1?e:e.slice(0,n)+t+e.slice(n+1)}function qe(e,n){return n<=0?["",e]:n>e.length?[e,""]:[e.slice(0,n),e.slice(n)]}function Re(e){let n=/-(\w)/g;return e.replace(n,(t,r)=>r?r.toUpperCase():"")}function Ve(e){let n=/\B([A-Z])/g;return e.replace(n,"-$1").toLowerCase()}function De(e){return e.length?Number(e.replace(/[#£€$,%]/g,"")):NaN}function Be(e){let t=["st","nd","rd"][(e/10%10^1&&e%10)-1]||"th";return`${e}${t}`}function Pe(e,n,t="..."){return n<=0?t:e.slice(0,n)+t}export{Ee as capitalise,M as ceil,Se as chars,E as clamp,m as clone,he as copyToClipboard,je as debounce,U as deepMerge,ue as drop,S as floor,le as groupsOf,se as head,ce as init,l as isArray,Fe as isBlank,X as isBoolean,p as isBrowser,H as isDefined,Ie as isEmpty,_ as isEmptyArray,$ as isEmptyObject,F as isEven,z as isFunction,c as isNull,w as isNumber,a as isObject,f as isObjectLike,I as isOdd,b as isString,J as isTouchDevice,K as isUndefined,Y as isWindow,ae as last,L as max,ke as memoize,q as min,ee as noop,Oe as once,fe as partition,R as product,V as randomChance,s as randomNumber,me as range,Le as replaceChar,D as round,we as scroll,pe as shuffle,ne as sleep,be as splitAt,qe as splitStrAt,B as sum,de as tail,xe as take,Ae as throttle,Te as toArray,Re as toCamel,Ve as toKebab,De as toNumber,Be as toOrdinal,P as toRomanNumerals,Pe as truncate,j as uniq,te as uuid};
1
+ function M(e,r){return e<=0?[...r]:r.slice(e)}function S(e,r){if(r<=0)throw new Error("[tsu] Invalid group size. Is it greater than 0?");if(r>=e.length)return[[...e]];let n=[];for(let t=0;t<e.length;t+=r)n.push(e.slice(t,t+r));return n}function L(e){return e[0]}function q(e){return e.slice(0,e.length-1)}function D(e){return e[e.length-1]}function $(e,r){let n=[],t=[];for(let o=0;o<e.length;o++){let i=e[o];r(i,o,e)?n.push(i):t.push(i)}return[n,t]}function W(...e){let r,n,t;e.length===1?(n=e[0],r=0,t=1):(r=e[0],n=e[1],t=e[2]||1),t<=0&&(console.warn("[tsu] warning: a step less than or equal to 0 will be set to 1."),t=1);let o=[],i=r;for(;i<n;)o.push(i),i+=t||1;return o}function z(e,r=1){let n=e/r;return Math.ceil(n)*r}function _(e,r,n){return Math.min(n,Math.max(r,e))}function J(e,r=1){let n=e/r;return Math.floor(n)*r}function Y(e){return e%2===0}function G(e){return e%2!==0}function ee(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.max(...r)}function ne(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.min(...r)}function oe(e){let r=1;for(let n=0;n<e.length;n++)r*=e[n];return r}function u(...e){let r,n;return e.length===1?(r=0,n=e[0]):(r=e[0],n=e[1]),Math.floor(Math.random()*(n-r))+r}function me(e){return u(e)===0}function le(e,r=1){let n=e/r;return Math.round(n)*r}function ce(e){let r=0;for(let n=0;n<e.length;n++)r+=e[n];return r}function xe(e,r=[]){if(!e.length)return NaN;let n=["#","\xA3","\u20AC","$","%",",",...r],t=new RegExp(`[${n.join("")}]`,"g");return Number(e.replace(t,""))}function m(e){return Array.isArray(e)}function Fe(e){return typeof e=="boolean"}function s(){return typeof window<"u"}function Le(e){return typeof e<"u"}function Be(e){return m(e)&&e.length===0}function $e(e){if(!y(e))return!1;for(let r in e)return!1;return!0}function We(e){return typeof e=="function"}function l(e){return Object.prototype.toString.call(e)==="[object Null]"}function h(e){return typeof e=="number"}function y(e){return Object.prototype.toString.call(e)==="[object Object]"}function p(e){return typeof e=="object"}function a(e){return typeof e=="string"}function Ke(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function Ze(e){return typeof e>"u"}function er(e){return s()&&Object.prototype.toString.call(e)==="[object Window]"}function c(e){if(m(e)){let r=[];for(let n=0;n<e.length;n++)p(e[n])&&!l(e[n])?r[n]=c(e[n]):r[n]=e[n];return r}if(p(e)&&!l(e)){let r={};for(let n in e)p(e[n])&&!l(e[n])?r[n]=c(e[n]):r[n]=e[n];return r}return e}function hr(e){return Object.entries(e)}function jr(e){return Object.keys(e)}function kr(e){return Object.values(e)}function Ur(e){let r=c(e),n,t,o;for(n=r.length;n;n-=1)t=u(n),o=r[n-1],r[n-1]=r[t],r[t]=o;return r}function Rr(e,r){return r<=0?[[],[...e]]:r>e.length?[[...e],[]]:[e.slice(0,r),e.slice(r)]}function Br(e){return e.slice(1)}function Ir(e,r){return e<=0?[]:r.slice(0,e)}function Pr(e){return e?Array.isArray(e)?e:[e]:[]}function Xr(e){return Array.from(new Set(e))}function k(e){let r=document.createElement("textarea");r.value=e??"",r.style.position="absolute",r.style.opacity="0",document.body.appendChild(r),r.select(),document.execCommand("copy"),r.remove()}function fn(e){s()&&(window.navigator&&"clipboard"in window.navigator?navigator.clipboard.writeText(e):k(e))}function O(e){return e<.5?4*Math.pow(e,3):(e-1)*(2*e-2)*(2*e-2)+1}function A(e,r,n,t){return e+(r-e)*O(n/t)}function N(e,r){return e.nodeName==="HTML"?-r:e.getBoundingClientRect().top+r}function ln({to:e,offset:r=0,duration:n=1e3,container:t=null}){let o=a(e)?document.querySelector(e):e,i=a(t)?document.querySelector(t):t,f=i?.scrollTop||window?.pageYOffset||0,x=(h(o)?o:N(o,f))+r,v=Date.now();function b(){let d=Date.now()-v,T=d<n,g=T?A(f,x,d,n):x;T&&requestAnimationFrame(b),i?i.scrollTop=g:window.scrollTo(0,g)}b()}function bn(e,r){r<0&&console.warn("[tsu] warning: a debounce delay less than 0ms will be treated as 0ms.");let n;return function(...t){clearTimeout(n),n=setTimeout(()=>{clearTimeout(n),e(...t)},r)}}function C(e){let r={};return function(...n){let t=JSON.stringify(n);if(t in r)return r[t];let o=e(...n);return r[t]=o,o}}var Tn=C;function yn(e){let r=!1;return(...n)=>{r||(e(...n),r=!0)}}function wn(e,r){r<0&&console.warn("[tsu] warning: a throttle limit less than 0ms will be treated as 0ms.");let n=!1;return function(...t){n||(e(...t),n=!0,setTimeout(()=>{n=!1},r))}}function Cn(){}async function Mn(e){return e<0&&console.warn("[tsu] warning: a sleep duration less than 0ms will be treated as 0ms."),new Promise(r=>{setTimeout(r,e)})}var w="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";function Un(e=16){let r=w.length,n=e,t="";for(;n--;)t+=w[u(r)];return t}function E(e,r=!1,n=" "){return r?e.split(n).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(n):e.charAt(0).toUpperCase()+e.slice(1)}var In=E;function Pn(e){return e.split("")}function Xn(e){return e.trim().length===0}function Hn(e){return e.length===0}function Vn(e,r,n){return r<0||r>e.length-1?e:e.slice(0,r)+n+e.slice(r+1)}function Kn(e,r){return r<=0?["",e]:r>e.length?[e,""]:[e.slice(0,r),e.slice(r)]}function Zn(e){let r=/-(\w)/g;return e.replace(r,(n,t)=>t?t.toUpperCase():"")}function Qn(e){let r=/\B([A-Z])/g;return e.replace(r,"-$1").toLowerCase()}function rt(e){let n=["st","nd","rd"][(Math.abs(e)/10%10^1&&Math.abs(e)%10)-1]||"th";return`${e}${n}`}var j={1:"I",4:"IV",5:"V",9:"IX",10:"X",40:"XL",50:"L",90:"XC",100:"C",400:"CD",500:"D",900:"CM",1e3:"M"};function tt(e,r=!1){let n=e,t="",o=Object.keys(j).map(Number).sort((i,f)=>f-i);for(let i of o)for(;n>=i;)t+=j[i],n-=i;return r?t.toLowerCase():t}function it(e,r,n="..."){return r<=0?n:e.slice(0,r)+n}function ft(e){return e.join("")}export{E as capitalise,In as capitalize,z as ceil,Pn as chars,_ as clamp,c as clone,fn as copyToClipboard,bn as debounce,M as drop,hr as es,J as floor,S as groups,L as head,q as init,m as isArray,Xn as isBlank,Fe as isBoolean,s as isBrowser,Le as isDefined,Hn as isEmpty,Be as isEmptyArray,$e as isEmptyObject,Y as isEven,We as isFunction,l as isNull,h as isNumber,y as isObject,p as isObjectLike,G as isOdd,a as isString,Ke as isTouchDevice,Ze as isUndefined,er as isWindow,jr as ks,D as last,ee as max,C as memoise,Tn as memoize,ne as min,Cn as noop,yn as once,$ as partition,oe as product,me as randomChance,u as randomNumber,W as range,Vn as replaceChar,le as round,ln as scroll,Ur as shuffle,Mn as sleep,Rr as splitArray,Kn as splitString,ce as sum,Br as tail,Ir as take,wn as throttle,Pr as toArray,Zn as toCamel,Qn as toKebab,xe as toNumber,rt as toOrdinal,tt as toRomanNumerals,it as truncate,ft as unchars,Xr as uniq,Un as uuid,kr as vs};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsu",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "type": "module",
5
5
  "description": "TypeScript utilities",
6
6
  "license": "MIT",