tsu 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +36 -36
- package/dist/index.js +1 -1
- package/package.json +6 -3
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var l=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var F=(n,e)=>{for(var t in e)l(n,t,{get:e[t],enumerable:!0})},E=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of O(e))!j.call(n,o)&&o!==t&&l(n,o,{get:()=>e[o],enumerable:!(r=v(e,o))||r.enumerable});return n};var A=n=>E(l({},"__esModule",{value:!0}),n);var gn={};F(gn,{capitalise:()=>cn,chars:()=>ln,debounce:()=>G,deepMerge:()=>w,delay:()=>Q,drop:()=>N,groupsOf:()=>S,head:()=>M,init:()=>C,isArray:()=>s,isBlank:()=>pn,isBoolean:()=>W,isBrowser:()=>g,isDefined:()=>$,isEmpty:()=>mn,isEmptyObject:()=>k,isEven:()=>tn,isFunction:()=>H,isNumber:()=>m,isObject:()=>u,isOdd:()=>rn,isString:()=>c,isTouchDevice:()=>z,isWindow:()=>J,last:()=>U,max:()=>V,memoize:()=>X,min:()=>I,modulo:()=>on,noop:()=>fn,once:()=>nn,partition:()=>q,randomChance:()=>un,randomNumber:()=>h,scroll:()=>K,sleep:()=>sn,splitAt:()=>B,sum:()=>R,tail:()=>D,take:()=>L,throttle:()=>en,toArray:()=>P,toCamel:()=>an,toKebab:()=>bn,toNumber:()=>dn,toOrdinal:()=>Tn,truncate:()=>xn,uniq:()=>p});module.exports=A(gn);function N(n,e){return n<=0?[...e]:e.slice(n)}function S(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 M(n){return n[0]}function C(n){return n.slice(0,n.length-1)}function U(n){return n[n.length-1]}function V(n){if(!!n.length)return Math.max(...n)}function I(n){if(!!n.length)return Math.min(...n)}function q(n,e){return e.reduce(([t,r],o,i,f)=>n(o,i,f)?[[...t,o],r]:[t,[...r,o]],[[],[]])}function B(n,e){return n<=0?[[],[...e]]:[e.slice(0,n),e.slice(n)]}function R(n){return n.length?n.reduce((e,t)=>e+t,0):0}function D(n){return n.slice(1)}function L(n,e){return n<=0?[]:e.slice(0,n)}function P(n){return n?Array.isArray(n)?n:[n]:[]}function p(n){return Array.from(new Set(n))}function s(n){return Array.isArray(n)}function W(n){return typeof n=="boolean"}function g(){return typeof window<"u"}function $(n){return typeof n<"u"}function k(n){if(!u(n))return!1;for(let e in n)return!1;return!0}function H(n){return typeof n=="function"}function m(n){return typeof n=="number"}function u(n){return Object.prototype.toString.call(n)==="[object Object]"}function c(n){return typeof n=="string"}function z(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function J(n){return g()&&toString.call(n)==="[object Window]"}function K({to:n,offset:e=0,duration:t=1e3,container:r=null}){let o=c(n)?document.querySelector(n):n,i=c(r)?document.querySelector(r):r,f=(i==null?void 0:i.scrollTop)||(window==null?void 0:window.pageYOffset)||0,a=(m(o)?o:_(o,f))+e,y=Date.now();function b(){let d=Date.now()-y,T=d<t,x=T?Z(f,a,d,t):a;T&&requestAnimationFrame(b),i?i.scrollTop=x:window.scrollTo(0,x)}b()}function Y(n){return n<.5?4*Math.pow(n,3):(n-1)*(2*n-2)*(2*n-2)+1}function Z(n,e,t,r){return n+(e-n)*Y(t/r)}function _(n,e){return n.nodeName==="HTML"?-e:n.getBoundingClientRect().top+e}function G(n,e){let t;return function(...r){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),n(...r)},e)}}function Q(n,e){setTimeout(()=>{n()},e)}function X(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 nn(n){let e=!1;return(...t)=>{e||(n(...t),e=!0)}}function en(n,e){let t=!1;return function(...r){t||(n(...r),t=!0,setTimeout(()=>{t=!1},e))}}function tn(n){return n%2===0}function rn(n){return n%2!==0}function on(n,e){return n-Math.floor(n/e)*e}function un(n){return h(n)===0}function h(n,e=0){return Math.floor(Math.random()*(n-e))+e}function fn(){}async function sn(n){return new Promise(e=>setTimeout(e,n))}function w(...n){return n.reduce((e,t)=>(Object.keys(t).forEach(r=>{s(e[r])&&s(t[r])?e[r]=p(e[r].concat(t[r])):u(e[r])&&u(t[r])?e[r]=w(e[r],t[r]):e[r]=t[r]}),e),{})}function cn(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 ln(n){return n.split("")}function pn(n){return n.trim().length===0}function mn(n){return n.length===0}function an(n){let e=/-(\w)/g;return n.replace(e,(t,r)=>r?r.toUpperCase():"")}function bn(n){let e=/\B([A-Z])/g;return n.replace(e,"-$1").toLowerCase()}function dn(n){return n.length?Number(n.replace(/[#£€$,%]/g,"")):NaN}function Tn(n){let t=["st","nd","rd"][(n/10%10^1&&n%10)-1]||"th";return`${n}${t}`}function xn(n,e,t="..."){return e<=0?t:n.slice(0,e)+t}0&&(module.exports={capitalise,chars,debounce,deepMerge,delay,drop,groupsOf,head,init,isArray,isBlank,isBoolean,isBrowser,isDefined,isEmpty,isEmptyObject,isEven,isFunction,isNumber,isObject,isOdd,isString,isTouchDevice,isWindow,last,max,memoize,min,modulo,noop,once,partition,randomChance,randomNumber,scroll,sleep,splitAt,sum,tail,take,throttle,toArray,toCamel,toKebab,toNumber,toOrdinal,truncate,uniq});
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare type VoidFn = Fn<void>;
|
|
|
5
5
|
declare type Obj<V = unknown> = Record<string | symbol | number, V>;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Removes the first n items of an array.
|
|
8
|
+
* Removes the first `n` items of an array.
|
|
9
9
|
*
|
|
10
10
|
* @param n - The number of items to remove.
|
|
11
11
|
* @param array - The array.
|
|
@@ -13,7 +13,7 @@ declare type Obj<V = unknown> = Record<string | symbol | number, V>;
|
|
|
13
13
|
*/
|
|
14
14
|
declare function drop<T>(n: number, array: readonly T[]): T[];
|
|
15
15
|
/**
|
|
16
|
-
* Splits an array into groups of size
|
|
16
|
+
* Splits an array into groups of equal size.
|
|
17
17
|
*
|
|
18
18
|
* @param s - The size of each group.
|
|
19
19
|
* @param array - The array.
|
|
@@ -64,7 +64,7 @@ declare function min(array: readonly number[]): number | undefined;
|
|
|
64
64
|
*/
|
|
65
65
|
declare function partition<T>(filter: (x: T, idx: number, a: readonly T[]) => boolean, array: readonly T[]): [T[], T[]];
|
|
66
66
|
/**
|
|
67
|
-
* Splits an array into two at a
|
|
67
|
+
* Splits an array into two at a stated index.
|
|
68
68
|
*
|
|
69
69
|
* @param i - The position to split at.
|
|
70
70
|
* @param array - The array.
|
|
@@ -86,15 +86,15 @@ declare function sum(array: readonly number[]): number;
|
|
|
86
86
|
*/
|
|
87
87
|
declare function tail<T>(array: readonly T[]): T[];
|
|
88
88
|
/**
|
|
89
|
-
* Returns the first n items of an array.
|
|
89
|
+
* Returns the first `n` items of an array.
|
|
90
90
|
*
|
|
91
91
|
* @param n - The number of items to return.
|
|
92
92
|
* @param array - The array.
|
|
93
|
-
* @returns The first n items.
|
|
93
|
+
* @returns The first `n` items.
|
|
94
94
|
*/
|
|
95
95
|
declare function take<T>(n: number, array: readonly T[]): T[];
|
|
96
96
|
/**
|
|
97
|
-
* Wraps a single value
|
|
97
|
+
* Wraps a single value in an array, if not already an array.
|
|
98
98
|
*
|
|
99
99
|
* @param maybeArray - The value to wrap, or the existing array.
|
|
100
100
|
* @returns The item wrapped in an array, or the provided array.
|
|
@@ -108,6 +108,23 @@ declare function toArray<T>(maybeArray: Nullable<Arrayable<T>>): T[];
|
|
|
108
108
|
*/
|
|
109
109
|
declare function uniq<T>(array: readonly T[]): T[];
|
|
110
110
|
|
|
111
|
+
interface ScrollConfig {
|
|
112
|
+
to: Element | string | number;
|
|
113
|
+
offset?: number;
|
|
114
|
+
duration?: number;
|
|
115
|
+
container?: Element | string | null;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Scrolls the page or provided container to a target element or y-coordinate.
|
|
119
|
+
*
|
|
120
|
+
* @param config - The scroll config.
|
|
121
|
+
* @param config.to - The scroll target.
|
|
122
|
+
* @param config.offset - The offset from the scroll target (in px).
|
|
123
|
+
* @param config.duration - The scroll duration (in ms).
|
|
124
|
+
* @param config.container - The container to scroll in.
|
|
125
|
+
*/
|
|
126
|
+
declare function scroll({ to, offset, duration, container }: ScrollConfig): void;
|
|
127
|
+
|
|
111
128
|
/**
|
|
112
129
|
* Prevents function execution until it hasn't been called for a stated time period.
|
|
113
130
|
*
|
|
@@ -115,14 +132,14 @@ declare function uniq<T>(array: readonly T[]): T[];
|
|
|
115
132
|
* @param delay - The time period (in ms).
|
|
116
133
|
* @returns The debounced function.
|
|
117
134
|
*/
|
|
118
|
-
declare function debounce(fn:
|
|
135
|
+
declare function debounce(fn: VoidFn, delay: number): VoidFn;
|
|
119
136
|
/**
|
|
120
137
|
* Delays function execution until after a stated time period has passed.
|
|
121
138
|
*
|
|
122
139
|
* @param fn - The function.
|
|
123
140
|
* @param delay - The time period (in ms).
|
|
124
141
|
*/
|
|
125
|
-
declare function delay(fn:
|
|
142
|
+
declare function delay(fn: VoidFn, delay: number): void;
|
|
126
143
|
/**
|
|
127
144
|
* Optimises subsequent calls of a function by caching return values.
|
|
128
145
|
*
|
|
@@ -136,7 +153,7 @@ declare function memoize<T>(fn: Fn<T>): Fn<T>;
|
|
|
136
153
|
* @param fn - The function.
|
|
137
154
|
* @returns The one-time callable function.
|
|
138
155
|
*/
|
|
139
|
-
declare function once(fn:
|
|
156
|
+
declare function once(fn: VoidFn): VoidFn;
|
|
140
157
|
/**
|
|
141
158
|
* Prevents function execution for a stated time period after it was last called.
|
|
142
159
|
*
|
|
@@ -144,7 +161,7 @@ declare function once(fn: Fn): VoidFn;
|
|
|
144
161
|
* @param limit - The time period.
|
|
145
162
|
* @returns The throttled function.
|
|
146
163
|
*/
|
|
147
|
-
declare function throttle(fn:
|
|
164
|
+
declare function throttle(fn: VoidFn, limit: number): VoidFn;
|
|
148
165
|
|
|
149
166
|
/**
|
|
150
167
|
* Identifies if a value is an array.
|
|
@@ -244,6 +261,13 @@ declare function isOdd(n: number): boolean;
|
|
|
244
261
|
* @returns The remainder of dividing n by m.
|
|
245
262
|
*/
|
|
246
263
|
declare function modulo(n: number, m: number): number;
|
|
264
|
+
/**
|
|
265
|
+
* Rolls an `n`-sided die.
|
|
266
|
+
*
|
|
267
|
+
* @param n - The number of sides on the die.
|
|
268
|
+
* @returns If the die roll was 0.
|
|
269
|
+
*/
|
|
270
|
+
declare function randomChance(n: number): boolean;
|
|
247
271
|
/**
|
|
248
272
|
* Generates a random integer between bounds.
|
|
249
273
|
*
|
|
@@ -252,13 +276,6 @@ declare function modulo(n: number, m: number): number;
|
|
|
252
276
|
* @returns The random integer.
|
|
253
277
|
*/
|
|
254
278
|
declare function randomNumber(max: number, min?: number): number;
|
|
255
|
-
/**
|
|
256
|
-
* Rolls an n-sided die.
|
|
257
|
-
*
|
|
258
|
-
* @param n - The number of sides on the die.
|
|
259
|
-
* @returns If the die roll was 0.
|
|
260
|
-
*/
|
|
261
|
-
declare function randomChance(n: number): boolean;
|
|
262
279
|
|
|
263
280
|
/**
|
|
264
281
|
* Does nothing.
|
|
@@ -283,23 +300,6 @@ declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) e
|
|
|
283
300
|
*/
|
|
284
301
|
declare function deepMerge<T extends Obj<any>[]>(...objects: T): UnionToIntersection<T[number]>;
|
|
285
302
|
|
|
286
|
-
declare type ScrollConfig = {
|
|
287
|
-
to: Element | string | number;
|
|
288
|
-
offset?: number;
|
|
289
|
-
duration?: number;
|
|
290
|
-
container?: Element | string | null;
|
|
291
|
-
};
|
|
292
|
-
/**
|
|
293
|
-
* Scrolls the page or provided container to a target element or y-coordinate.
|
|
294
|
-
*
|
|
295
|
-
* @param config - The scroll config.
|
|
296
|
-
* @param config.to - The scroll target.
|
|
297
|
-
* @param config.offset - The offset from the scroll target (in px).
|
|
298
|
-
* @param config.duration - The scroll duration (in ms).
|
|
299
|
-
* @param config.container - The container to scroll in.
|
|
300
|
-
*/
|
|
301
|
-
declare function scroll({ to, offset, duration, container }: ScrollConfig): void;
|
|
302
|
-
|
|
303
303
|
/**
|
|
304
304
|
* Capitalises the first letter of one word, or all words, in a string.
|
|
305
305
|
*
|
|
@@ -345,7 +345,7 @@ declare function toCamel(str: string): string;
|
|
|
345
345
|
*/
|
|
346
346
|
declare function toKebab(str: string): string;
|
|
347
347
|
/**
|
|
348
|
-
* Converts a string which contains a number
|
|
348
|
+
* Converts a string which contains a number into the number itself.
|
|
349
349
|
*
|
|
350
350
|
* @param str - The string.
|
|
351
351
|
* @returns The number.
|
|
@@ -357,7 +357,7 @@ declare function toNumber(str: string): number;
|
|
|
357
357
|
* @param n - The number.
|
|
358
358
|
* @returns The number with the ordinal suffix appended.
|
|
359
359
|
*/
|
|
360
|
-
declare function toOrdinal(n: number
|
|
360
|
+
declare function toOrdinal(n: number): string;
|
|
361
361
|
/**
|
|
362
362
|
* Truncates a string to a provided length.
|
|
363
363
|
*
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function j(n,e){return n<=0?[...e]:e.slice(n)}function F(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 E(n){return n[0]}function A(n){return n.slice(0,n.length-1)}function N(n){return n[n.length-1]}function S(n){if(!!n.length)return Math.max(...n)}function M(n){if(!!n.length)return Math.min(...n)}function C(n,e){return e.reduce(([t,r],o,i,u)=>n(o,i,u)?[[...t,o],r]:[t,[...r,o]],[[],[]])}function U(n,e){return n<=0?[[],[...e]]:[e.slice(0,n),e.slice(n)]}function V(n){return n.length?n.reduce((e,t)=>e+t,0):0}function I(n){return n.slice(1)}function q(n,e){return n<=0?[]:e.slice(0,n)}function B(n){return n?Array.isArray(n)?n:[n]:[]}function d(n){return Array.from(new Set(n))}function s(n){return Array.isArray(n)}function D(n){return typeof n=="boolean"}function g(){return typeof window<"u"}function L(n){return typeof n<"u"}function P(n){if(!f(n))return!1;for(let e in n)return!1;return!0}function W(n){return typeof n=="function"}function T(n){return typeof n=="number"}function f(n){return Object.prototype.toString.call(n)==="[object Object]"}function c(n){return typeof n=="string"}function $(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function k(n){return g()&&toString.call(n)==="[object Window]"}function J({to:n,offset:e=0,duration:t=1e3,container:r=null}){let o=c(n)?document.querySelector(n):n,i=c(r)?document.querySelector(r):r,u=(i==null?void 0:i.scrollTop)||(window==null?void 0:window.pageYOffset)||0,l=(T(o)?o:y(o,u))+e,x=Date.now();function p(){let m=Date.now()-x,a=m<t,b=a?w(u,l,m,t):l;a&&requestAnimationFrame(p),i?i.scrollTop=b:window.scrollTo(0,b)}p()}function h(n){return n<.5?4*Math.pow(n,3):(n-1)*(2*n-2)*(2*n-2)+1}function w(n,e,t,r){return n+(e-n)*h(t/r)}function y(n,e){return n.nodeName==="HTML"?-e:n.getBoundingClientRect().top+e}function Y(n,e){let t;return function(...r){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),n(...r)},e)}}function Z(n,e){setTimeout(()=>{n()},e)}function _(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 G(n){let e=!1;return(...t)=>{e||(n(...t),e=!0)}}function Q(n,e){let t=!1;return function(...r){t||(n(...r),t=!0,setTimeout(()=>{t=!1},e))}}function nn(n){return n%2===0}function en(n){return n%2!==0}function tn(n,e){return n-Math.floor(n/e)*e}function rn(n){return v(n)===0}function v(n,e=0){return Math.floor(Math.random()*(n-e))+e}function un(){}async function fn(n){return new Promise(e=>setTimeout(e,n))}function O(...n){return n.reduce((e,t)=>(Object.keys(t).forEach(r=>{s(e[r])&&s(t[r])?e[r]=d(e[r].concat(t[r])):f(e[r])&&f(t[r])?e[r]=O(e[r],t[r]):e[r]=t[r]}),e),{})}function mn(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 an(n){return n.split("")}function bn(n){return n.trim().length===0}function dn(n){return n.length===0}function Tn(n){let e=/-(\w)/g;return n.replace(e,(t,r)=>r?r.toUpperCase():"")}function xn(n){let e=/\B([A-Z])/g;return n.replace(e,"-$1").toLowerCase()}function gn(n){return n.length?Number(n.replace(/[#£€$,%]/g,"")):NaN}function hn(n){let t=["st","nd","rd"][(n/10%10^1&&n%10)-1]||"th";return`${n}${t}`}function wn(n,e,t="..."){return e<=0?t:n.slice(0,e)+t}export{mn as capitalise,an as chars,Y as debounce,O as deepMerge,Z as delay,j as drop,F as groupsOf,E as head,A as init,s as isArray,bn as isBlank,D as isBoolean,g as isBrowser,L as isDefined,dn as isEmpty,P as isEmptyObject,nn as isEven,W as isFunction,T as isNumber,f as isObject,en as isOdd,c as isString,$ as isTouchDevice,k as isWindow,N as last,S as max,_ as memoize,M as min,tn as modulo,un as noop,G as once,C as partition,rn as randomChance,v as randomNumber,J as scroll,fn as sleep,U as splitAt,V as sum,I as tail,q as take,Q as throttle,B as toArray,Tn as toCamel,xn as toKebab,gn as toNumber,hn as toOrdinal,wn as truncate,d as uniq};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsu",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A collection of TypeScript utilities.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,8 +30,10 @@
|
|
|
30
30
|
"watch": "nr build --watch src",
|
|
31
31
|
"test": "jest",
|
|
32
32
|
"prepublishOnly": "nr test; nr build",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"_docs:dev": "vuepress dev _docs",
|
|
34
|
+
"_docs:build": "vuepress build _docs",
|
|
35
|
+
"docs:dev": "vitepress dev docs --port 8888",
|
|
36
|
+
"docs:build": "vitepress build docs"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
39
|
"@antfu/ni": "^0.17.2",
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
"ts-jest": "^28.0.8",
|
|
47
49
|
"tsup": "^6.2.2",
|
|
48
50
|
"typescript": "^4.7.4",
|
|
51
|
+
"vitepress": "1.0.0-alpha.8",
|
|
49
52
|
"vuepress": "2.0.0-beta.41"
|
|
50
53
|
}
|
|
51
54
|
}
|