tsu 1.3.3 → 2.0.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 +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +34 -39
- package/dist/index.js +1 -1
- package/package.json +7 -9
package/LICENSE
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var N=(n,e)=>{for(var r in e)s(n,r,{get:e[r],enumerable:!0})},E=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of O(e))!j.call(n,o)&&o!==r&&s(n,o,{get:()=>e[o],enumerable:!(t=v(e,o))||t.enumerable});return n};var F=n=>E(s({},"__esModule",{value:!0}),n);var Tn={};N(Tn,{capitalise:()=>fn,chars:()=>ln,debounce:()=>Z,deepMerge:()=>w,drop:()=>A,groupsOf:()=>S,head:()=>C,init:()=>M,isArray:()=>f,isBlank:()=>sn,isBoolean:()=>k,isBrowser:()=>g,isDefined:()=>D,isEmpty:()=>pn,isEmptyObject:()=>L,isEven:()=>X,isFunction:()=>P,isNull:()=>W,isNumber:()=>m,isObject:()=>u,isOdd:()=>nn,isString:()=>l,isTouchDevice:()=>$,isWindow:()=>H,last:()=>U,max:()=>en,memoize:()=>_,min:()=>rn,noop:()=>un,once:()=>G,partition:()=>V,randomChance:()=>tn,randomNumber:()=>y,scroll:()=>z,sleep:()=>cn,splitAt:()=>I,sum:()=>on,tail:()=>q,take:()=>B,throttle:()=>Q,toArray:()=>R,toCamel:()=>mn,toKebab:()=>an,toNumber:()=>bn,toOrdinal:()=>xn,truncate:()=>dn,uniq:()=>p});module.exports=F(Tn);function A(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 r=[];for(let t=0;t<e.length;t+=n)r.push(e.slice(t,t+n));return r}function C(n){return n[0]}function M(n){return n.slice(0,n.length-1)}function U(n){return n[n.length-1]}function V(n,e){return e.reduce(([r,t],o,i,c)=>n(o,i,c)?[[...r,o],t]:[r,[...t,o]],[[],[]])}function I(n,e){return n<=0?[[],[...e]]:[e.slice(0,n),e.slice(n)]}function q(n){return n.slice(1)}function B(n,e){return n<=0?[]:e.slice(0,n)}function R(n){return n?Array.isArray(n)?n:[n]:[]}function p(n){return Array.from(new Set(n))}function f(n){return Array.isArray(n)}function k(n){return typeof n=="boolean"}function g(){return typeof window<"u"}function D(n){return typeof n<"u"}function L(n){if(!u(n))return!1;for(let e in n)return!1;return!0}function P(n){return typeof n=="function"}function W(n){return Object.prototype.toString.call(n)==="[object Null]"}function m(n){return typeof n=="number"}function u(n){return Object.prototype.toString.call(n)==="[object Object]"}function l(n){return typeof n=="string"}function $(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function H(n){return g()&&Object.prototype.toString.call(n)==="[object Window]"}function z({to:n,offset:e=0,duration:r=1e3,container:t=null}){let o=l(n)?document.querySelector(n):n,i=l(t)?document.querySelector(t):t,c=(i==null?void 0:i.scrollTop)||(window==null?void 0:window.pageYOffset)||0,a=(m(o)?o:Y(o,c))+e,h=Date.now();function b(){let x=Date.now()-h,d=x<r,T=d?K(c,a,x,r):a;d&&requestAnimationFrame(b),i?i.scrollTop=T:window.scrollTo(0,T)}b()}function J(n){return n<.5?4*Math.pow(n,3):(n-1)*(2*n-2)*(2*n-2)+1}function K(n,e,r,t){return n+(e-n)*J(r/t)}function Y(n,e){return n.nodeName==="HTML"?-e:n.getBoundingClientRect().top+e}function Z(n,e){let r;return function(...t){clearTimeout(r),r=setTimeout(()=>{clearTimeout(r),n(...t)},e)}}function _(n){let e={};return function(...r){let t=JSON.stringify(r);if(t in e)return e[t];let o=n(...r);return e[t]=o,o}}function G(n){let e=!1;return(...r)=>{e||(n(...r),e=!0)}}function Q(n,e){let r=!1;return function(...t){r||(n(...t),r=!0,setTimeout(()=>{r=!1},e))}}function X(n){return n%2===0}function nn(n){return n%2!==0}function en(n){if(!!n.length)return Math.max(...n)}function rn(n){if(!!n.length)return Math.min(...n)}function tn(n){return y(n)===0}function y(...n){let e,r;return n.length===1?(e=0,r=n[0]):(e=n[0],r=n[1]),Math.floor(Math.random()*(r-e))+e}function on(n){return n.reduce((e,r)=>e+r,0)}function un(){}async function cn(n){return new Promise(e=>setTimeout(e,n))}function w(...n){return n.reduce((e,r)=>(Object.keys(r).forEach(t=>{f(e[t])&&f(r[t])?e[t]=p(e[t].concat(r[t])):u(e[t])&&u(r[t])?e[t]=w(e[t],r[t]):e[t]=r[t]}),e),{})}function fn(n,e=!1,r=" "){return e?n.split(r).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(r):n.charAt(0).toUpperCase()+n.slice(1)}function ln(n){return n.split("")}function sn(n){return n.trim().length===0}function pn(n){return n.length===0}function mn(n){let e=/-(\w)/g;return n.replace(e,(r,t)=>t?t.toUpperCase():"")}function an(n){let e=/\B([A-Z])/g;return n.replace(e,"-$1").toLowerCase()}function bn(n){return n.length?Number(n.replace(/[#£€$,%]/g,"")):NaN}function xn(n){let r=["st","nd","rd"][(n/10%10^1&&n%10)-1]||"th";return`${n}${r}`}function dn(n,e,r="..."){return e<=0?r:n.slice(0,e)+r}0&&(module.exports={capitalise,chars,debounce,deepMerge,drop,groupsOf,head,init,isArray,isBlank,isBoolean,isBrowser,isDefined,isEmpty,isEmptyObject,isEven,isFunction,isNull,isNumber,isObject,isOdd,isString,isTouchDevice,isWindow,last,max,memoize,min,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
|
@@ -41,20 +41,6 @@ declare function init<T>(array: readonly T[]): T[];
|
|
|
41
41
|
* @returns The last item.
|
|
42
42
|
*/
|
|
43
43
|
declare function last<T>(array: readonly T[]): T;
|
|
44
|
-
/**
|
|
45
|
-
* Returns the maximum number of an array.
|
|
46
|
-
*
|
|
47
|
-
* @param array - The array of numbers.
|
|
48
|
-
* @returns The maximum number.
|
|
49
|
-
*/
|
|
50
|
-
declare function max(array: readonly number[]): number | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* Returns the minimum number of an array.
|
|
53
|
-
*
|
|
54
|
-
* @param array - The array of numbers.
|
|
55
|
-
* @returns The minimum number.
|
|
56
|
-
*/
|
|
57
|
-
declare function min(array: readonly number[]): number | undefined;
|
|
58
44
|
/**
|
|
59
45
|
* Splits an array into two based on a predicate function.
|
|
60
46
|
*
|
|
@@ -71,13 +57,6 @@ declare function partition<T>(filter: (x: T, idx: number, a: readonly T[]) => bo
|
|
|
71
57
|
* @returns The tuple of values before and after the split.
|
|
72
58
|
*/
|
|
73
59
|
declare function splitAt<T>(i: number, array: readonly T[]): [T[], T[]];
|
|
74
|
-
/**
|
|
75
|
-
* Returns the sum of an array of numbers.
|
|
76
|
-
*
|
|
77
|
-
* @param array - The array of numbers.
|
|
78
|
-
* @returns The sum.
|
|
79
|
-
*/
|
|
80
|
-
declare function sum(array: readonly number[]): number;
|
|
81
60
|
/**
|
|
82
61
|
* Returns all but the first item of an array.
|
|
83
62
|
*
|
|
@@ -133,13 +112,6 @@ declare function scroll({ to, offset, duration, container }: ScrollConfig): void
|
|
|
133
112
|
* @returns The debounced function.
|
|
134
113
|
*/
|
|
135
114
|
declare function debounce(fn: VoidFn, delay: number): VoidFn;
|
|
136
|
-
/**
|
|
137
|
-
* Delays function execution until after a stated time period has passed.
|
|
138
|
-
*
|
|
139
|
-
* @param fn - The function.
|
|
140
|
-
* @param delay - The time period (in ms).
|
|
141
|
-
*/
|
|
142
|
-
declare function delay(fn: VoidFn, delay: number): void;
|
|
143
115
|
/**
|
|
144
116
|
* Optimises subsequent calls of a function by caching return values.
|
|
145
117
|
*
|
|
@@ -204,6 +176,13 @@ declare function isEmptyObject(val: unknown): val is Record<string, never>;
|
|
|
204
176
|
* @returns If the value is a function.
|
|
205
177
|
*/
|
|
206
178
|
declare function isFunction<T extends Fn>(val: unknown): val is T;
|
|
179
|
+
/**
|
|
180
|
+
* Identifies if a value is null.
|
|
181
|
+
*
|
|
182
|
+
* @param val - The value.
|
|
183
|
+
* @returns If the value is null.
|
|
184
|
+
*/
|
|
185
|
+
declare function isNull(val: unknown): val is null;
|
|
207
186
|
/**
|
|
208
187
|
* Identifies if a value is a number.
|
|
209
188
|
*
|
|
@@ -254,15 +233,23 @@ declare function isEven(n: number): boolean;
|
|
|
254
233
|
*/
|
|
255
234
|
declare function isOdd(n: number): boolean;
|
|
256
235
|
/**
|
|
257
|
-
*
|
|
236
|
+
* Returns the maximum number of an array.
|
|
237
|
+
*
|
|
238
|
+
* @param array - The array of numbers.
|
|
239
|
+
* @returns The maximum number.
|
|
240
|
+
*/
|
|
241
|
+
declare function max(array: readonly []): undefined;
|
|
242
|
+
declare function max(array: readonly number[]): number;
|
|
243
|
+
/**
|
|
244
|
+
* Returns the minimum number of an array.
|
|
258
245
|
*
|
|
259
|
-
* @param
|
|
260
|
-
* @
|
|
261
|
-
* @returns The remainder of dividing n by m.
|
|
246
|
+
* @param array - The array of numbers.
|
|
247
|
+
* @returns The minimum number.
|
|
262
248
|
*/
|
|
263
|
-
declare function
|
|
249
|
+
declare function min(array: readonly []): undefined;
|
|
250
|
+
declare function min(array: readonly number[]): number;
|
|
264
251
|
/**
|
|
265
|
-
* Rolls an
|
|
252
|
+
* Rolls an n-sided die.
|
|
266
253
|
*
|
|
267
254
|
* @param n - The number of sides on the die.
|
|
268
255
|
* @returns If the die roll was 0.
|
|
@@ -271,11 +258,19 @@ declare function randomChance(n: number): boolean;
|
|
|
271
258
|
/**
|
|
272
259
|
* Generates a random integer between bounds.
|
|
273
260
|
*
|
|
274
|
-
* @param max - The exclusive maximum bound.
|
|
275
261
|
* @param min - The inclusive minimum bound.
|
|
262
|
+
* @param max - The exclusive maximum bound.
|
|
276
263
|
* @returns The random integer.
|
|
277
264
|
*/
|
|
278
|
-
declare function randomNumber(max: number
|
|
265
|
+
declare function randomNumber(max: number): number;
|
|
266
|
+
declare function randomNumber(min: number, max: number): number;
|
|
267
|
+
/**
|
|
268
|
+
* Returns the sum of a number array.
|
|
269
|
+
*
|
|
270
|
+
* @param ns - The number array.
|
|
271
|
+
* @returns The sum.
|
|
272
|
+
*/
|
|
273
|
+
declare function sum(ns: readonly number[]): number;
|
|
279
274
|
|
|
280
275
|
/**
|
|
281
276
|
* Does nothing.
|
|
@@ -363,9 +358,9 @@ declare function toOrdinal(n: number): string;
|
|
|
363
358
|
*
|
|
364
359
|
* @param str - The string.
|
|
365
360
|
* @param length - The length.
|
|
366
|
-
* @param
|
|
361
|
+
* @param suffix - The suffix to apply after truncation.
|
|
367
362
|
* @returns The truncated string.
|
|
368
363
|
*/
|
|
369
|
-
declare function truncate(str: string, length: number,
|
|
364
|
+
declare function truncate(str: string, length: number, suffix?: string): string;
|
|
370
365
|
|
|
371
|
-
export { Arrayable, Fn, Nullable, Obj, VoidFn, capitalise, chars, debounce, deepMerge,
|
|
366
|
+
export { Arrayable, Fn, Nullable, Obj, VoidFn, capitalise, chars, debounce, deepMerge, drop, groupsOf, head, init, isArray, isBlank, isBoolean, isBrowser, isDefined, isEmpty, isEmptyObject, isEven, isFunction, isNull, isNumber, isObject, isOdd, isString, isTouchDevice, isWindow, last, max, memoize, min, noop, once, partition, randomChance, randomNumber, scroll, sleep, splitAt, sum, tail, take, throttle, toArray, toCamel, toKebab, toNumber, toOrdinal, truncate, uniq };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function j(n,e){return n<=0?[...e]:e.slice(n)}function
|
|
1
|
+
function j(n,e){return n<=0?[...e]:e.slice(n)}function N(n,e){if(n<=0)throw new Error("[tsu] Invalid group size. Is it greater than 0?");if(n>=e.length)return[[...e]];let r=[];for(let t=0;t<e.length;t+=n)r.push(e.slice(t,t+n));return r}function E(n){return n[0]}function F(n){return n.slice(0,n.length-1)}function A(n){return n[n.length-1]}function S(n,e){return e.reduce(([r,t],o,i,u)=>n(o,i,u)?[[...r,o],t]:[r,[...t,o]],[[],[]])}function C(n,e){return n<=0?[[],[...e]]:[e.slice(0,n),e.slice(n)]}function M(n){return n.slice(1)}function U(n,e){return n<=0?[]:e.slice(0,n)}function V(n){return n?Array.isArray(n)?n:[n]:[]}function x(n){return Array.from(new Set(n))}function f(n){return Array.isArray(n)}function q(n){return typeof n=="boolean"}function g(){return typeof window<"u"}function B(n){return typeof n<"u"}function R(n){if(!c(n))return!1;for(let e in n)return!1;return!0}function k(n){return typeof n=="function"}function D(n){return Object.prototype.toString.call(n)==="[object Null]"}function d(n){return typeof n=="number"}function c(n){return Object.prototype.toString.call(n)==="[object Object]"}function l(n){return typeof n=="string"}function L(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function P(n){return g()&&Object.prototype.toString.call(n)==="[object Window]"}function H({to:n,offset:e=0,duration:r=1e3,container:t=null}){let o=l(n)?document.querySelector(n):n,i=l(t)?document.querySelector(t):t,u=(i==null?void 0:i.scrollTop)||(window==null?void 0:window.pageYOffset)||0,s=(d(o)?o:h(o,u))+e,T=Date.now();function p(){let m=Date.now()-T,a=m<r,b=a?w(u,s,m,r):s;a&&requestAnimationFrame(p),i?i.scrollTop=b:window.scrollTo(0,b)}p()}function y(n){return n<.5?4*Math.pow(n,3):(n-1)*(2*n-2)*(2*n-2)+1}function w(n,e,r,t){return n+(e-n)*y(r/t)}function h(n,e){return n.nodeName==="HTML"?-e:n.getBoundingClientRect().top+e}function J(n,e){let r;return function(...t){clearTimeout(r),r=setTimeout(()=>{clearTimeout(r),n(...t)},e)}}function K(n){let e={};return function(...r){let t=JSON.stringify(r);if(t in e)return e[t];let o=n(...r);return e[t]=o,o}}function Y(n){let e=!1;return(...r)=>{e||(n(...r),e=!0)}}function Z(n,e){let r=!1;return function(...t){r||(n(...t),r=!0,setTimeout(()=>{r=!1},e))}}function G(n){return n%2===0}function Q(n){return n%2!==0}function X(n){if(!!n.length)return Math.max(...n)}function nn(n){if(!!n.length)return Math.min(...n)}function en(n){return v(n)===0}function v(...n){let e,r;return n.length===1?(e=0,r=n[0]):(e=n[0],r=n[1]),Math.floor(Math.random()*(r-e))+e}function rn(n){return n.reduce((e,r)=>e+r,0)}function on(){}async function un(n){return new Promise(e=>setTimeout(e,n))}function O(...n){return n.reduce((e,r)=>(Object.keys(r).forEach(t=>{f(e[t])&&f(r[t])?e[t]=x(e[t].concat(r[t])):c(e[t])&&c(r[t])?e[t]=O(e[t],r[t]):e[t]=r[t]}),e),{})}function pn(n,e=!1,r=" "){return e?n.split(r).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(r):n.charAt(0).toUpperCase()+n.slice(1)}function mn(n){return n.split("")}function an(n){return n.trim().length===0}function bn(n){return n.length===0}function xn(n){let e=/-(\w)/g;return n.replace(e,(r,t)=>t?t.toUpperCase():"")}function dn(n){let e=/\B([A-Z])/g;return n.replace(e,"-$1").toLowerCase()}function Tn(n){return n.length?Number(n.replace(/[#£€$,%]/g,"")):NaN}function gn(n){let r=["st","nd","rd"][(n/10%10^1&&n%10)-1]||"th";return`${n}${r}`}function yn(n,e,r="..."){return e<=0?r:n.slice(0,e)+r}export{pn as capitalise,mn as chars,J as debounce,O as deepMerge,j as drop,N as groupsOf,E as head,F as init,f as isArray,an as isBlank,q as isBoolean,g as isBrowser,B as isDefined,bn as isEmpty,R as isEmptyObject,G as isEven,k as isFunction,D as isNull,d as isNumber,c as isObject,Q as isOdd,l as isString,L as isTouchDevice,P as isWindow,A as last,X as max,K as memoize,nn as min,on as noop,Y as once,S as partition,en as randomChance,v as randomNumber,H as scroll,un as sleep,C as splitAt,rn as sum,M as tail,U as take,Z as throttle,V as toArray,xn as toCamel,dn as toKebab,Tn as toNumber,gn as toOrdinal,yn as truncate,x as uniq};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsu",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "TypeScript utilities",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,25 +28,23 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "tsup",
|
|
30
30
|
"watch": "nr build --watch src",
|
|
31
|
-
"test": "
|
|
32
|
-
"
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"test:watch": "vitest watch",
|
|
33
33
|
"docs:dev": "vitepress dev docs --port 8888",
|
|
34
|
-
"docs:build": "vitepress build docs"
|
|
34
|
+
"docs:build": "vitepress build docs",
|
|
35
|
+
"prepublishOnly": "nr test; nr build"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@antfu/ni": "^0.17.2",
|
|
38
|
-
"@types/jest": "^28.1.7",
|
|
39
39
|
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
40
40
|
"@typescript-eslint/parser": "^5.33.0",
|
|
41
41
|
"eslint": "^8.22.0",
|
|
42
42
|
"eslint-config-prettier": "^8.5.0",
|
|
43
43
|
"eslint-plugin-prettier": "^4.2.1",
|
|
44
|
-
"jest": "^28.1.3",
|
|
45
44
|
"prettier": "^2.7.1",
|
|
46
|
-
"ts-jest": "^28.0.8",
|
|
47
45
|
"tsup": "^6.2.2",
|
|
48
46
|
"typescript": "^4.7.4",
|
|
49
|
-
"vitepress": "1.0.0-alpha.
|
|
50
|
-
"
|
|
47
|
+
"vitepress": "1.0.0-alpha.35",
|
|
48
|
+
"vitest": "^0.26.3"
|
|
51
49
|
}
|
|
52
50
|
}
|