tsu 2.8.0 → 2.9.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/README.md CHANGED
@@ -1,13 +1,27 @@
1
- # tsu
2
-
3
- > TypeScript utilities
4
-
5
- <a href="https://npmjs.com/package/tsu">
6
- <img src="https://img.shields.io/npm/v/tsu" alt="npm version">
1
+ <div align="center">
2
+ <a href="https://gitlab.com/happytiptoe/tsu">
3
+ <img src="https://gitlab.com/happytiptoe/tsu/-/raw/main/assets/logo.png" alt="tsu - opinionated project scaffolder" width="251">
4
+ <br>
5
+ </a>
6
+ <h1>tsu</h1>
7
+ <h3>✨ TypeScript Utilities ✨</h3>
8
+ </div>
9
+
10
+ <div align="center">
11
+ <a href="https://www.npmjs.com/package/tsu" target="__blank">
12
+ <img src="https://img.shields.io/npm/v/tsu?color=3eaa47&label=" alt="NPM version">
13
+ </a>
14
+ <a href="https://tsu.pages.dev" target="__blank">
15
+ <img src="https://img.shields.io/static/v1?label=&message=View%20documentation&color=3eaa47" alt="view documentation">
16
+ </a>
17
+ <br>
18
+ <a href="https://gitlab.com/happytiptoe/tsu" target="__blank">
19
+ <img src="https://img.shields.io/gitlab/stars/happytiptoe/tsu?style=flat&color=131514" alt="gitlab stars">
7
20
  </a>
8
21
  <a href="https://npmjs.com/package/tsu">
9
- <img src="https://img.shields.io/npm/l/tsu" alt="license">
22
+ <img src="https://img.shields.io/npm/l/tsu?color=131514" alt="license">
10
23
  </a>
24
+ </div>
11
25
 
12
26
  ## Installation
