tsu 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright © 2021-Present HappyTiptoe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,58 @@
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">
20
+ </a>
21
+ <a href="https://npmjs.com/package/tsu">
22
+ <img src="https://img.shields.io/npm/l/tsu?color=131514" alt="license">
23
+ </a>
24
+ </div>
25
+
26
+ ## Installation
27
+
28
+ Install with your favourite package manager:
29
+
30
+ ```sh
31
+ # yarn
32
+ yarn add tsu
33
+
34
+ # pnpm
35
+ pnpm add tsu
36
+
37
+ # npm
38
+ npm install tsu
39
+ ```
40
+
41
+ Import as required:
42
+
43
+ ```js
44
+ import { ... } from 'tsu'
45
+ ```
46
+
47
+ ## Documentation
48
+
49
+ Full documentation is available [here](https://tsu.pages.dev/).
50
+
51
+ ## Credits
52
+
53
+ - [antfu](https://github.com/antfu) - For the inspiration to make a utils library.
54
+ - [yuanqing](https://github.com/yuanqing) - For the package name.
55
+
56
+ ## License
57
+
58
+ [MIT](http://opensource.org/licenses/MIT)
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var d=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var B=(e,r)=>{for(var n in r)d(e,n,{get:r[n],enumerable:!0})},D=(e,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of R(r))!L.call(e,t)&&t!==n&&d(e,t,{get:()=>r[t],enumerable:!(o=U(r,t))||o.enumerable});return e};var q=e=>D(d({},"__esModule",{value:!0}),e);var _e={};B(_e,{average:()=>G,capitalise:()=>A,capitalize:()=>Le,ceil:()=>ee,chars:()=>Be,clamp:()=>c,clone:()=>a,copyToClipboard:()=>ve,debounce:()=>Oe,drop:()=>H,es:()=>ce,floor:()=>re,groups:()=>I,head:()=>P,init:()=>W,isArray:()=>m,isBlank:()=>De,isBoolean:()=>z,isBrowser:()=>l,isDefined:()=>_,isEmpty:()=>qe,isEmptyArray:()=>V,isEmptyObject:()=>J,isEven:()=>ne,isFunction:()=>g,isNull:()=>s,isNumber:()=>y,isObject:()=>T,isObjectLike:()=>p,isOdd:()=>oe,isString:()=>b,isTouchDevice:()=>Y,isUndefined:()=>Z,isWindow:()=>f,ks:()=>ae,last:()=>$,max:()=>te,memoise:()=>C,memoize:()=>Ae,min:()=>ie,noop:()=>Se,omit:()=>pe,once:()=>Ne,partition:()=>K,product:()=>ue,randomChance:()=>fe,randomNumber:()=>u,range:()=>X,remove:()=>Q,repeat:()=>Me,replaceChar:()=>He,round:()=>me,scroll:()=>Ce,shuffle:()=>be,sleep:()=>Ue,splitArray:()=>de,splitString:()=>Ie,sum:()=>h,tail:()=>Te,take:()=>ge,throttle:()=>Fe,toArray:()=>ye,toCamel:()=>Pe,toDp:()=>le,toKebab:()=>We,toNumber:()=>se,toOrdinal:()=>$e,toRomanNumerals:()=>Ke,truncate:()=>Xe,unchars:()=>ze,uniq:()=>he,uuid:()=>Re,vs:()=>xe});module.exports=q(_e);function H(e,r){return r<=0?[...e]:e.slice(r)}function I(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 o=0;o<e.length;o+=r)n.push(e.slice(o,o+r));return n}function P(e){return e[0]}function W(e){return e.slice(0,e.length-1)}function $(e){return e[e.length-1]}function K(e,r){let n=[],o=[];for(let t=0;t<e.length;t++){let i=e[t];r(i,t,e)?n.push(i):o.push(i)}return[n,o]}function X(...e){let r,n,o;e.length===1?(n=e[0],r=0,o=1):(r=e[0],n=e[1],o=e[2]||1),o<=0&&(console.warn("[tsu] warning: a step less than or equal to 0 will be set to 1."),o=1);let t=[],i=r;for(;i<n;)t.push(i),i+=o||1;return t}function m(e){return Array.isArray(e)}function z(e){return typeof e=="boolean"}function l(){return typeof window<"u"}function _(e){return typeof e<"u"}function V(e){return m(e)&&e.length===0}function J(e){if(!T(e))return!1;for(let r in e)return!1;return!0}function g(e){return typeof e=="function"}function s(e){return Object.prototype.toString.call(e)==="[object Null]"}function y(e){return typeof e=="number"}function T(e){return Object.prototype.toString.call(e)==="[object Object]"}function p(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 f(e){return l()&&Object.prototype.toString.call(e)==="[object Window]"}function Q(e,r){let n=g(r)?r:t=>t===r,o=e.findIndex(n);return o!==-1?[...e.slice(0,o),...e.slice(o+1)]:e}function G(e){return e.length<1?0:h(e)/e.length}function ee(e,r=1){let n=e/r;return Math.ceil(n)*r}function c(e,r,n){return Math.min(n,Math.max(r,e))}function re(e,r=1){let n=e/r;return Math.floor(n)*r}function ne(e){return e%2===0}function oe(e){return e%2!==0}function te(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.max(...r)}function ie(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.min(...r)}function ue(e){if(e.length<1)return 0;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 fe(e){return u(e)===0}function me(e,r=1){let n=e/r;return Math.round(n)*r}function h(e){let r=0;for(let n=0;n<e.length;n++)r+=e[n];return r}function le(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 n=c(r,0,100);return Number(e.toFixed(n))}function se(e,r=[]){if(!e.length)return NaN;let n=["#","\xA3","\u20AC","$","%",",",...r],o=new RegExp(`[${n.join("")}]`,"g");return Number(e.replace(o,""))}function a(e){if(m(e)){let r=[];for(let n=0;n<e.length;n++)p(e[n])&&!s(e[n])?r[n]=a(e[n]):r[n]=e[n];return r}if(p(e)&&!s(e)){let r={};for(let n in e)p(e[n])&&!s(e[n])?r[n]=a(e[n]):r[n]=e[n];return r}return e}function pe(e,r){let n={...e};for(let o of r)delete n[o];return n}function ce(e){return Object.entries(e)}function ae(e){return Object.keys(e)}function xe(e){return Object.values(e)}function be(e){let r=a(e),n,o,t;for(n=r.length;n;n-=1)o=u(n),t=r[n-1],r[n-1]=r[o],r[o]=t;return r}function de(e,r){return r<=0?[[],[...e]]:r>e.length?[[...e],[]]:[e.slice(0,r),e.slice(r)]}function Te(e){return e.slice(1)}function ge(e,r){return r<=0?[]:e.slice(0,r)}function ye(e){return e?Array.isArray(e)?e:[e]:[]}function he(e){return Array.from(new Set(e))}function we(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 ve(e){l()&&(window.navigator&&"clipboard"in window.navigator?navigator.clipboard.writeText(e):we(e))}function je(e){return e<.5?4*Math.pow(e,3):(e-1)*(2*e-2)*(2*e-2)+1}function ke(e,r,n,o){return e+(r-e)*je(n/o)}function Ee(e,r,n){let o;return y(e)?o=e:f(n)?o=e.getBoundingClientRect().top+r:o=e.getBoundingClientRect().top+r-n.getBoundingClientRect().top,o}function Ce({to:e,offset:r=0,duration:n=1e3,container:o=null}){let t=b(e)?document.querySelector(e):e,i=b(o)?document.querySelector(o):o||window,x=f(i)?window.pageYOffset||document.documentElement.scrollTop:i.scrollTop||0,M=f(i)?document.documentElement.scrollHeight-window.innerHeight:i.scrollHeight-i.clientHeight,F=Ee(t,x,i)+r,w=c(F,0,M),S=Date.now();function v(){let j=Date.now()-S,k=j<n,E=k?ke(x,w,j,n):w;k&&requestAnimationFrame(v),f(i)?window.scrollTo(0,E):i instanceof HTMLElement&&(i.scrollTop=E)}v()}function Oe(e,r){r<0&&console.warn("[tsu] warning: debounce delays less than 0 will be set to 0.");let n;return function(...o){clearTimeout(n),n=setTimeout(()=>{clearTimeout(n),e(...o)},r)}}function C(e){let r={};return function(...n){let o=JSON.stringify(n);if(o in r)return r[o];let t=e(...n);return r[o]=t,t}}var Ae=C;function Ne(e){let r=!1;return(...n)=>{r||(e(...n),r=!0)}}function Me(e,r){if(!(r<=0))for(let n=0;n<r;n++)e(n)}function Fe(e,r){r<0&&console.warn("[tsu] warning: throttle limits less than 0 will be set to 0.");let n=!1;return function(...o){n||(e(...o),n=!0,setTimeout(()=>{n=!1},r))}}function Se(){}async function Ue(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 Re(e=16){let r=O.length,n=e,o="";for(;n--;)o+=O[u(r)];return o}function A(e,r=!1,n=" "){return r?e.split(n).map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(n):e.charAt(0).toUpperCase()+e.slice(1)}var Le=A;function Be(e){return e.split("")}function De(e){return e.trim().length===0}function qe(e){return e.length===0}function He(e,r,n){return r<0||r>e.length-1?e:e.slice(0,r)+n+e.slice(r+1)}function Ie(e,r){return r<=0?["",e]:r>e.length?[e,""]:[e.slice(0,r),e.slice(r)]}function Pe(e){let r=/-(\w)/g;return e.replace(r,(n,o)=>o?o.toUpperCase():"")}function We(e){let r=/\B([A-Z])/g;return e.replace(r,"-$1").toLowerCase()}function $e(e){let n=["st","nd","rd"][(Math.abs(e)/10%10^1&&Math.abs(e)%10)-1]||"th";return`${e}${n}`}var N={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 Ke(e,r=!1){let n=e,o="",t=Object.keys(N).map(Number).sort((i,x)=>x-i);for(let i of t)for(;n>=i;)o+=N[i],n-=i;return r?o.toLowerCase():o}function Xe(e,r,n="..."){return r<=0?n:e.slice(0,r)+n}function ze(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,omit,once,partition,product,randomChance,randomNumber,range,remove,repeat,replaceChar,round,scroll,shuffle,sleep,splitArray,splitString,sum,tail,take,throttle,toArray,toCamel,toDp,toKebab,toNumber,toOrdinal,toRomanNumerals,truncate,unchars,uniq,uuid,vs});
@@ -0,0 +1,613 @@
1
+ /**
2
+ * Removes the first `n` items of an array.
3
+ *
4
+ * @param array - The array.
5
+ * @param n - The number of items to remove.
6
+ * @returns The remaining items.
7
+ */
8
+ declare function drop<T>(array: readonly T[], n: number): T[];
9
+
10
+ /**
11
+ * Splits an array into groups of equal size.
12
+ *
13
+ * @param array - The array.
14
+ * @param n - The size of each group.
15
+ * @returns The array split into groups.
16
+ */
17
+ declare function groups<T>(array: readonly T[], n: number): T[][];
18
+
19
+ /**
20
+ * Returns the first item of an array.
21
+ *
22
+ * @param array - The array.
23
+ * @returns The first item.
24
+ */
25
+ declare function head(array: readonly []): undefined;
26
+ declare function head<T>(array: readonly T[]): T;
27
+
28
+ /**
29
+ * Returns all but the last item of an array.
30
+ *
31
+ * @param array - The array.
32
+ * @returns The array without the last item.
33
+ */
34
+ declare function init<T>(array: readonly T[]): T[];
35
+
36
+ /**
37
+ * Returns the last item of an array.
38
+ *
39
+ * @param array - The array.
40
+ * @returns The last item.
41
+ */
42
+ declare function last(array: readonly []): undefined;
43
+ declare function last<T>(array: readonly T[]): T;
44
+
45
+ /**
46
+ * Splits an array into two based on a predicate function.
47
+ *
48
+ * @param array - The array.
49
+ * @param filter - The predicate function.
50
+ * @returns The tuple of values that satisfy the predicate and those that don't.
51
+ */
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
+ /**
55
+ * Generates a range of numbers.
56
+ *
57
+ * @param start - The inclusive start value.
58
+ * @param stop - The exlusive stop value.
59
+ * @param step - The step to increment by.
60
+ * @returns The range of numbers.
61
+ */
62
+ declare function range(stop: number): number[];
63
+ declare function range(start: number, stop: number, step?: number): number[];
64
+
65
+ /**
66
+ * Removes an item from an array.
67
+ *
68
+ * @param array - The array.
69
+ * @param item - The item, or getter function for the item, to remove.
70
+ * @returns The array with the item removed, if found.
71
+ */
72
+ declare function remove<T>(array: T[], itemOrGetter: T | ((item: T) => boolean)): T[];
73
+
74
+ /**
75
+ * Randomly shuffles items in an array.
76
+ *
77
+ * @param array - The array.
78
+ * @returns A copy of the array with its items randomly shuffled.
79
+ */
80
+ declare function shuffle<T>(array: T[]): T[];
81
+
82
+ /**
83
+ * Splits an array into two at a specified index.
84
+ *
85
+ * @param array - The array.
86
+ * @param i - The position to split at.
87
+ * @returns The tuple of values before and after the split.
88
+ */
89
+ declare function splitArray<T>(array: readonly T[], i: number): [T[], T[]];
90
+
91
+ /**
92
+ * Returns all but the first item of an array.
93
+ *
94
+ * @param array - The array.
95
+ * @returns The array without the first item.
96
+ */
97
+ declare function tail<T>(array: readonly T[]): T[];
98
+
99
+ /**
100
+ * Returns the first `n` items of an array.
101
+ *
102
+ * @param array - The array.
103
+ * @param n - The number of items to return.
104
+ * @returns The first `n` items.
105
+ */
106
+ declare function take<T>(array: readonly T[], n: number): T[];
107
+
108
+ type Arrayable<T> = T | Array<T>;
109
+ type Nullable<T> = T | null | undefined;
110
+ type Fn<T = any> = (...args: any[]) => T;
111
+ type VoidFn = Fn<void>;
112
+ type Obj<V = unknown> = Record<string | symbol | number, V>;
113
+
114
+ /**
115
+ * Wraps a single value in an array, if not already an array.
116
+ *
117
+ * @param maybeArray - The value to wrap, or the existing array.
118
+ * @returns The item wrapped in an array, or the provided array.
119
+ */
120
+ declare function toArray<T>(maybeArray: Nullable<Arrayable<T>>): T[];
121
+
122
+ /**
123
+ * Removes duplicate primitive values from an array.
124
+ *
125
+ * @param array - The array.
126
+ * @returns The array without duplicated primitive values.
127
+ */
128
+ declare function uniq<T>(array: readonly T[]): T[];
129
+
130
+ /**
131
+ * Copies the provided string to the user's clipboard.
132
+ *
133
+ * @param str - The string to be copied to the clipboard.
134
+ */
135
+ declare function copyToClipboard(str: string): void;
136
+
137
+ interface ScrollConfig {
138
+ to: Element | string | number;
139
+ offset?: number;
140
+ duration?: number;
141
+ container?: Element | string | null;
142
+ }
143
+ /**
144
+ * Scrolls the page or provided container to a target element or y-coordinate.
145
+ *
146
+ * @param config - The scroll config.
147
+ * @param config.to - The scroll target.
148
+ * @param config.offset - The offset from the scroll target (in px).
149
+ * @param config.duration - The scroll duration (in ms).
150
+ * @param config.container - The container to scroll in.
151
+ */
152
+ declare function scroll({ to, offset, duration, container }: ScrollConfig): void;
153
+
154
+ /**
155
+ * Prevents function execution until it hasn't been called for a specified time period.
156
+ *
157
+ * @param fn - The function.
158
+ * @param delay - The time period (in ms).
159
+ * @returns The debounced function.
160
+ */
161
+ declare function debounce(fn: Fn<void>, delay: number): Fn<void>;
162
+
163
+ /**
164
+ * Optimises subsequent calls of a function by caching return values.
165
+ *
166
+ * @param fn - The function.
167
+ * @returns The memoised function.
168
+ */
169
+ declare function memoise<T>(fn: Fn<T>): Fn<T>;
170
+ declare const memoize: typeof memoise;
171
+
172
+ /**
173
+ * Enforces that a function is only callable one time.
174
+ *
175
+ * @param fn - The function.
176
+ * @returns The one-time callable function.
177
+ */
178
+ declare function once(fn: Fn<void>): Fn<void>;
179
+
180
+ /**
181
+ * Executes a given function a specified number of times.
182
+ *
183
+ * @param fn - The function to execute for each iteration.
184
+ * @param n - The number of times to execute the function.
185
+ */
186
+ declare function repeat(fn: (i: number) => void, n: number): void;
187
+
188
+ /**
189
+ * Prevents function execution for a specified time period after it was last called.
190
+ *
191
+ * @param fn - The function.
192
+ * @param limit - The time period.
193
+ * @returns The throttled function.
194
+ */
195
+ declare function throttle(fn: Fn<void>, limit: number): Fn<void>;
196
+
197
+ /**
198
+ * Identifies if a value is an array.
199
+ *
200
+ * @param val - The value.
201
+ * @returns If the value is an array.
202
+ */
203
+ declare function isArray(val: unknown): val is any[];
204
+
205
+ /**
206
+ * Identifies if a value is a boolean.
207
+ *
208
+ * @param val - The value.
209
+ * @returns If the value is a boolean.
210
+ */
211
+ declare function isBoolean(val: unknown): val is boolean;
212
+
213
+ /**
214
+ * Identifies if the code is being run in a browser.
215
+ *
216
+ * @returns If the code is being run in a browser.
217
+ */
218
+ declare function isBrowser(): boolean;
219
+
220
+ /**
221
+ * Identifies if a value is defined.
222
+ *
223
+ * @param val - The value.
224
+ * @returns If the value is defined.
225
+ */
226
+ declare function isDefined<T>(val: T): val is Exclude<T, null | undefined>;
227
+
228
+ /**
229
+ * Identifies if a value is an empty array.
230
+ *
231
+ * @param val - The value.
232
+ * @returns If the value is an empty array.
233
+ */
234
+ declare function isEmptyArray(val: unknown): val is [];
235
+
236
+ /**
237
+ * Identifies if a value is an empty object.
238
+ *
239
+ * @param val - The value.
240
+ * @returns If the value is an empty object.
241
+ */
242
+ declare function isEmptyObject(val: unknown): val is Obj<never>;
243
+
244
+ /**
245
+ * Identifies if a value is a function.
246
+ *
247
+ * @param val - The value.
248
+ * @returns If the value is a function.
249
+ */
250
+ declare function isFunction<T extends Fn>(val: unknown): val is T;
251
+
252
+ /**
253
+ * Identifies if a value is null.
254
+ *
255
+ * @param val - The value.
256
+ * @returns If the value is null.
257
+ */
258
+ declare function isNull(val: unknown): val is null;
259
+
260
+ /**
261
+ * Identifies if a value is a number.
262
+ *
263
+ * @param val - The value.
264
+ * @returns If the value is a number.
265
+ */
266
+ declare function isNumber(val: unknown): val is number;
267
+
268
+ /**
269
+ * Identifies if a value is an object.
270
+ *
271
+ * @param val - The value.
272
+ * @returns If the value is an object.
273
+ */
274
+ declare function isObject(val: unknown): val is Obj;
275
+
276
+ /**
277
+ * Identifies if a value is an array, an object, a date, or null.
278
+ *
279
+ * @param val - The value.
280
+ * @returns If the value is an array, an object, a date, or null.
281
+ */
282
+ declare function isObjectLike(val: unknown): val is object;
283
+
284
+ /**
285
+ * Identifies if a value is a string.
286
+ *
287
+ * @param val - The value.
288
+ * @returns If the value is a string.
289
+ */
290
+ declare function isString(val: unknown): val is string;
291
+
292
+ /**
293
+ * Identifies if the code is being run on a touch device.
294
+ *
295
+ * @returns If the code is being run on a touch device.
296
+ */
297
+ declare function isTouchDevice(): boolean;
298
+
299
+ /**
300
+ * Identifies if a value is undefined.
301
+ *
302
+ * @param val - The value.
303
+ * @returns If the value is undefined.
304
+ */
305
+ declare function isUndefined(val: unknown): val is undefined;
306
+
307
+ /**
308
+ * Identifies if a value is the global window.
309
+ *
310
+ * @param val - The value.
311
+ * @returns If the value is the global window.
312
+ */
313
+ declare function isWindow(val: unknown): val is Window;
314
+
315
+ /**
316
+ * Does nothing.
317
+ *
318
+ * @returns Nothing.
319
+ */
320
+ declare function noop(): void;
321
+
322
+ /**
323
+ * Halts thread execution for a specified time period.
324
+ *
325
+ * @param duration - The time period (in ms).
326
+ * @returns The halting promise.
327
+ */
328
+ declare function sleep(duration: number): Promise<void>;
329
+
330
+ /**
331
+ * Generates a random string of a specified length.
332
+ *
333
+ * @param length - The length of the randomly generated string.
334
+ * @returns The randomly generated string.
335
+ */
336
+ declare function uuid(length?: number): string;
337
+
338
+ /**
339
+ * Returns the average of a number array.
340
+ *
341
+ * @param ns - The number array.
342
+ * @returns The average.
343
+ */
344
+ declare function average(ns: readonly number[]): number;
345
+
346
+ /**
347
+ * Rounds a number up to the nearest multiple of the specified factor.
348
+ *
349
+ * @param n - The number to round up.
350
+ * @param factor - The factor used for rounding.
351
+ * @returns The rounded number.
352
+ */
353
+ declare function ceil(n: number, factor?: number): number;
354
+
355
+ /**
356
+ * Restricts a number between two bounds.
357
+ *
358
+ * @param n - The number to restrict.
359
+ * @param min - The minimum bound.
360
+ * @param max - The maximum bound.
361
+ * @returns The number restricted between the specified bounds.
362
+ */
363
+ declare function clamp(n: number, min: number, max: number): number;
364
+
365
+ /**
366
+ * Rounds a number down to the nearest multiple of the specified factor.
367
+ *
368
+ * @param n - The number to round down.
369
+ * @param factor - The factor used for rounding.
370
+ * @returns The rounded number.
371
+ */
372
+ declare function floor(n: number, factor?: number): number;
373
+
374
+ /**
375
+ * Identifies if a number is even.
376
+ *
377
+ * @param n - The number.
378
+ * @returns If the number is even.
379
+ */
380
+ declare function isEven(n: number): boolean;
381
+
382
+ /**
383
+ * Identifies if a number is odd.
384
+ *
385
+ * @param n - The number.
386
+ * @returns If the number is odd.
387
+ */
388
+ declare function isOdd(n: number): boolean;
389
+
390
+ /**
391
+ * Returns the maximum number of provided numbers or array of numbers.
392
+ *
393
+ * @param ns - The numbers or the array of numbers.
394
+ * @returns The maximum number.
395
+ */
396
+ declare function max(...ns: number[] | [number[]]): number;
397
+
398
+ /**
399
+ * Returns the minimum number of provided numbers or array of numbers.
400
+ *
401
+ * @param ns - The numbers or the array of numbers.
402
+ * @returns The minimum number.
403
+ */
404
+ declare function min(...ns: number[] | [number[]]): number;
405
+
406
+ /**
407
+ * Returns the product of a number array.
408
+ *
409
+ * @param ns - The number array.
410
+ * @returns The product.
411
+ */
412
+ declare function product(ns: readonly number[]): number;
413
+
414
+ /**
415
+ * Rolls an n-sided die.
416
+ *
417
+ * @param n - The number of sides on the die.
418
+ * @returns If the die roll was 0.
419
+ */
420
+ declare function randomChance(n: number): boolean;
421
+
422
+ /**
423
+ * Generates a random integer between bounds.
424
+ *
425
+ * @param min - The inclusive minimum bound.
426
+ * @param max - The exclusive maximum bound.
427
+ * @returns The random integer.
428
+ */
429
+ declare function randomNumber(max: number): number;
430
+ declare function randomNumber(min: number, max: number): number;
431
+
432
+ /**
433
+ * Rounds a number to the nearest multiple of the specified factor.
434
+ *
435
+ * @param n - The number to round.
436
+ * @param factor - The factor used for rounding.
437
+ * @returns The rounded number.
438
+ */
439
+ declare function round(n: number, factor?: number): number;
440
+
441
+ /**
442
+ * Returns the sum of a number array.
443
+ *
444
+ * @param ns - The number array.
445
+ * @returns The sum.
446
+ */
447
+ declare function sum(ns: readonly number[]): number;
448
+
449
+ /**
450
+ * Rounds a number to a specified number of decimal places.
451
+ *
452
+ * @param n - The number to round.
453
+ * @param decimalPlaces - The number of decimal places to round to.
454
+ * @returns The rounded number.
455
+ */
456
+ declare function toDp(n: number, decimalPlaces?: number): number;
457
+
458
+ /**
459
+ * Converts a string which contains a number into the number itself.
460
+ *
461
+ * @param str - The string.
462
+ * @param extensions - Additional symbols to consider in the conversion.
463
+ * @returns The number.
464
+ */
465
+ declare function toNumber(str: string, extensions?: string[]): number;
466
+
467
+ /**
468
+ * Deep clones an array or object.
469
+ *
470
+ * @param input - The array or object to clone.
471
+ * @returns A deep clone of the input array or object.
472
+ */
473
+ declare function clone<T>(input: T): T;
474
+
475
+ /**
476
+ * Creates a shallow copy of an object, omitting the specified keys.
477
+ *
478
+ * @param object - The object to copy.
479
+ * @param keysToOmit - The keys to omit from the copied object.
480
+ * @returns A shallow copy of the object, without the specified keys.
481
+ */
482
+ declare function omit<T extends Record<string, any>, K extends keyof T>(object: T, keysToOmit: K[] | any[]): Pick<T, Exclude<keyof T, K>>;
483
+
484
+ /**
485
+ * Strict-typed, shorthand `Object.entries`
486
+ *
487
+ * @param obj - The object to extract the entries from.
488
+ * @returns The entries.
489
+ */
490
+ declare function es<T extends object>(obj: T): [keyof T, T[keyof T]][];
491
+
492
+ /**
493
+ * Strict-typed, shorthand `Object.keys`
494
+ *
495
+ * @param obj - The object to extract the keys from.
496
+ * @returns The keys.
497
+ */
498
+ declare function ks<T extends object>(obj: T): Array<`${keyof T & (string | number | boolean | null | undefined)}`>;
499
+
500
+ /**
501
+ * Shorthand `Object.values`
502
+ *
503
+ * @param obj - The object to extract the values from.
504
+ * @returns The values.
505
+ */
506
+ declare function vs<T>(obj: Obj<T>): T[];
507
+
508
+ /**
509
+ * Capitalises the first letter of one word, or all words, in a string.
510
+ *
511
+ * @param str - The string.
512
+ * @param allWords - If all words should be capitalised.
513
+ * @param delimiter - The delimiter to split the string by.
514
+ * @returns The capitalised string.
515
+ */
516
+ declare function capitalise(str: string, allWords?: boolean, delimiter?: string): string;
517
+ declare const capitalize: typeof capitalise;
518
+
519
+ /**
520
+ * Separates a string into an array of characters.
521
+ *
522
+ * @param str - The string.
523
+ * @returns The string's characters.
524
+ */
525
+ declare function chars(str: string): string[];
526
+
527
+ /**
528
+ * Identifies strings which only contain whitespace.
529
+ *
530
+ * @param str - The string.
531
+ * @returns If the string is blank.
532
+ */
533
+ declare function isBlank(str: string): boolean;
534
+
535
+ /**
536
+ * Identifies empty strings.
537
+ *
538
+ * @param str - The string.
539
+ * @returns If the string is empty.
540
+ */
541
+ declare function isEmpty(str: string): boolean;
542
+
543
+ /**
544
+ * Replaces a character at a specified index in a string with a new character.
545
+ *
546
+ * @param str - The string.
547
+ * @param i - The index of the character to replace.
548
+ * @param char - The character to replace with.
549
+ * @returns The modified string with the character replaced.
550
+ */
551
+ declare function replaceChar(str: string, i: number, char: string): string;
552
+
553
+ /**
554
+ * Splits a string into two at a specified index.
555
+ *
556
+ * @param str - The string.
557
+ * @param i - The position to split at.
558
+ * @returns The tuple of strings before and after the split.
559
+ */
560
+ declare function splitString(str: string, i: number): [string, string];
561
+
562
+ /**
563
+ * Converts a kebab case string to camel case.
564
+ *
565
+ * @param str - The kebab case string.
566
+ * @returns The camel case string.
567
+ */
568
+ declare function toCamel(str: string): string;
569
+
570
+ /**
571
+ * Converts a camel case string to kebab case.
572
+ *
573
+ * @param str - The camel case string.
574
+ * @returns The kebab case string.
575
+ */
576
+ declare function toKebab(str: string): string;
577
+
578
+ /**
579
+ * Adds the respective ordinal suffix (-st, -nd, -rd or -th) to a number.
580
+ *
581
+ * @param n - The number.
582
+ * @returns The number with the ordinal suffix appended.
583
+ */
584
+ declare function toOrdinal(n: number): string;
585
+
586
+ /**
587
+ * Converts a given number to Roman numerals.
588
+ *
589
+ * @param n - The number to convert to Roman numerals.
590
+ * @param lowerCase - If the numerals should be in lowercase.
591
+ * @returns The Roman numeral representation of the given number.
592
+ */
593
+ declare function toRomanNumerals(n: number, lowerCase?: boolean): string;
594
+
595
+ /**
596
+ * Truncates a string to a provided length.
597
+ *
598
+ * @param str - The string.
599
+ * @param length - The length.
600
+ * @param suffix - The suffix to apply after truncation.
601
+ * @returns The truncated string.
602
+ */
603
+ declare function truncate(str: string, length: number, suffix?: string): string;
604
+
605
+ /**
606
+ * Joins an array of characters into a string.
607
+ *
608
+ * @param chars - The characters.
609
+ * @returns The string.
610
+ */
611
+ declare function unchars(chars: string[]): string;
612
+
613
+ 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, omit, once, partition, product, randomChance, randomNumber, range, remove, repeat, replaceChar, round, scroll, shuffle, sleep, splitArray, splitString, sum, tail, take, throttle, toArray, toCamel, toDp, toKebab, toNumber, toOrdinal, toRomanNumerals, truncate, unchars, uniq, uuid, vs };
@@ -0,0 +1,613 @@
1
+ /**
2
+ * Removes the first `n` items of an array.
3
+ *
4
+ * @param array - The array.
5
+ * @param n - The number of items to remove.
6
+ * @returns The remaining items.
7
+ */
8
+ declare function drop<T>(array: readonly T[], n: number): T[];
9
+
10
+ /**
11
+ * Splits an array into groups of equal size.
12
+ *
13
+ * @param array - The array.
14
+ * @param n - The size of each group.
15
+ * @returns The array split into groups.
16
+ */
17
+ declare function groups<T>(array: readonly T[], n: number): T[][];
18
+
19
+ /**
20
+ * Returns the first item of an array.
21
+ *
22
+ * @param array - The array.
23
+ * @returns The first item.
24
+ */
25
+ declare function head(array: readonly []): undefined;
26
+ declare function head<T>(array: readonly T[]): T;
27
+
28
+ /**
29
+ * Returns all but the last item of an array.
30
+ *
31
+ * @param array - The array.
32
+ * @returns The array without the last item.
33
+ */
34
+ declare function init<T>(array: readonly T[]): T[];
35
+
36
+ /**
37
+ * Returns the last item of an array.
38
+ *
39
+ * @param array - The array.
40
+ * @returns The last item.
41
+ */
42
+ declare function last(array: readonly []): undefined;
43
+ declare function last<T>(array: readonly T[]): T;
44
+
45
+ /**
46
+ * Splits an array into two based on a predicate function.
47
+ *
48
+ * @param array - The array.
49
+ * @param filter - The predicate function.
50
+ * @returns The tuple of values that satisfy the predicate and those that don't.
51
+ */
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
+ /**
55
+ * Generates a range of numbers.
56
+ *
57
+ * @param start - The inclusive start value.
58
+ * @param stop - The exlusive stop value.
59
+ * @param step - The step to increment by.
60
+ * @returns The range of numbers.
61
+ */
62
+ declare function range(stop: number): number[];
63
+ declare function range(start: number, stop: number, step?: number): number[];
64
+
65
+ /**
66
+ * Removes an item from an array.
67
+ *
68
+ * @param array - The array.
69
+ * @param item - The item, or getter function for the item, to remove.
70
+ * @returns The array with the item removed, if found.
71
+ */
72
+ declare function remove<T>(array: T[], itemOrGetter: T | ((item: T) => boolean)): T[];
73
+
74
+ /**
75
+ * Randomly shuffles items in an array.
76
+ *
77
+ * @param array - The array.
78
+ * @returns A copy of the array with its items randomly shuffled.
79
+ */
80
+ declare function shuffle<T>(array: T[]): T[];
81
+
82
+ /**
83
+ * Splits an array into two at a specified index.
84
+ *
85
+ * @param array - The array.
86
+ * @param i - The position to split at.
87
+ * @returns The tuple of values before and after the split.
88
+ */
89
+ declare function splitArray<T>(array: readonly T[], i: number): [T[], T[]];
90
+
91
+ /**
92
+ * Returns all but the first item of an array.
93
+ *
94
+ * @param array - The array.
95
+ * @returns The array without the first item.
96
+ */
97
+ declare function tail<T>(array: readonly T[]): T[];
98
+
99
+ /**
100
+ * Returns the first `n` items of an array.
101
+ *
102
+ * @param array - The array.
103
+ * @param n - The number of items to return.
104
+ * @returns The first `n` items.
105
+ */
106
+ declare function take<T>(array: readonly T[], n: number): T[];
107
+
108
+ type Arrayable<T> = T | Array<T>;
109
+ type Nullable<T> = T | null | undefined;
110
+ type Fn<T = any> = (...args: any[]) => T;
111
+ type VoidFn = Fn<void>;
112
+ type Obj<V = unknown> = Record<string | symbol | number, V>;
113
+
114
+ /**
115
+ * Wraps a single value in an array, if not already an array.
116
+ *
117
+ * @param maybeArray - The value to wrap, or the existing array.
118
+ * @returns The item wrapped in an array, or the provided array.
119
+ */
120
+ declare function toArray<T>(maybeArray: Nullable<Arrayable<T>>): T[];
121
+
122
+ /**
123
+ * Removes duplicate primitive values from an array.
124
+ *
125
+ * @param array - The array.
126
+ * @returns The array without duplicated primitive values.
127
+ */
128
+ declare function uniq<T>(array: readonly T[]): T[];
129
+
130
+ /**
131
+ * Copies the provided string to the user's clipboard.
132
+ *
133
+ * @param str - The string to be copied to the clipboard.
134
+ */
135
+ declare function copyToClipboard(str: string): void;
136
+
137
+ interface ScrollConfig {
138
+ to: Element | string | number;
139
+ offset?: number;
140
+ duration?: number;
141
+ container?: Element | string | null;
142
+ }
143
+ /**
144
+ * Scrolls the page or provided container to a target element or y-coordinate.
145
+ *
146
+ * @param config - The scroll config.
147
+ * @param config.to - The scroll target.
148
+ * @param config.offset - The offset from the scroll target (in px).
149
+ * @param config.duration - The scroll duration (in ms).
150
+ * @param config.container - The container to scroll in.
151
+ */
152
+ declare function scroll({ to, offset, duration, container }: ScrollConfig): void;
153
+
154
+ /**
155
+ * Prevents function execution until it hasn't been called for a specified time period.
156
+ *
157
+ * @param fn - The function.
158
+ * @param delay - The time period (in ms).
159
+ * @returns The debounced function.
160
+ */
161
+ declare function debounce(fn: Fn<void>, delay: number): Fn<void>;
162
+
163
+ /**
164
+ * Optimises subsequent calls of a function by caching return values.
165
+ *
166
+ * @param fn - The function.
167
+ * @returns The memoised function.
168
+ */
169
+ declare function memoise<T>(fn: Fn<T>): Fn<T>;
170
+ declare const memoize: typeof memoise;
171
+
172
+ /**
173
+ * Enforces that a function is only callable one time.
174
+ *
175
+ * @param fn - The function.
176
+ * @returns The one-time callable function.
177
+ */
178
+ declare function once(fn: Fn<void>): Fn<void>;
179
+
180
+ /**
181
+ * Executes a given function a specified number of times.
182
+ *
183
+ * @param fn - The function to execute for each iteration.
184
+ * @param n - The number of times to execute the function.
185
+ */
186
+ declare function repeat(fn: (i: number) => void, n: number): void;
187
+
188
+ /**
189
+ * Prevents function execution for a specified time period after it was last called.
190
+ *
191
+ * @param fn - The function.
192
+ * @param limit - The time period.
193
+ * @returns The throttled function.
194
+ */
195
+ declare function throttle(fn: Fn<void>, limit: number): Fn<void>;
196
+
197
+ /**
198
+ * Identifies if a value is an array.
199
+ *
200
+ * @param val - The value.
201
+ * @returns If the value is an array.
202
+ */
203
+ declare function isArray(val: unknown): val is any[];
204
+
205
+ /**
206
+ * Identifies if a value is a boolean.
207
+ *
208
+ * @param val - The value.
209
+ * @returns If the value is a boolean.
210
+ */
211
+ declare function isBoolean(val: unknown): val is boolean;
212
+
213
+ /**
214
+ * Identifies if the code is being run in a browser.
215
+ *
216
+ * @returns If the code is being run in a browser.
217
+ */
218
+ declare function isBrowser(): boolean;
219
+
220
+ /**
221
+ * Identifies if a value is defined.
222
+ *
223
+ * @param val - The value.
224
+ * @returns If the value is defined.
225
+ */
226
+ declare function isDefined<T>(val: T): val is Exclude<T, null | undefined>;
227
+
228
+ /**
229
+ * Identifies if a value is an empty array.
230
+ *
231
+ * @param val - The value.
232
+ * @returns If the value is an empty array.
233
+ */
234
+ declare function isEmptyArray(val: unknown): val is [];
235
+
236
+ /**
237
+ * Identifies if a value is an empty object.
238
+ *
239
+ * @param val - The value.
240
+ * @returns If the value is an empty object.
241
+ */
242
+ declare function isEmptyObject(val: unknown): val is Obj<never>;
243
+
244
+ /**
245
+ * Identifies if a value is a function.
246
+ *
247
+ * @param val - The value.
248
+ * @returns If the value is a function.
249
+ */
250
+ declare function isFunction<T extends Fn>(val: unknown): val is T;
251
+
252
+ /**
253
+ * Identifies if a value is null.
254
+ *
255
+ * @param val - The value.
256
+ * @returns If the value is null.
257
+ */
258
+ declare function isNull(val: unknown): val is null;
259
+
260
+ /**
261
+ * Identifies if a value is a number.
262
+ *
263
+ * @param val - The value.
264
+ * @returns If the value is a number.
265
+ */
266
+ declare function isNumber(val: unknown): val is number;
267
+
268
+ /**
269
+ * Identifies if a value is an object.
270
+ *
271
+ * @param val - The value.
272
+ * @returns If the value is an object.
273
+ */
274
+ declare function isObject(val: unknown): val is Obj;
275
+
276
+ /**
277
+ * Identifies if a value is an array, an object, a date, or null.
278
+ *
279
+ * @param val - The value.
280
+ * @returns If the value is an array, an object, a date, or null.
281
+ */
282
+ declare function isObjectLike(val: unknown): val is object;
283
+
284
+ /**
285
+ * Identifies if a value is a string.
286
+ *
287
+ * @param val - The value.
288
+ * @returns If the value is a string.
289
+ */
290
+ declare function isString(val: unknown): val is string;
291
+
292
+ /**
293
+ * Identifies if the code is being run on a touch device.
294
+ *
295
+ * @returns If the code is being run on a touch device.
296
+ */
297
+ declare function isTouchDevice(): boolean;
298
+
299
+ /**
300
+ * Identifies if a value is undefined.
301
+ *
302
+ * @param val - The value.
303
+ * @returns If the value is undefined.
304
+ */
305
+ declare function isUndefined(val: unknown): val is undefined;
306
+
307
+ /**
308
+ * Identifies if a value is the global window.
309
+ *
310
+ * @param val - The value.
311
+ * @returns If the value is the global window.
312
+ */
313
+ declare function isWindow(val: unknown): val is Window;
314
+
315
+ /**
316
+ * Does nothing.
317
+ *
318
+ * @returns Nothing.
319
+ */
320
+ declare function noop(): void;
321
+
322
+ /**
323
+ * Halts thread execution for a specified time period.
324
+ *
325
+ * @param duration - The time period (in ms).
326
+ * @returns The halting promise.
327
+ */
328
+ declare function sleep(duration: number): Promise<void>;
329
+
330
+ /**
331
+ * Generates a random string of a specified length.
332
+ *
333
+ * @param length - The length of the randomly generated string.
334
+ * @returns The randomly generated string.
335
+ */
336
+ declare function uuid(length?: number): string;
337
+
338
+ /**
339
+ * Returns the average of a number array.
340
+ *
341
+ * @param ns - The number array.
342
+ * @returns The average.
343
+ */
344
+ declare function average(ns: readonly number[]): number;
345
+
346
+ /**
347
+ * Rounds a number up to the nearest multiple of the specified factor.
348
+ *
349
+ * @param n - The number to round up.
350
+ * @param factor - The factor used for rounding.
351
+ * @returns The rounded number.
352
+ */
353
+ declare function ceil(n: number, factor?: number): number;
354
+
355
+ /**
356
+ * Restricts a number between two bounds.
357
+ *
358
+ * @param n - The number to restrict.
359
+ * @param min - The minimum bound.
360
+ * @param max - The maximum bound.
361
+ * @returns The number restricted between the specified bounds.
362
+ */
363
+ declare function clamp(n: number, min: number, max: number): number;
364
+
365
+ /**
366
+ * Rounds a number down to the nearest multiple of the specified factor.
367
+ *
368
+ * @param n - The number to round down.
369
+ * @param factor - The factor used for rounding.
370
+ * @returns The rounded number.
371
+ */
372
+ declare function floor(n: number, factor?: number): number;
373
+
374
+ /**
375
+ * Identifies if a number is even.
376
+ *
377
+ * @param n - The number.
378
+ * @returns If the number is even.
379
+ */
380
+ declare function isEven(n: number): boolean;
381
+
382
+ /**
383
+ * Identifies if a number is odd.
384
+ *
385
+ * @param n - The number.
386
+ * @returns If the number is odd.
387
+ */
388
+ declare function isOdd(n: number): boolean;
389
+
390
+ /**
391
+ * Returns the maximum number of provided numbers or array of numbers.
392
+ *
393
+ * @param ns - The numbers or the array of numbers.
394
+ * @returns The maximum number.
395
+ */
396
+ declare function max(...ns: number[] | [number[]]): number;
397
+
398
+ /**
399
+ * Returns the minimum number of provided numbers or array of numbers.
400
+ *
401
+ * @param ns - The numbers or the array of numbers.
402
+ * @returns The minimum number.
403
+ */
404
+ declare function min(...ns: number[] | [number[]]): number;
405
+
406
+ /**
407
+ * Returns the product of a number array.
408
+ *
409
+ * @param ns - The number array.
410
+ * @returns The product.
411
+ */
412
+ declare function product(ns: readonly number[]): number;
413
+
414
+ /**
415
+ * Rolls an n-sided die.
416
+ *
417
+ * @param n - The number of sides on the die.
418
+ * @returns If the die roll was 0.
419
+ */
420
+ declare function randomChance(n: number): boolean;
421
+
422
+ /**
423
+ * Generates a random integer between bounds.
424
+ *
425
+ * @param min - The inclusive minimum bound.
426
+ * @param max - The exclusive maximum bound.
427
+ * @returns The random integer.
428
+ */
429
+ declare function randomNumber(max: number): number;
430
+ declare function randomNumber(min: number, max: number): number;
431
+
432
+ /**
433
+ * Rounds a number to the nearest multiple of the specified factor.
434
+ *
435
+ * @param n - The number to round.
436
+ * @param factor - The factor used for rounding.
437
+ * @returns The rounded number.
438
+ */
439
+ declare function round(n: number, factor?: number): number;
440
+
441
+ /**
442
+ * Returns the sum of a number array.
443
+ *
444
+ * @param ns - The number array.
445
+ * @returns The sum.
446
+ */
447
+ declare function sum(ns: readonly number[]): number;
448
+
449
+ /**
450
+ * Rounds a number to a specified number of decimal places.
451
+ *
452
+ * @param n - The number to round.
453
+ * @param decimalPlaces - The number of decimal places to round to.
454
+ * @returns The rounded number.
455
+ */
456
+ declare function toDp(n: number, decimalPlaces?: number): number;
457
+
458
+ /**
459
+ * Converts a string which contains a number into the number itself.
460
+ *
461
+ * @param str - The string.
462
+ * @param extensions - Additional symbols to consider in the conversion.
463
+ * @returns The number.
464
+ */
465
+ declare function toNumber(str: string, extensions?: string[]): number;
466
+
467
+ /**
468
+ * Deep clones an array or object.
469
+ *
470
+ * @param input - The array or object to clone.
471
+ * @returns A deep clone of the input array or object.
472
+ */
473
+ declare function clone<T>(input: T): T;
474
+
475
+ /**
476
+ * Creates a shallow copy of an object, omitting the specified keys.
477
+ *
478
+ * @param object - The object to copy.
479
+ * @param keysToOmit - The keys to omit from the copied object.
480
+ * @returns A shallow copy of the object, without the specified keys.
481
+ */
482
+ declare function omit<T extends Record<string, any>, K extends keyof T>(object: T, keysToOmit: K[] | any[]): Pick<T, Exclude<keyof T, K>>;
483
+
484
+ /**
485
+ * Strict-typed, shorthand `Object.entries`
486
+ *
487
+ * @param obj - The object to extract the entries from.
488
+ * @returns The entries.
489
+ */
490
+ declare function es<T extends object>(obj: T): [keyof T, T[keyof T]][];
491
+
492
+ /**
493
+ * Strict-typed, shorthand `Object.keys`
494
+ *
495
+ * @param obj - The object to extract the keys from.
496
+ * @returns The keys.
497
+ */
498
+ declare function ks<T extends object>(obj: T): Array<`${keyof T & (string | number | boolean | null | undefined)}`>;
499
+
500
+ /**
501
+ * Shorthand `Object.values`
502
+ *
503
+ * @param obj - The object to extract the values from.
504
+ * @returns The values.
505
+ */
506
+ declare function vs<T>(obj: Obj<T>): T[];
507
+
508
+ /**
509
+ * Capitalises the first letter of one word, or all words, in a string.
510
+ *
511
+ * @param str - The string.
512
+ * @param allWords - If all words should be capitalised.
513
+ * @param delimiter - The delimiter to split the string by.
514
+ * @returns The capitalised string.
515
+ */
516
+ declare function capitalise(str: string, allWords?: boolean, delimiter?: string): string;
517
+ declare const capitalize: typeof capitalise;
518
+
519
+ /**
520
+ * Separates a string into an array of characters.
521
+ *
522
+ * @param str - The string.
523
+ * @returns The string's characters.
524
+ */
525
+ declare function chars(str: string): string[];
526
+
527
+ /**
528
+ * Identifies strings which only contain whitespace.
529
+ *
530
+ * @param str - The string.
531
+ * @returns If the string is blank.
532
+ */
533
+ declare function isBlank(str: string): boolean;
534
+
535
+ /**
536
+ * Identifies empty strings.
537
+ *
538
+ * @param str - The string.
539
+ * @returns If the string is empty.
540
+ */
541
+ declare function isEmpty(str: string): boolean;
542
+
543
+ /**
544
+ * Replaces a character at a specified index in a string with a new character.
545
+ *
546
+ * @param str - The string.
547
+ * @param i - The index of the character to replace.
548
+ * @param char - The character to replace with.
549
+ * @returns The modified string with the character replaced.
550
+ */
551
+ declare function replaceChar(str: string, i: number, char: string): string;
552
+
553
+ /**
554
+ * Splits a string into two at a specified index.
555
+ *
556
+ * @param str - The string.
557
+ * @param i - The position to split at.
558
+ * @returns The tuple of strings before and after the split.
559
+ */
560
+ declare function splitString(str: string, i: number): [string, string];
561
+
562
+ /**
563
+ * Converts a kebab case string to camel case.
564
+ *
565
+ * @param str - The kebab case string.
566
+ * @returns The camel case string.
567
+ */
568
+ declare function toCamel(str: string): string;
569
+
570
+ /**
571
+ * Converts a camel case string to kebab case.
572
+ *
573
+ * @param str - The camel case string.
574
+ * @returns The kebab case string.
575
+ */
576
+ declare function toKebab(str: string): string;
577
+
578
+ /**
579
+ * Adds the respective ordinal suffix (-st, -nd, -rd or -th) to a number.
580
+ *
581
+ * @param n - The number.
582
+ * @returns The number with the ordinal suffix appended.
583
+ */
584
+ declare function toOrdinal(n: number): string;
585
+
586
+ /**
587
+ * Converts a given number to Roman numerals.
588
+ *
589
+ * @param n - The number to convert to Roman numerals.
590
+ * @param lowerCase - If the numerals should be in lowercase.
591
+ * @returns The Roman numeral representation of the given number.
592
+ */
593
+ declare function toRomanNumerals(n: number, lowerCase?: boolean): string;
594
+
595
+ /**
596
+ * Truncates a string to a provided length.
597
+ *
598
+ * @param str - The string.
599
+ * @param length - The length.
600
+ * @param suffix - The suffix to apply after truncation.
601
+ * @returns The truncated string.
602
+ */
603
+ declare function truncate(str: string, length: number, suffix?: string): string;
604
+
605
+ /**
606
+ * Joins an array of characters into a string.
607
+ *
608
+ * @param chars - The characters.
609
+ * @returns The string.
610
+ */
611
+ declare function unchars(chars: string[]): string;
612
+
613
+ 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, omit, once, partition, product, randomChance, randomNumber, range, remove, repeat, 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 ADDED
@@ -0,0 +1 @@
1
+ function B(e,r){return r<=0?[...e]:e.slice(r)}function q(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 o=0;o<e.length;o+=r)n.push(e.slice(o,o+r));return n}function I(e){return e[0]}function W(e){return e.slice(0,e.length-1)}function K(e){return e[e.length-1]}function z(e,r){let n=[],o=[];for(let i=0;i<e.length;i++){let t=e[i];r(t,i,e)?n.push(t):o.push(t)}return[n,o]}function V(...e){let r,n,o;e.length===1?(n=e[0],r=0,o=1):(r=e[0],n=e[1],o=e[2]||1),o<=0&&(console.warn("[tsu] warning: a step less than or equal to 0 will be set to 1."),o=1);let i=[],t=r;for(;t<n;)i.push(t),t+=o||1;return i}function l(e){return Array.isArray(e)}function Z(e){return typeof e=="boolean"}function s(){return typeof window<"u"}function ee(e){return typeof e<"u"}function oe(e){return l(e)&&e.length===0}function ue(e){if(!w(e))return!1;for(let r in e)return!1;return!0}function v(e){return typeof e=="function"}function p(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 c(e){return typeof e=="object"}function b(e){return typeof e=="string"}function xe(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function de(e){return typeof e>"u"}function f(e){return s()&&Object.prototype.toString.call(e)==="[object Window]"}function De(e,r){let n=v(r)?r:i=>i===r,o=e.findIndex(n);return o!==-1?[...e.slice(0,o),...e.slice(o+1)]:e}function Ie(e){return e.length<1?0:k(e)/e.length}function We(e,r=1){let n=e/r;return Math.ceil(n)*r}function a(e,r,n){return Math.min(n,Math.max(r,e))}function Xe(e,r=1){let n=e/r;return Math.floor(n)*r}function _e(e){return e%2===0}function Je(e){return e%2!==0}function Ze(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.max(...r)}function Ge(...e){let r;return e.length===1&&Array.isArray(e[0])?r=e[0]:r=e,Math.min(...r)}function rr(e){if(e.length<1)return 0;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 ir(e){return u(e)===0}function fr(e,r=1){let n=e/r;return Math.round(n)*r}function k(e){let r=0;for(let n=0;n<e.length;n++)r+=e[n];return r}function pr(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 n=a(r,0,100);return Number(e.toFixed(n))}function ar(e,r=[]){if(!e.length)return NaN;let n=["#","\xA3","\u20AC","$","%",",",...r],o=new RegExp(`[${n.join("")}]`,"g");return Number(e.replace(o,""))}function x(e){if(l(e)){let r=[];for(let n=0;n<e.length;n++)c(e[n])&&!p(e[n])?r[n]=x(e[n]):r[n]=e[n];return r}if(c(e)&&!p(e)){let r={};for(let n in e)c(e[n])&&!p(e[n])?r[n]=x(e[n]):r[n]=e[n];return r}return e}function Ur(e,r){let n={...e};for(let o of r)delete n[o];return n}function Lr(e){return Object.entries(e)}function Dr(e){return Object.keys(e)}function Hr(e){return Object.values(e)}function Jr(e){let r=x(e),n,o,i;for(n=r.length;n;n-=1)o=u(n),i=r[n-1],r[n-1]=r[o],r[o]=i;return r}function Zr(e,r){return r<=0?[[],[...e]]:r>e.length?[[...e],[]]:[e.slice(0,r),e.slice(r)]}function Gr(e){return e.slice(1)}function rn(e,r){return r<=0?[]:e.slice(0,r)}function on(e){return e?Array.isArray(e)?e:[e]:[]}function un(e){return Array.from(new Set(e))}function M(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 kn(e){s()&&(window.navigator&&"clipboard"in window.navigator?navigator.clipboard.writeText(e):M(e))}function F(e){return e<.5?4*Math.pow(e,3):(e-1)*(2*e-2)*(2*e-2)+1}function S(e,r,n,o){return e+(r-e)*F(n/o)}function U(e,r,n){let o;return j(e)?o=e:f(n)?o=e.getBoundingClientRect().top+r:o=e.getBoundingClientRect().top+r-n.getBoundingClientRect().top,o}function An({to:e,offset:r=0,duration:n=1e3,container:o=null}){let i=b(e)?document.querySelector(e):e,t=b(o)?document.querySelector(o):o||window,m=f(t)?window.pageYOffset||document.documentElement.scrollTop:t.scrollTop||0,O=f(t)?document.documentElement.scrollHeight-window.innerHeight:t.scrollHeight-t.clientHeight,A=U(i,m,t)+r,d=a(A,0,O),N=Date.now();function T(){let g=Date.now()-N,y=g<n,h=y?S(m,d,g,n):d;y&&requestAnimationFrame(T),f(t)?window.scrollTo(0,h):t instanceof HTMLElement&&(t.scrollTop=h)}T()}function Un(e,r){r<0&&console.warn("[tsu] warning: debounce delays less than 0 will be set to 0.");let n;return function(...o){clearTimeout(n),n=setTimeout(()=>{clearTimeout(n),e(...o)},r)}}function R(e){let r={};return function(...n){let o=JSON.stringify(n);if(o in r)return r[o];let i=e(...n);return r[o]=i,i}}var Ln=R;function Dn(e){let r=!1;return(...n)=>{r||(e(...n),r=!0)}}function Hn(e,r){if(!(r<=0))for(let n=0;n<r;n++)e(n)}function Pn(e,r){r<0&&console.warn("[tsu] warning: throttle limits less than 0 will be set to 0.");let n=!1;return function(...o){n||(e(...o),n=!0,setTimeout(()=>{n=!1},r))}}function Jn(){}async function Zn(e){return e<0&&console.warn("[tsu] warning: sleep durations less than 0 are set to 0."),new Promise(r=>{setTimeout(r,e)})}var E="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";function eo(e=16){let r=E.length,n=e,o="";for(;n--;)o+=E[u(r)];return o}function L(e,r=!1,n=" "){return r?e.split(n).map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(n):e.charAt(0).toUpperCase()+e.slice(1)}var uo=L;function mo(e){return e.split("")}function so(e){return e.trim().length===0}function co(e){return e.length===0}function xo(e,r,n){return r<0||r>e.length-1?e:e.slice(0,r)+n+e.slice(r+1)}function To(e,r){return r<=0?["",e]:r>e.length?[e,""]:[e.slice(0,r),e.slice(r)]}function yo(e){let r=/-(\w)/g;return e.replace(r,(n,o)=>o?o.toUpperCase():"")}function wo(e){let r=/\B([A-Z])/g;return e.replace(r,"-$1").toLowerCase()}function jo(e){let n=["st","nd","rd"][(Math.abs(e)/10%10^1&&Math.abs(e)%10)-1]||"th";return`${e}${n}`}var C={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 Eo(e,r=!1){let n=e,o="",i=Object.keys(C).map(Number).sort((t,m)=>m-t);for(let t of i)for(;n>=t;)o+=C[t],n-=t;return r?o.toLowerCase():o}function Oo(e,r,n="..."){return r<=0?n:e.slice(0,r)+n}function No(e){return e.join("")}export{Ie as average,L as capitalise,uo as capitalize,We as ceil,mo as chars,a as clamp,x as clone,kn as copyToClipboard,Un as debounce,B as drop,Lr as es,Xe as floor,q as groups,I as head,W as init,l as isArray,so as isBlank,Z as isBoolean,s as isBrowser,ee as isDefined,co as isEmpty,oe as isEmptyArray,ue as isEmptyObject,_e as isEven,v as isFunction,p as isNull,j as isNumber,w as isObject,c as isObjectLike,Je as isOdd,b as isString,xe as isTouchDevice,de as isUndefined,f as isWindow,Dr as ks,K as last,Ze as max,R as memoise,Ln as memoize,Ge as min,Jn as noop,Ur as omit,Dn as once,z as partition,rr as product,ir as randomChance,u as randomNumber,V as range,De as remove,Hn as repeat,xo as replaceChar,fr as round,An as scroll,Jr as shuffle,Zn as sleep,Zr as splitArray,To as splitString,k as sum,Gr as tail,rn as take,Pn as throttle,on as toArray,yo as toCamel,pr as toDp,wo as toKebab,ar as toNumber,jo as toOrdinal,Eo as toRomanNumerals,Oo as truncate,No as unchars,un as uniq,eo as uuid,Hr as vs};
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "tsu",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "TypeScript utilities",
6
+ "license": "MIT",
7
+ "author": "HappyTiptoe",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://gitlab.com/HappyTiptoe/tsu.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://gitlab.com/HappyTiptoe/tsu/issues"
27
+ },
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "watch": "nr build --watch src",
31
+ "test": "vitest run",
32
+ "test:watch": "vitest watch",
33
+ "lint": "eslint 'src/**/*.{ts,tsx}'",
34
+ "lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix",
35
+ "docs:dev": "vitepress dev docs --port 8888",
36
+ "docs:build": "vitepress build docs",
37
+ "prepublishOnly": "nr test; nr build"
38
+ },
39
+ "devDependencies": {
40
+ "@antfu/ni": "^28.2.0",
41
+ "@eslint/js": "^9.39.2",
42
+ "@types/node": "^25.2.0",
43
+ "eslint": "^9.39.2",
44
+ "eslint-config-prettier": "^10.1.8",
45
+ "jiti": "^2.6.1",
46
+ "prettier": "^3.8.1",
47
+ "tsup": "^8.5.1",
48
+ "typescript": "^5.9.3",
49
+ "typescript-eslint": "^8.54.0",
50
+ "vite": "^7.3.1",
51
+ "vitepress": "^1.6.4",
52
+ "vitest": "^4.0.18"
53
+ }
54
+ }