@aliexme/js-utils 2.0.0 → 2.1.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/array/arraysIntersection.cjs +1 -0
- package/dist/array/groupArrayItems.cjs +1 -0
- package/dist/array/randomArrayItem.cjs +1 -0
- package/dist/array/subtractArrays.cjs +1 -0
- package/dist/array/uniquify.cjs +1 -0
- package/dist/async/asyncResult.cjs +1 -0
- package/dist/async/asyncify.cjs +1 -0
- package/dist/async/sleep.cjs +1 -0
- package/dist/function/debounce.cjs +1 -0
- package/dist/function/debounce.d.ts +9 -0
- package/dist/function/debounce.js +26 -0
- package/dist/function/index.d.ts +2 -0
- package/dist/function/noop.cjs +1 -0
- package/dist/function/throttle.cjs +1 -0
- package/dist/function/throttle.d.ts +8 -0
- package/dist/function/throttle.js +23 -0
- package/dist/index.cjs +1 -0
- package/dist/index.js +36 -30
- package/dist/number/clamp.cjs +1 -0
- package/dist/number/clamp.d.ts +1 -0
- package/dist/number/clamp.js +4 -0
- package/dist/number/index.d.ts +1 -0
- package/dist/number/randomInt.cjs +1 -0
- package/dist/number/round.cjs +1 -0
- package/dist/object/findObjectKey.cjs +1 -0
- package/dist/object/getObjectKey.cjs +1 -0
- package/dist/object/objectForEach.cjs +1 -0
- package/dist/object/omitObjectProperties.cjs +1 -0
- package/dist/object/omitUndefinedObjectValues.cjs +1 -0
- package/dist/string/capitalize.cjs +1 -0
- package/dist/string/randomString.cjs +1 -0
- package/dist/string/secureString.cjs +1 -0
- package/package.json +11 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=(n,i,...r)=>{if(n.length===0||i.length===0||r.some(e=>e.length===0))return[];let t=n.filter(e=>i.includes(e));return r.forEach(e=>{t=t.filter(l=>e.includes(l))}),t};exports.arraysIntersection=o;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=(s,u)=>{const e={};return s.forEach(r=>{const t=r[u],o=e[t];o?o.push(r):e[t]=[r]}),e};exports.groupArrayItems=a;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=t=>{const r=Math.floor(Math.random()*t.length);return t[r]};exports.randomArrayItem=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=(t,e)=>t.length===0||e.length===0?t:t.filter(r=>!e.includes(r));exports.subtractArrays=n;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=e=>[...new Set(e)];exports.uniquify=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./asyncify.cjs"),e=n=>s.asyncify(n)();exports.asyncResult=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=e=>(...t)=>new Promise(r=>{setTimeout(()=>r(e(...t)),0)});exports.asyncify=n;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=async e=>new Promise(t=>setTimeout(t,e));exports.sleep=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../number/clamp.cjs"),C=(l,c,m={})=>{const{maxWait:i,withLeading:d=!1}=m;let e=null,t=null;const o=()=>{e!==null&&(clearTimeout(e),e=null)},n=()=>{t=null},T=()=>{o(),n()},s=(...r)=>{o();const u=Date.now(),b=t?u-t:0,a=i?f.clamp(i-b,0,c):c;if(!t&&(t=u,d)){l(...r),e=setTimeout(n,a);return}e=setTimeout(()=>{l(...r),n()},a)};return s.cancel=T,s};exports.debounce=C;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface DebouncedFunc<T extends (...args: unknown[]) => unknown> {
|
|
2
|
+
(...args: Parameters<T>): void;
|
|
3
|
+
cancel(): void;
|
|
4
|
+
}
|
|
5
|
+
export interface DebounceOptions {
|
|
6
|
+
maxWait?: number;
|
|
7
|
+
withLeading?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const debounce: <T extends (...args: unknown[]) => unknown>(func: T, delay: number, options?: DebounceOptions) => DebouncedFunc<T>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { clamp as C } from "../number/clamp.js";
|
|
2
|
+
const p = (l, i, m = {}) => {
|
|
3
|
+
const { maxWait: c, withLeading: f = !1 } = m;
|
|
4
|
+
let t = null, e = null;
|
|
5
|
+
const o = () => {
|
|
6
|
+
t !== null && (clearTimeout(t), t = null);
|
|
7
|
+
}, n = () => {
|
|
8
|
+
e = null;
|
|
9
|
+
}, T = () => {
|
|
10
|
+
o(), n();
|
|
11
|
+
}, s = (...r) => {
|
|
12
|
+
o();
|
|
13
|
+
const a = Date.now(), d = e ? a - e : 0, u = c ? C(c - d, 0, i) : i;
|
|
14
|
+
if (!e && (e = a, f)) {
|
|
15
|
+
l(...r), t = setTimeout(n, u);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
t = setTimeout(() => {
|
|
19
|
+
l(...r), n();
|
|
20
|
+
}, u);
|
|
21
|
+
};
|
|
22
|
+
return s.cancel = T, s;
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
p as debounce
|
|
26
|
+
};
|
package/dist/function/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=()=>{};exports.noop=o;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=(n,r,s={})=>{const{withTrailing:T=!1}=s;let e=null,t=null,l=!1;const o=()=>{e!==null&&(clearTimeout(e),e=null)},a=()=>{t!==null&&(clearTimeout(t),t=null)},c=()=>{l=!1},m=()=>{o(),a(),c()},i=(...u)=>{if(l){T&&(o(),e=setTimeout(()=>n(...u),r));return}o(),n(...u),l=!0,t=setTimeout(c,r)};return i.cancel=m,i};exports.throttle=d;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ThrottledFunc<T extends (...args: unknown[]) => unknown> {
|
|
2
|
+
(...args: Parameters<T>): void;
|
|
3
|
+
cancel(): void;
|
|
4
|
+
}
|
|
5
|
+
export interface ThrottleOptions {
|
|
6
|
+
withTrailing?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const throttle: <T extends (...args: unknown[]) => unknown>(func: T, delay: number, options?: ThrottleOptions) => ThrottledFunc<T>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const f = (n, c, s = {}) => {
|
|
2
|
+
const { withTrailing: T = !1 } = s;
|
|
3
|
+
let e = null, l = null, t = !1;
|
|
4
|
+
const o = () => {
|
|
5
|
+
e !== null && (clearTimeout(e), e = null);
|
|
6
|
+
}, m = () => {
|
|
7
|
+
l !== null && (clearTimeout(l), l = null);
|
|
8
|
+
}, r = () => {
|
|
9
|
+
t = !1;
|
|
10
|
+
}, a = () => {
|
|
11
|
+
o(), m(), r();
|
|
12
|
+
}, i = (...u) => {
|
|
13
|
+
if (t) {
|
|
14
|
+
T && (o(), e = setTimeout(() => n(...u), c));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
o(), n(...u), t = !0, l = setTimeout(r, c);
|
|
18
|
+
};
|
|
19
|
+
return i.cancel = a, i;
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
f as throttle
|
|
23
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./string/capitalize.cjs"),r=require("./string/secureString.cjs"),t=require("./string/randomString.cjs"),n=require("./number/round.cjs"),o=require("./number/clamp.cjs"),c=require("./number/randomInt.cjs"),i=require("./array/uniquify.cjs"),s=require("./array/subtractArrays.cjs"),u=require("./array/arraysIntersection.cjs"),a=require("./array/groupArrayItems.cjs"),y=require("./array/randomArrayItem.cjs"),d=require("./object/getObjectKey.cjs"),m=require("./object/findObjectKey.cjs"),q=require("./object/objectForEach.cjs"),b=require("./object/omitObjectProperties.cjs"),l=require("./object/omitUndefinedObjectValues.cjs"),p=require("./function/noop.cjs"),j=require("./function/debounce.cjs"),g=require("./function/throttle.cjs"),f=require("./async/asyncify.cjs"),O=require("./async/asyncResult.cjs"),I=require("./async/sleep.cjs");exports.capitalize=e.capitalize;exports.secureString=r.secureString;exports.randomString=t.randomString;exports.round=n.round;exports.clamp=o.clamp;exports.randomInt=c.randomInt;exports.uniquify=i.uniquify;exports.subtractArrays=s.subtractArrays;exports.arraysIntersection=u.arraysIntersection;exports.groupArrayItems=a.groupArrayItems;exports.randomArrayItem=y.randomArrayItem;exports.getObjectKey=d.getObjectKey;exports.findObjectKey=m.findObjectKey;exports.objectForEach=q.objectForEach;exports.omitObjectProperties=b.omitObjectProperties;exports.omitUndefinedObjectValues=l.omitUndefinedObjectValues;exports.noop=p.noop;exports.debounce=j.debounce;exports.throttle=g.throttle;exports.asyncify=f.asyncify;exports.asyncResult=O.asyncResult;exports.sleep=I.sleep;
|
package/dist/index.js
CHANGED
|
@@ -2,39 +2,45 @@ import { capitalize as e } from "./string/capitalize.js";
|
|
|
2
2
|
import { secureString as m } from "./string/secureString.js";
|
|
3
3
|
import { randomString as f } from "./string/randomString.js";
|
|
4
4
|
import { round as n } from "./number/round.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
5
|
+
import { clamp as c } from "./number/clamp.js";
|
|
6
|
+
import { randomInt as s } from "./number/randomInt.js";
|
|
7
|
+
import { uniquify as u } from "./array/uniquify.js";
|
|
8
|
+
import { subtractArrays as b } from "./array/subtractArrays.js";
|
|
9
|
+
import { arraysIntersection as j } from "./array/arraysIntersection.js";
|
|
10
|
+
import { groupArrayItems as I } from "./array/groupArrayItems.js";
|
|
11
|
+
import { randomArrayItem as A } from "./array/randomArrayItem.js";
|
|
12
|
+
import { getObjectKey as K } from "./object/getObjectKey.js";
|
|
13
|
+
import { findObjectKey as q } from "./object/findObjectKey.js";
|
|
14
|
+
import { objectForEach as E } from "./object/objectForEach.js";
|
|
15
|
+
import { omitObjectProperties as P } from "./object/omitObjectProperties.js";
|
|
16
|
+
import { omitUndefinedObjectValues as U } from "./object/omitUndefinedObjectValues.js";
|
|
17
|
+
import { noop as k } from "./function/noop.js";
|
|
18
|
+
import { debounce as w } from "./function/debounce.js";
|
|
19
|
+
import { throttle as C } from "./function/throttle.js";
|
|
20
|
+
import { asyncify as G } from "./async/asyncify.js";
|
|
21
|
+
import { asyncResult as J } from "./async/asyncResult.js";
|
|
22
|
+
import { sleep as M } from "./async/sleep.js";
|
|
20
23
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
j as arraysIntersection,
|
|
25
|
+
J as asyncResult,
|
|
26
|
+
G as asyncify,
|
|
24
27
|
e as capitalize,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
c as clamp,
|
|
29
|
+
w as debounce,
|
|
30
|
+
q as findObjectKey,
|
|
31
|
+
K as getObjectKey,
|
|
32
|
+
I as groupArrayItems,
|
|
33
|
+
k as noop,
|
|
34
|
+
E as objectForEach,
|
|
35
|
+
P as omitObjectProperties,
|
|
36
|
+
U as omitUndefinedObjectValues,
|
|
37
|
+
A as randomArrayItem,
|
|
38
|
+
s as randomInt,
|
|
34
39
|
f as randomString,
|
|
35
40
|
n as round,
|
|
36
41
|
m as secureString,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
M as sleep,
|
|
43
|
+
b as subtractArrays,
|
|
44
|
+
C as throttle,
|
|
45
|
+
u as uniquify
|
|
40
46
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=(t,e,a)=>Math.min(Math.max(t,e),a);exports.clamp=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
package/dist/number/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=(t=0,n=999999)=>Math.floor(Math.random()*(n-t+1))+t;exports.randomInt=o;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=(t,r={})=>{const{precision:o=0}=r;return Math.round(t*Math.pow(10,o))/Math.pow(10,o)};exports.round=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=(t,n)=>{var e;return(e=Object.entries(t).find(([,i])=>n(i)))==null?void 0:e[0]};exports.findObjectKey=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./findObjectKey.cjs"),n=(e,t)=>r.findObjectKey(e,c=>c===t);exports.getObjectKey=n;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=(e,c)=>{Object.keys(e).forEach(t=>{const o=e[t];c({key:t,value:o})})};exports.objectForEach=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./objectForEach.cjs"),s=(o,t)=>{const e={};return n.objectForEach(o,({key:r,value:i})=>{(Array.isArray(t)?t.some(c=>String(c)===r):String(t)===r)||(e[r]=i)}),e};exports.omitObjectProperties=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./objectForEach.cjs"),i=o=>{const e={};return r.objectForEach(o,({key:c,value:t})=>{t!==void 0&&(e[c]=t)}),e};exports.omitUndefinedObjectValues=i;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=e=>e.charAt(0).toUpperCase()+e.slice(1);exports.capitalize=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../number/randomInt.cjs"),u=require("../array/randomArrayItem.cjs"),d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],i=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],m=["0","1","2","3","4","5","6","7","8","9"],l=["!","#","@","~","$","^",".",",","-","+","%","?","*","="],p={1:d,2:i,3:m,4:l},g=(o={})=>{const{length:n=16}=o;let r="";for(let t=0;t<n;t++){const e=a.randomInt(1,4),s=p[e],c=u.randomArrayItem(s);r+=c}return r};exports.randomString=g;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=(e,n={})=>{const{maxInsecureChars:r=4}=n,t="****";if(!e)return e;const c=Math.min(Math.floor(e.length/2),r),s=e.slice(e.length-c);return`${t}${s}`};exports.secureString=a;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aliexme/js-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Common JavaScript utilities",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Alexander Smirnov <al.smirnov996@gmail.com>",
|
|
@@ -15,8 +15,15 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
-
"main": "./dist/index.
|
|
19
|
-
"
|
|
18
|
+
"main": "./dist/index.cjs",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
20
27
|
"sideEffects": false,
|
|
21
28
|
"publishConfig": {
|
|
22
29
|
"access": "public"
|
|
@@ -25,5 +32,5 @@
|
|
|
25
32
|
"build": "vite build",
|
|
26
33
|
"ts:check": "tsc --noEmit"
|
|
27
34
|
},
|
|
28
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "1b5e61f9119616217f31eaf85d7fafafb197f964"
|
|
29
36
|
}
|