tsu 2.10.0 → 2.10.1

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 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});
1
+ "use strict";var x=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var S=(e,r)=>{for(var t in r)x(e,t,{get:r[t],enumerable:!0})},U=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of M(r))!F.call(e,o)&&o!==t&&x(e,o,{get:()=>r[o],enumerable:!(n=E(r,o))||n.enumerable});return e};var L=e=>U(x({},"__esModule",{value:!0}),e);var We={};S(We,{average:()=>W,capitalise:()=>N,capitalize:()=>Me,ceil:()=>X,chars:()=>Fe,clamp:()=>d,clone:()=>p,copyToClipboard:()=>ge,debounce:()=>ve,drop:()=>D,es:()=>me,floor:()=>z,groups:()=>R,head:()=>q,init:()=>B,isArray:()=>f,isBlank:()=>Se,isBoolean:()=>ee,isBrowser:()=>m,isDefined:()=>re,isEmpty:()=>Ue,isEmptyArray:()=>te,isEmptyObject:()=>ne,isEven:()=>H,isFunction:()=>oe,isNull:()=>s,isNumber:()=>g,isObject:()=>T,isObjectLike:()=>l,isOdd:()=>_,isString:()=>a,isTouchDevice:()=>ie,isUndefined:()=>ue,isWindow:()=>fe,ks:()=>se,last:()=>I,max:()=>V,memoise:()=>k,memoize:()=>ke,min:()=>J,noop:()=>Ae,once:()=>Oe,partition:()=>$,product:()=>K,randomChance:()=>Y,randomNumber:()=>u,range:()=>P,replaceChar:()=>Le,round:()=>Z,scroll:()=>je,shuffle:()=>pe,sleep:()=>Ce,splitArray:()=>ce,splitString:()=>De,sum:()=>b,tail:()=>ae,take:()=>xe,throttle:()=>Ne,toArray:()=>be,toCamel:()=>Re,toDp:()=>G,toKebab:()=>qe,toNumber:()=>Q,toOrdinal:()=>Be,toRomanNumerals:()=>Ie,truncate:()=>$e,unchars:()=>Pe,uniq:()=>de,uuid:()=>Ee,vs:()=>le});module.exports=L(We);function D(e,r){return e<=0?[...r]:r.slice(e)}function R(e,r){if(r<=0)throw new Error("[tsu] Invalid group size. Is it greater than 0?");if(r>=e.length)return[[...e]];let t=[];for(let n=0;n<e.length;n+=r)t.push(e.slice(n,n+r));return t}function q(e){return e[0]}function B(e){return e.slice(0,e.length-1)}function I(e){return e[e.length-1]}function $(e,r){let t=[],n=[];for(let o=0;o<e.length;o++){let i=e[o];r(i,o,e)?t.push(i):n.push(i)}return[t,n]}function P(...e){let r,t,n;e.length===1?(t=e[0],r=0,n=1):(r=e[0],t=e[1],n=e[2]||1),n<=0&&(console.warn("[tsu] warning: a step less than or equal to 0 will be set to 1."),n=1);let o=[],i=r;for(;i<t;)o.push(i),i+=n||1;return o}function W(e){return e.length<1?0:b(e)/e.length}function X(e,r=1){let t=e/r;return Math.ceil(t)*r}function d(e,r,t){return Math.min(t,Math.max(r,e))}function z(e,r=1){let t=e/r;return Math.floor(t)*r}function H(e){return e%2===0}function _(e){return e%2!==0}function V(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.max(...r)}function J(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.min(...r)}function K(e){if(e.length<1)return 0;let r=1;for(let t=0;t<e.length;t++)r*=e[t];return r}function u(...e){let r,t;return e.length===1?(r=0,t=e[0]):(r=e[0],t=e[1]),Math.floor(Math.random()*(t-r))+r}function Y(e){return u(e)===0}function Z(e,r=1){let t=e/r;return Math.round(t)*r}function b(e){let r=0;for(let t=0;t<e.length;t++)r+=e[t];return r}function G(e,r=0){r<0&&console.warn("[tsu] warning: decimalPlaces less than 0 are set to 0."),r>100&&console.warn("[tsu] warning: decimalPlaces greater than 100 are set to 100.");let t=d(r,0,100);return Number(e.toFixed(t))}function Q(e,r=[]){if(!e.length)return NaN;let t=["#","\xA3","\u20AC","$","%",",",...r],n=new RegExp(`[${t.join("")}]`,"g");return Number(e.replace(n,""))}function f(e){return Array.isArray(e)}function ee(e){return typeof e=="boolean"}function m(){return typeof window<"u"}function re(e){return typeof e<"u"}function te(e){return f(e)&&e.length===0}function ne(e){if(!T(e))return!1;for(let r in e)return!1;return!0}function oe(e){return typeof e=="function"}function s(e){return Object.prototype.toString.call(e)==="[object Null]"}function g(e){return typeof e=="number"}function T(e){return Object.prototype.toString.call(e)==="[object Object]"}function l(e){return typeof e=="object"}function a(e){return typeof e=="string"}function ie(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function ue(e){return typeof e>"u"}function fe(e){return m()&&Object.prototype.toString.call(e)==="[object Window]"}function p(e){if(f(e)){let r=[];for(let t=0;t<e.length;t++)l(e[t])&&!s(e[t])?r[t]=p(e[t]):r[t]=e[t];return r}if(l(e)&&!s(e)){let r={};for(let t in e)l(e[t])&&!s(e[t])?r[t]=p(e[t]):r[t]=e[t];return r}return e}function me(e){return Object.entries(e)}function se(e){return Object.keys(e)}function le(e){return Object.values(e)}function pe(e){let r=p(e),t,n,o;for(t=r.length;t;t-=1)n=u(t),o=r[t-1],r[t-1]=r[n],r[n]=o;return r}function ce(e,r){return r<=0?[[],[...e]]:r>e.length?[[...e],[]]:[e.slice(0,r),e.slice(r)]}function ae(e){return e.slice(1)}function xe(e,r){return e<=0?[]:r.slice(0,e)}function be(e){return e?Array.isArray(e)?e:[e]:[]}function de(e){return Array.from(new Set(e))}function Te(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 ge(e){m()&&(window.navigator&&"clipboard"in window.navigator?navigator.clipboard.writeText(e):Te(e))}function ye(e){return e<.5?4*Math.pow(e,3):(e-1)*(2*e-2)*(2*e-2)+1}function he(e,r,t,n){return e+(r-e)*ye(t/n)}function we(e,r){return e.nodeName==="HTML"?-r:e.getBoundingClientRect().top+r}function je({to:e,offset:r=0,duration:t=1e3,container:n=null}){let o=a(e)?document.querySelector(e):e,i=a(n)?document.querySelector(n):n,c=i?.scrollTop||window?.pageYOffset||0,y=(g(o)?o:we(o,c))+r,C=Date.now();function h(){let w=Date.now()-C,j=w<t,v=j?he(c,y,w,t):y;j&&requestAnimationFrame(h),i?i.scrollTop=v:window.scrollTo(0,v)}h()}function ve(e,r){r<0&&console.warn("[tsu] warning: debounce delays less than 0 will be set to 0.");let t;return function(...n){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),e(...n)},r)}}function k(e){let r={};return function(...t){let n=JSON.stringify(t);if(n in r)return r[n];let o=e(...t);return r[n]=o,o}}var ke=k;function Oe(e){let r=!1;return(...t)=>{r||(e(...t),r=!0)}}function Ne(e,r){r<0&&console.warn("[tsu] warning: throttle limits less than 0 will be set to 0.");let t=!1;return function(...n){t||(e(...n),t=!0,setTimeout(()=>{t=!1},r))}}function Ae(){}async function Ce(e){return e<0&&console.warn("[tsu] warning: sleep durations less than 0 are set to 0."),new Promise(r=>{setTimeout(r,e)})}var O="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";function Ee(e=16){let r=O.length,t=e,n="";for(;t--;)n+=O[u(r)];return n}function N(e,r=!1,t=" "){return r?e.split(t).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(t):e.charAt(0).toUpperCase()+e.slice(1)}var Me=N;function Fe(e){return e.split("")}function Se(e){return e.trim().length===0}function Ue(e){return e.length===0}function Le(e,r,t){return r<0||r>e.length-1?e:e.slice(0,r)+t+e.slice(r+1)}function De(e,r){return r<=0?["",e]:r>e.length?[e,""]:[e.slice(0,r),e.slice(r)]}function Re(e){let r=/-(\w)/g;return e.replace(r,(t,n)=>n?n.toUpperCase():"")}function qe(e){let r=/\B([A-Z])/g;return e.replace(r,"-$1").toLowerCase()}function Be(e){let t=["st","nd","rd"][(Math.abs(e)/10%10^1&&Math.abs(e)%10)-1]||"th";return`${e}${t}`}var A={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 Ie(e,r=!1){let t=e,n="",o=Object.keys(A).map(Number).sort((i,c)=>c-i);for(let i of o)for(;t>=i;)n+=A[i],t-=i;return r?n.toLowerCase():n}function $e(e,r,t="..."){return r<=0?t:e.slice(0,r)+t}function Pe(e){return e.join("")}0&&(module.exports={average,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,toDp,toKebab,toNumber,toOrdinal,toRomanNumerals,truncate,unchars,uniq,uuid,vs});
package/dist/index.d.cts CHANGED
@@ -318,6 +318,14 @@ declare function sleep(duration: number): Promise<void>;
318
318
  */
319
319
  declare function uuid(length?: number): string;
320
320
 
321
+ /**
322
+ * Returns the average of a number array.
323
+ *
324
+ * @param ns - The number array.
325
+ * @returns The average.
326
+ */
327
+ declare function average(ns: readonly number[]): number;
328
+
321
329
  /**
322
330
  * Rounds a number up to the nearest multiple of the specified factor.
323
331
  *
@@ -421,6 +429,15 @@ declare function round(n: number, factor?: number): number;
421
429
  */
422
430
  declare function sum(ns: readonly number[]): number;
423
431
 
432
+ /**
433
+ * Rounds a number to a specified number of decimal places.
434
+ *
435
+ * @param n - The number to round.
436
+ * @param decimalPlaces - The number of decimal places to round to.
437
+ * @returns The rounded number.
438
+ */
439
+ declare function toDp(n: number, decimalPlaces?: number): number;
440
+
424
441
  /**
425
442
  * Converts a string which contains a number into the number itself.
426
443
  *
@@ -567,4 +584,4 @@ declare function truncate(str: string, length: number, suffix?: string): string;
567
584
  */
568
585
  declare function unchars(chars: string[]): string;
569
586
 
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 };
587
+ export { type Arrayable, type Fn, type Nullable, type Obj, type VoidFn, average, 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, toDp, toKebab, toNumber, toOrdinal, toRomanNumerals, truncate, unchars, uniq, uuid, vs };
package/dist/index.d.ts CHANGED
@@ -318,6 +318,14 @@ declare function sleep(duration: number): Promise<void>;
318
318
  */