13
27
 
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var b=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var F=(n,e)=>{for(var t in e)b(n,t,{get:e[t],enumerable:!0})},M=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of N(e))!U.call(n,o)&&o!==t&&b(n,o,{get:()=>e[o],enumerable:!(r=A(e,o))||r.enumerable});return n};var S=n=>M(b({},"__esModule",{value:!0}),n);var Fn={};F(Fn,{capitalise:()=>yn,ceil:()=>E,chars:()=>hn,clamp:()=>C,clone:()=>m,debounce:()=>dn,deepMerge:()=>v,drop:()=>Q,floor:()=>q,groupsOf:()=>X,head:()=>nn,init:()=>en,isArray:()=>s,isBlank:()=>wn,isBoolean:()=>H,isBrowser:()=>j,isDefined:()=>_,isEmpty:()=>jn,isEmptyObject:()=>$,isEven:()=>I,isFunction:()=>z,isNull:()=>c,isNumber:()=>d,isObject:()=>f,isObjectLike:()=>a,isOdd:()=>V,isString:()=>p,isTouchDevice:()=>J,isWindow:()=>K,last:()=>tn,max:()=>L,memoize:()=>xn,min:()=>R,noop:()=>Y,once:()=>Tn,partition:()=>rn,product:()=>B,randomChance:()=>D,randomNumber:()=>l,range:()=>on,round:()=>P,scroll:()=>an,shuffle:()=>un,sleep:()=>Z,splitAt:()=>ln,splitStrAt:()=>On,sum:()=>W,tail:()=>sn,take:()=>cn,throttle:()=>gn,toArray:()=>fn,toCamel:()=>vn,toKebab:()=>kn,toNumber:()=>An,toOrdinal:()=>Nn,truncate:()=>Un,uniq:()=>x,uuid:()=>G});module.exports=S(Fn);function E(n,e=1){let t=n/e;return Math.ceil(t)*e}function C(n,e,t){return Math.min(t,Math.max(e,n))}function q(n,e=1){let t=n/e;return Math.floor(t)*e}function I(n){return n%2===0}function V(n){return n%2!==0}function L(...n){let e;return n.length===1&&Array.isArray(n[0])?e=n[0]:e=n,Math.max(...e)}function R(...n){let e;return n.length===1&&Array.isArray(n[0])?e=n[0]:e=n,Math.min(...e)}function B(n){let e=1;for(let t=0;t<n.length;t++)e*=n[t];return e}function D(n){return l(n)===0}function l(...n){let e,t;return n.length===1?(e=0,t=n[0]):(e=n[0],t=n[1]),Math.floor(Math.random()*(t-e))+e}function P(n,e=1){let t=n/e;return Math.round(t)*e}function W(n){let e=0;for(let t=0;t<n.length;t++)e+=n[t];return e}function s(n){return Array.isArray(n)}function H(n){return typeof n=="boolean"}function j(){return typeof window<"u"}function _(n){return typeof n<"u"}function $(n){if(!f(n))return!1;for(let e in n)return!1;return!0}function z(n){return typeof n=="function"}function c(n){return Object.prototype.toString.call(n)==="[object Null]"}function d(n){return typeof n=="number"}function f(n){return Object.prototype.toString.call(n)==="[object Object]"}function a(n){return typeof n=="object"}function p(n){return typeof n=="string"}function J(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function K(n){return j()&&Object.prototype.toString.call(n)==="[object Window]"}function m(n){if(s(n)){let e=[];for(let t=0;t<n.length;t++)a(n[t])&&!c(n[t])?e[t]=m(n[t]):e[t]=n[t];return e}if(a(n)&&!c(n)){let e={};for(let t in n)a(n[t])&&!c(n[t])?e[t]=m(n[t]):e[t]=n[t];return e}return n}function Y(){}async function Z(n){return n<0&&console.warn("[tsu] warning: a sleep duration less than 0ms will be treated as 0ms."),new Promise(e=>{setTimeout(e,n)})}var O="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";function G(n=16){let e=O.length,t=n,r="";for(;t--;)r+=O[l(e)];return r}function Q(n,e){return n<=0?[...e]:e.slice(n)}function X(n,e){if(n<=0)throw new Error("[tsu] Invalid group size. Is it greater than 0?");if(n>=e.length)return[[...e]];let t=[];for(let r=0;r<e.length;r+=n)t.push(e.slice(r,r+n));return t}function nn(n){return n[0]}function en(n){return n.slice(0,n.length-1)}function tn(n){return n[n.length-1]}function rn(n,e){let t=[],r=[];for(let o=0;o<n.length;o++){let i=n[o];e(i,o,n)?t.push(i):r.push(i)}return[t,r]}function on(...n){let e,t,r;n.length===1?(t=n[0],e=0,r=1):(e=n[0],t=n[1],r=n[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=e;for(;i<t;)o.push(i),i+=r||1;return o}function un(n){let e=m(n),t,r,o;for(t=e.length;t;t-=1)r=l(t),o=e[t-1],e[t-1]=e[r],e[r]=o;return e}function ln(n,e){return n<=0?[[],[...e]]:n>e.length?[[...e],[]]:[e.slice(0,n),e.slice(n)]}function sn(n){return n.slice(1)}function cn(n,e){return n<=0?[]:e.slice(0,n)}function fn(n){return n?Array.isArray(n)?n:[n]:[]}function x(n){return Array.from(new Set(n))}function an({to:n,offset:e=0,duration:t=1e3,container:r=null}){let o=p(n)?document.querySelector(n):n,i=p(r)?document.querySelector(r):r,u=i?.scrollTop||window?.pageYOffset||0,T=(d(o)?o:bn(o,u))+e,k=Date.now();function g(){let y=Date.now()-k,h=y<t,w=h?pn(u,T,y,t):T;h&&requestAnimationFrame(g),i?i.scrollTop=w:window.scrollTo(0,w)}g()}function mn(n){return n<.5?4*Math.pow(n,3):(n-1)*(2*n-2)*(2*n-2)+1}function pn(n,e,t,r){return n+(e-n)*mn(t/r)}function bn(n,e){return n.nodeName==="HTML"?-e:n.getBoundingClientRect().top+e}function dn(n,e){e<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),n(...r)},e)}}function xn(n){let e={};return function(...t){let r=JSON.stringify(t);if(r in e)return e[r];let o=n(...t);return e[r]=o,o}}function Tn(n){let e=!1;return(...t)=>{e||(n(...t),e=!0)}}function gn(n,e){e<0&&console.warn("[tsu] warning: a throttle limit less than 0ms will be treated as 0ms.");let t=!1;return function(...r){t||(n(...r),t=!0,setTimeout(()=>{t=!1},e))}}function v(...n){let e={};for(let t=0;t<n.length;t++){let r=n[t],o=Object.keys(r);for(let i=0;i<o.length;i++){let u=o[i];s(e[u])&&s(r[u])?e[u]=x(e[u].concat(r[u])):f(e[u])&&f(r[u])?e[u]=v(e[u],r[u]):e[u]=r[u]}}return e}function yn(n,e=!1,t=" "){return e?n.split(t).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(t):n.charAt(0).toUpperCase()+n.slice(1)}function hn(n){return n.split("")}function wn(n){return n.trim().length===0}function jn(n){return n.length===0}function On(n,e){return n<=0?["",e]:n>e.length?[e,""]:[e.slice(0,n),e.slice(n)]}function vn(n){let e=/-(\w)/g;return n.replace(e,(t,r)=>r?r.toUpperCase():"")}function kn(n){let e=/\B([A-Z])/g;return n.replace(e,"-$1").toLowerCase()}function An(n){return n.length?Number(n.replace(/[#£€$,%]/g,"")):NaN}function Nn(n){let t=["st","nd","rd"][(n/10%10^1&&n%10)-1]||"th";return`${n}${t}`}function Un(n,e,t="..."){return e<=0?t:n.slice(0,e)+t}0&&(module.exports={capitalise,ceil,chars,clamp,clone,debounce,deepMerge,drop,floor,groupsOf,head,init,isArray,isBlank,isBoolean,isBrowser,isDefined,isEmpty,isEmptyObject,isEven,isFunction,isNull,isNumber,isObject,isObjectLike,isOdd,isString,isTouchDevice,isWindow,last,max,memoize,min,noop,once,partition,product,randomChance,randomNumber,range,round,scroll,shuffle,sleep,splitAt,splitStrAt,sum,tail,take,throttle,toArray,toCamel,toKebab,toNumber,toOrdinal,truncate,uniq,uuid});
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});
package/dist/index.d.cts CHANGED
@@ -106,6 +106,12 @@ declare function toArray<T>(maybeArray: Nullable<Arrayable<T>>): T[];
106
106
  */
107
107
  declare function uniq<T>(array: readonly T[]): T[];
108
108
 
109
+ /**
110
+ * Copies the provided string to the user's clipboard.
111
+ *
112
+ * @param str - The string to be copied to the clipboard.
113
+ */
114
+ declare function copyToClipboard(str: string): void;
109
115
  interface ScrollConfig {
110
116
  to: Element | string | number;
111
117
  offset?: number;
@@ -180,7 +186,14 @@ declare function isBrowser(): boolean;
180
186
  * @param val - The value.
181
187
  * @returns If the value is defined.
182
188
  */
183
- declare function isDefined<T = unknown>(val?: T): val is T;
189
+ declare function isDefined<T>(val: T): val is T;
190
+ /**
191
+ * Identifies if a value is an empty array.
192
+ *
193
+ * @param val - The value.
194
+ * @returns If the value is an empty array.
195
+ */
196
+ declare function isEmptyArray(val: unknown): val is [];
184
197
  /**
185
198
  * Identifies if a value is an empty object.
186
199
  *
@@ -236,6 +249,13 @@ declare function isString(val: unknown): val is string;
236
249
  * @returns If the code is being run on a touch device.
237
250
  */
238
251
  declare function isTouchDevice(): boolean;
252
+ /**
253
+ * Identifies if a value is undefined.
254
+ *
255
+ * @param val - The value.
256
+ * @returns If the value is undefined.
257
+ */
258
+ declare function isUndefined(val: unknown): val is undefined;
239
259
  /**
240
260
  * Identifies if a value is the global window.
241
261
  *
@@ -335,6 +355,14 @@ declare function round(n: number, factor?: number): number;
335
355
  * @returns The sum.
336
356
  */
337
357
  declare function sum(ns: readonly number[]): number;
358
+ /**
359
+ * Converts a given number to Roman numerals.
360
+ *
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.
364
+ */
365
+ declare function toRomanNumerals(n: number, lowerCase?: boolean): string;
338
366
 
339
367
  /**
340
368
  * Deep clones an array or object.
@@ -403,14 +431,23 @@ declare function isBlank(str: string): boolean;
403
431
  * @returns If the string is empty.
404
432
  */
405
433
  declare function isEmpty(str: string): boolean;
434
+ /**
435
+ * Replaces a character at a specified index in a string with a new character.
436
+ *
437
+ * @param str - The string.
438
+ * @param i - The index of the character to replace.
439
+ * @param char - The character to replace with.
440
+ * @returns - The modified string with the character replaced.
441
+ */
442
+ declare function replaceChar(str: string, i: number, char: string): string;
406
443
  /**
407
444
  * Splits a string into two at a specified index.
408
445
  *
409
- * @param i - The position to split at.
410
446
  * @param str - The string.
447
+ * @param i - The position to split at.
411
448
  * @returns The tuple of strings before and after the split.
412
449
  */
413
- declare function splitStrAt(i: number, str: string): [string, string];
450
+ declare function splitStrAt(str: string, i: number): [string, string];
414
451
  /**
415
452
  * Converts a kebab case string to camel case.
416
453
  *
@@ -449,4 +486,4 @@ declare function toOrdinal(n: number): string;
449
486
  */
450
487
  declare function truncate(str: string, length: number, suffix?: string): string;
451
488
 
452
- export { type Arrayable, type Fn, type Nullable, type Obj, type VoidFn, capitalise, ceil, chars, clamp, clone, debounce, deepMerge, drop, floor, groupsOf, head, init, isArray, isBlank, isBoolean, isBrowser, isDefined, isEmpty, isEmptyObject, isEven, isFunction, isNull, isNumber, isObject, isObjectLike, isOdd, isString, isTouchDevice, isWindow, last, max, memoize, min, noop, once, partition, product, randomChance, randomNumber, range, round, scroll, shuffle, sleep, splitAt, splitStrAt, sum, tail, take, throttle, toArray, toCamel, toKebab, toNumber, toOrdinal, truncate, uniq, uuid };
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 };
package/dist/index.d.ts CHANGED
@@ -106,6 +106,12 @@ declare function toArray<T>(maybeArray: Nullable<Arrayable<T>>): T[];
106
106
  */
107
107
  declare function uniq<T>(array: readonly T[]): T[];
108
108
 
109
+ /**
110
+ * Copies the provided string to the user's clipboard.
111
+ *
112
+ * @param str - The string to be copied to the clipboard.
113
+ */
114
+ declare function copyToClipboard(str: string): void;
109
115
  interface ScrollConfig {
110
116
  to: Element | string | number;
111
117
  offset?: number;
@@ -180,7 +186,14 @@ declare function isBrowser(): boolean;
180
186
  * @param val - The value.
181
187
  * @returns If the value is defined.
182
188
  */
183
- declare function isDefined<T = unknown>(val?: T): val is T;
189
+ declare function isDefined<T>(val: T): val is T;
190
+ /**
191
+ * Identifies if a value is an empty array.
192
+ *
193
+ * @param val - The value.
194
+ * @returns If the value is an empty array.
195
+ */
196
+ declare function isEmptyArray(val: unknown): val is [];
184
197
  /**
185
198
  * Identifies if a value is an empty object.
186
199
  *
@@ -236,6 +249,13 @@ declare function isString(val: unknown): val is string;
236
249
  * @returns If the code is being run on a touch device.
237
250
  */
238
251
  declare function isTouchDevice(): boolean;
252
+ /**
253
+ * Identifies if a value is undefined.
254
+ *
255
+ * @param val - The value.
256
+ * @returns If the value is undefined.
257
+ */
258
+ declare function isUndefined(val: unknown): val is undefined;
239
259
  /**
240
260
  * Identifies if a value is the global window.
241
261
  *
@@ -335,6 +355,14 @@ declare function round(n: number, factor?: number): number;
335
355
  * @returns The sum.
336
356
  */
337
357
  declare function sum(ns: readonly number[]): number;
358
+ /**
359
+ * Converts a given number to Roman numerals.
360
+ *
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.
364
+ */
365
+ declare function toRomanNumerals(n: number, lowerCase?: boolean): string;
338
366
 
339
367
  /**
340
368
  * Deep clones an array or object.
@@ -403,14 +431,23 @@ declare function isBlank(str: string): boolean;
403
431
  * @returns If the string is empty.
404
432
  */
405
433
  declare function isEmpty(str: string): boolean;
434
+ /**
435
+ * Replaces a character at a specified index in a string with a new character.
436
+ *
437
+ * @param str - The string.
438
+ * @param i - The index of the character to replace.
439
+ * @param char - The character to replace with.
440
+ * @returns - The modified string with the character replaced.
441
+ */
442
+ declare function replaceChar(str: string, i: number, char: string): string;
406
443
  /**
407
444
  * Splits a string into two at a specified index.
408
445
  *
409
- * @param i - The position to split at.
410
446
  * @param str - The string.
447
+ * @param i - The position to split at.
411
448
  * @returns The tuple of strings before and after the split.
412
449
  */
413
- declare function splitStrAt(i: number, str: string): [string, string];
450
+ declare function splitStrAt(str: string, i: number): [string, string];
414
451
  /**
415
452
  * Converts a kebab case string to camel case.
416
453
  *
@@ -449,4 +486,4 @@ declare function toOrdinal(n: number): string;
449
486
  */
450
487
  declare function truncate(str: string, length: number, suffix?: string): string;
451
488
 
452
- export { type Arrayable, type Fn, type Nullable, type Obj, type VoidFn, capitalise, ceil, chars, clamp, clone, debounce, deepMerge, drop, floor, groupsOf, head, init, isArray, isBlank, isBoolean, isBrowser, isDefined, isEmpty, isEmptyObject, isEven, isFunction, isNull, isNumber, isObject, isObjectLike, isOdd, isString, isTouchDevice, isWindow, last, max, memoize, min, noop, once, partition, product, randomChance, randomNumber, range, round, scroll, shuffle, sleep, splitAt, splitStrAt, sum, tail, take, throttle, toArray, toCamel, toKebab, toNumber, toOrdinal, truncate, uniq, uuid };
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 };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function U(n,e=1){let t=n/e;return Math.ceil(t)*e}function F(n,e,t){return Math.min(t,Math.max(e,n))}function M(n,e=1){let t=n/e;return Math.floor(t)*e}function S(n){return n%2===0}function E(n){return n%2!==0}function C(...n){let e;return n.length===1&&Array.isArray(n[0])?e=n[0]:e=n,Math.max(...e)}function q(...n){let e;return n.length===1&&Array.isArray(n[0])?e=n[0]:e=n,Math.min(...e)}function I(n){let e=1;for(let t=0;t<n.length;t++)e*=n[t];return e}function V(n){return l(n)===0}function l(...n){let e,t;return n.length===1?(e=0,t=n[0]):(e=n[0],t=n[1]),Math.floor(Math.random()*(t-e))+e}function L(n,e=1){let t=n/e;return Math.round(t)*e}function R(n){let e=0;for(let t=0;t<n.length;t++)e+=n[t];return e}function s(n){return Array.isArray(n)}function D(n){return typeof n=="boolean"}function O(){return typeof window<"u"}function P(n){return typeof n<"u"}function W(n){if(!f(n))return!1;for(let e in n)return!1;return!0}function H(n){return typeof n=="function"}function c(n){return Object.prototype.toString.call(n)==="[object Null]"}function y(n){return typeof n=="number"}function f(n){return Object.prototype.toString.call(n)==="[object Object]"}function a(n){return typeof n=="object"}function p(n){return typeof n=="string"}function _(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function $(n){return O()&&Object.prototype.toString.call(n)==="[object Window]"}function m(n){if(s(n)){let e=[];for(let t=0;t<n.length;t++)a(n[t])&&!c(n[t])?e[t]=m(n[t]):e[t]=n[t];return e}if(a(n)&&!c(n)){let e={};for(let t in n)a(n[t])&&!c(n[t])?e[t]=m(n[t]):e[t]=n[t];return e}return n}function Y(){}async function Z(n){return n<0&&console.warn("[tsu] warning: a sleep duration less than 0ms will be treated as 0ms."),new Promise(e=>{setTimeout(e,n)})}var h="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";function G(n=16){let e=h.length,t=n,r="";for(;t--;)r+=h[l(e)];return r}function en(n,e){return n<=0?[...e]:e.slice(n)}function tn(n,e){if(n<=0)throw new Error("[tsu] Invalid group size. Is it greater than 0?");if(n>=e.length)return[[...e]];let t=[];for(let r=0;r<e.length;r+=n)t.push(e.slice(r,r+n));return t}function rn(n){return n[0]}function on(n){return n.slice(0,n.length-1)}function un(n){return n[n.length-1]}function ln(n,e){let t=[],r=[];for(let o=0;o<n.length;o++){let i=n[o];e(i,o,n)?t.push(i):r.push(i)}return[t,r]}function sn(...n){let e,t,r;n.length===1?(t=n[0],e=0,r=1):(e=n[0],t=n[1],r=n[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=e;for(;i<t;)o.push(i),i+=r||1;return o}function cn(n){let e=m(n),t,r,o;for(t=e.length;t;t-=1)r=l(t),o=e[t-1],e[t-1]=e[r],e[r]=o;return e}function fn(n,e){return n<=0?[[],[...e]]:n>e.length?[[...e],[]]:[e.slice(0,n),e.slice(n)]}function an(n){return n.slice(1)}function mn(n,e){return n<=0?[]:e.slice(0,n)}function pn(n){return n?Array.isArray(n)?n:[n]:[]}function w(n){return Array.from(new Set(n))}function xn({to:n,offset:e=0,duration:t=1e3,container:r=null}){let o=p(n)?document.querySelector(n):n,i=p(r)?document.querySelector(r):r,u=i?.scrollTop||window?.pageYOffset||0,b=(y(o)?o:A(o,u))+e,j=Date.now();function d(){let x=Date.now()-j,T=x<t,g=T?k(u,b,x,t):b;T&&requestAnimationFrame(d),i?i.scrollTop=g:window.scrollTo(0,g)}d()}function v(n){return n<.5?4*Math.pow(n,3):(n-1)*(2*n-2)*(2*n-2)+1}function k(n,e,t,r){return n+(e-n)*v(t/r)}function A(n,e){return n.nodeName==="HTML"?-e:n.getBoundingClientRect().top+e}function gn(n,e){e<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),n(...r)},e)}}function yn(n){let e={};return function(...t){let r=JSON.stringify(t);if(r in e)return e[r];let o=n(...t);return e[r]=o,o}}function hn(n){let e=!1;return(...t)=>{e||(n(...t),e=!0)}}function wn(n,e){e<0&&console.warn("[tsu] warning: a throttle limit less than 0ms will be treated as 0ms.");let t=!1;return function(...r){t||(n(...r),t=!0,setTimeout(()=>{t=!1},e))}}function N(...n){let e={};for(let t=0;t<n.length;t++){let r=n[t],o=Object.keys(r);for(let i=0;i<o.length;i++){let u=o[i];s(e[u])&&s(r[u])?e[u]=w(e[u].concat(r[u])):f(e[u])&&f(r[u])?e[u]=N(e[u],r[u]):e[u]=r[u]}}return e}function An(n,e=!1,t=" "){return e?n.split(t).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(t):n.charAt(0).toUpperCase()+n.slice(1)}function Nn(n){return n.split("")}function Un(n){return n.trim().length===0}function Fn(n){return n.length===0}function Mn(n,e){return n<=0?["",e]:n>e.length?[e,""]:[e.slice(0,n),e.slice(n)]}function Sn(n){let e=/-(\w)/g;return n.replace(e,(t,r)=>r?r.toUpperCase():"")}function En(n){let e=/\B([A-Z])/g;return n.replace(e,"-$1").toLowerCase()}function Cn(n){return n.length?Number(n.replace(/[#£€$,%]/g,"")):NaN}function qn(n){let t=["st","nd","rd"][(n/10%10^1&&n%10)-1]||"th";return`${n}${t}`}function In(n,e,t="..."){return e<=0?t:n.slice(0,e)+t}export{An as capitalise,U as ceil,Nn as chars,F as clamp,m as clone,gn as debounce,N as deepMerge,en as drop,M as floor,tn as groupsOf,rn as head,on as init,s as isArray,Un as isBlank,D as isBoolean,O as isBrowser,P as isDefined,Fn as isEmpty,W as isEmptyObject,S as isEven,H as isFunction,c as isNull,y as isNumber,f as isObject,a as isObjectLike,E as isOdd,p as isString,_ as isTouchDevice,$ as isWindow,un as last,C as max,yn as memoize,q as min,Y as noop,hn as once,ln as partition,I as product,V as randomChance,l as randomNumber,sn as range,L as round,xn as scroll,cn as shuffle,Z as sleep,fn as splitAt,Mn as splitStrAt,R as sum,an as tail,mn as take,wn as throttle,pn as toArray,Sn as toCamel,En as toKebab,Cn as toNumber,qn as toOrdinal,In as truncate,w as uniq,G as uuid};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsu",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "type": "module",
5
5
  "description": "TypeScript utilities",
6
6
  "license": "MIT",