319
319
  declare function uuid(length?: number): string;
320
320
 
321
+ /**
322
+ * Returns the average of a number array.
323
+ *
324
+ * @param ns - The number array.
325
+ * @returns The average.
326
+ */
327
+ declare function average(ns: readonly number[]): number;
328
+
321
329
  /**
322
330
  * Rounds a number up to the nearest multiple of the specified factor.
323
331
  *
@@ -421,6 +429,15 @@ declare function round(n: number, factor?: number): number;
421
429
  */
422
430
  declare function sum(ns: readonly number[]): number;
423
431
 
432
+ /**
433
+ * Rounds a number to a specified number of decimal places.
434
+ *
435
+ * @param n - The number to round.
436
+ * @param decimalPlaces - The number of decimal places to round to.
437
+ * @returns The rounded number.
438
+ */
439
+ declare function toDp(n: number, decimalPlaces?: number): number;
440
+
424
441
  /**
425
442
  * Converts a string which contains a number into the number itself.
426
443
  *
@@ -567,4 +584,4 @@ declare function truncate(str: string, length: number, suffix?: string): string;
567
584
  */
568
585
  declare function unchars(chars: string[]): string;
569
586
 
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 };
587
+ export { type Arrayable, type Fn, type Nullable, type Obj, type VoidFn, average, 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, toDp, toKebab, toNumber, toOrdinal, toRomanNumerals, truncate, unchars, uniq, uuid, vs };
package/dist/index.js CHANGED
@@ -1 +1 @@
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};
1
+ function S(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 t=[];for(let n=0;n<e.length;n+=r)t.push(e.slice(n,n+r));return t}function R(e){return e[0]}function B(e){return e.slice(0,e.length-1)}function $(e){return e[e.length-1]}function W(e,r){let t=[],n=[];for(let o=0;o<e.length;o++){let i=e[o];r(i,o,e)?t.push(i):n.push(i)}return[t,n]}function z(...e){let r,t,n;e.length===1?(t=e[0],r=0,n=1):(r=e[0],t=e[1],n=e[2]||1),n<=0&&(console.warn("[tsu] warning: a step less than or equal to 0 will be set to 1."),n=1);let o=[],i=r;for(;i<t;)o.push(i),i+=n||1;return o}function V(e){return e.length<1?0:y(e)/e.length}function K(e,r=1){let t=e/r;return Math.ceil(t)*r}function h(e,r,t){return Math.min(t,Math.max(r,e))}function G(e,r=1){let t=e/r;return Math.floor(t)*r}function ee(e){return e%2===0}function te(e){return e%2!==0}function oe(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.max(...r)}function ue(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.min(...r)}function me(e){if(e.length<1)return 0;let r=1;for(let t=0;t<e.length;t++)r*=e[t];return r}function u(...e){let r,t;return e.length===1?(r=0,t=e[0]):(r=e[0],t=e[1]),Math.floor(Math.random()*(t-r))+r}function ce(e){return u(e)===0}function xe(e,r=1){let t=e/r;return Math.round(t)*r}function y(e){let r=0;for(let t=0;t<e.length;t++)r+=e[t];return r}function ge(e,r=0){r<0&&console.warn("[tsu] warning: decimalPlaces less than 0 are set to 0."),r>100&&console.warn("[tsu] warning: decimalPlaces greater than 100 are set to 100.");let t=h(r,0,100);return Number(e.toFixed(t))}function he(e,r=[]){if(!e.length)return NaN;let t=["#","\xA3","\u20AC","$","%",",",...r],n=new RegExp(`[${t.join("")}]`,"g");return Number(e.replace(n,""))}function m(e){return Array.isArray(e)}function Ie(e){return typeof e=="boolean"}function s(){return typeof window<"u"}function We(e){return typeof e<"u"}function He(e){return m(e)&&e.length===0}function Je(e){if(!w(e))return!1;for(let r in e)return!1;return!0}function Ye(e){return typeof e=="function"}function l(e){return Object.prototype.toString.call(e)==="[object Null]"}function j(e){return typeof e=="number"}function w(e){return Object.prototype.toString.call(e)==="[object Object]"}function p(e){return typeof e=="object"}function a(e){return typeof e=="string"}function nr(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function ir(e){return typeof e>"u"}function mr(e){return s()&&Object.prototype.toString.call(e)==="[object Window]"}function c(e){if(m(e)){let r=[];for(let t=0;t<e.length;t++)p(e[t])&&!l(e[t])?r[t]=c(e[t]):r[t]=e[t];return r}if(p(e)&&!l(e)){let r={};for(let t in e)p(e[t])&&!l(e[t])?r[t]=c(e[t]):r[t]=e[t];return r}return e}function Cr(e){return Object.entries(e)}function Mr(e){return Object.keys(e)}function Sr(e){return Object.values(e)}function Pr(e){let r=c(e),t,n,o;for(t=r.length;t;t-=1)n=u(t),o=r[t-1],r[t-1]=r[n],r[n]=o;return r}function Xr(e,r){return r<=0?[[],[...e]]:r>e.length?[[...e],[]]:[e.slice(0,r),e.slice(r)]}function Hr(e){return e.slice(1)}function Vr(e,r){return e<=0?[]:r.slice(0,e)}function Kr(e){return e?Array.isArray(e)?e:[e]:[]}function Zr(e){return Array.from(new Set(e))}function N(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 xt(e){s()&&(window.navigator&&"clipboard"in window.navigator?navigator.clipboard.writeText(e):N(e))}function A(e){return e<.5?4*Math.pow(e,3):(e-1)*(2*e-2)*(2*e-2)+1}function C(e,r,t,n){return e+(r-e)*A(t/n)}function E(e,r){return e.nodeName==="HTML"?-r:e.getBoundingClientRect().top+r}function Tt({to:e,offset:r=0,duration:t=1e3,container:n=null}){let o=a(e)?document.querySelector(e):e,i=a(n)?document.querySelector(n):n,f=i?.scrollTop||window?.pageYOffset||0,x=(j(o)?o:E(o,f))+r,O=Date.now();function b(){let d=Date.now()-O,T=d<t,g=T?C(f,x,d,t):x;T&&requestAnimationFrame(b),i?i.scrollTop=g:window.scrollTo(0,g)}b()}function jt(e,r){r<0&&console.warn("[tsu] warning: debounce delays less than 0 will be set to 0.");let t;return function(...n){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),e(...n)},r)}}function M(e){let r={};return function(...t){let n=JSON.stringify(t);if(n in r)return r[n];let o=e(...t);return r[n]=o,o}}var kt=M;function Nt(e){let r=!1;return(...t)=>{r||(e(...t),r=!0)}}function Ct(e,r){r<0&&console.warn("[tsu] warning: throttle limits less than 0 will be set to 0.");let t=!1;return function(...n){t||(e(...n),t=!0,setTimeout(()=>{t=!1},r))}}function Dt(){}async function qt(e){return e<0&&console.warn("[tsu] warning: sleep durations less than 0 are set to 0."),new Promise(r=>{setTimeout(r,e)})}var v="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";function $t(e=16){let r=v.length,t=e,n="";for(;t--;)n+=v[u(r)];return n}function F(e,r=!1,t=" "){return r?e.split(t).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(t):e.charAt(0).toUpperCase()+e.slice(1)}var _t=F;function Jt(e){return e.split("")}function Yt(e){return e.trim().length===0}function Gt(e){return e.length===0}function en(e,r,t){return r<0||r>e.length-1?e:e.slice(0,r)+t+e.slice(r+1)}function tn(e,r){return r<=0?["",e]:r>e.length?[e,""]:[e.slice(0,r),e.slice(r)]}function on(e){let r=/-(\w)/g;return e.replace(r,(t,n)=>n?n.toUpperCase():"")}function fn(e){let r=/\B([A-Z])/g;return e.replace(r,"-$1").toLowerCase()}function sn(e){let t=["st","nd","rd"][(Math.abs(e)/10%10^1&&Math.abs(e)%10)-1]||"th";return`${e}${t}`}var k={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 pn(e,r=!1){let t=e,n="",o=Object.keys(k).map(Number).sort((i,f)=>f-i);for(let i of o)for(;t>=i;)n+=k[i],t-=i;return r?n.toLowerCase():n}function an(e,r,t="..."){return r<=0?t:e.slice(0,r)+t}function bn(e){return e.join("")}export{V as average,F as capitalise,_t as capitalize,K as ceil,Jt as chars,h as clamp,c as clone,xt as copyToClipboard,jt as debounce,S as drop,Cr as es,G as floor,L as groups,R as head,B as init,m as isArray,Yt as isBlank,Ie as isBoolean,s as isBrowser,We as isDefined,Gt as isEmpty,He as isEmptyArray,Je as isEmptyObject,ee as isEven,Ye as isFunction,l as isNull,j as isNumber,w as isObject,p as isObjectLike,te as isOdd,a as isString,nr as isTouchDevice,ir as isUndefined,mr as isWindow,Mr as ks,$ as last,oe as max,M as memoise,kt as memoize,ue as min,Dt as noop,Nt as once,W as partition,me as product,ce as randomChance,u as randomNumber,z as range,en as replaceChar,xe as round,Tt as scroll,Pr as shuffle,qt as sleep,Xr as splitArray,tn as splitString,y as sum,Hr as tail,Vr as take,Ct as throttle,Kr as toArray,on as toCamel,ge as toDp,fn as toKebab,he as toNumber,sn as toOrdinal,pn as toRomanNumerals,an as truncate,bn as unchars,Zr as uniq,$t as uuid,Sr as vs};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsu",
3
- "version": "2.10.0",
3
+ "version": "2.10.1",
4
4
  "type": "module",
5
5
  "description": "TypeScript utilities",
6
6
  "license": "MIT",