@aliexme/js-utils 1.2.0-alpha.1 → 2.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/dist/async/index.d.ts +1 -0
- package/dist/async/sleep.d.ts +1 -0
- package/dist/async/sleep.js +4 -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/throttle.d.ts +8 -0
- package/dist/function/throttle.js +23 -0
- package/dist/index.js +38 -30
- package/dist/number/clamp.d.ts +1 -0
- package/dist/number/clamp.js +4 -0
- package/dist/number/index.d.ts +1 -0
- package/package.json +2 -2
package/dist/async/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sleep: (ms: number) => Promise<void>;
|
|
@@ -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,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.js
CHANGED
|
@@ -1,38 +1,46 @@
|
|
|
1
1
|
import { capitalize as e } from "./string/capitalize.js";
|
|
2
2
|
import { secureString as m } from "./string/secureString.js";
|
|
3
|
-
import { randomString as
|
|
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 {
|
|
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";
|
|
19
23
|
export {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
j as arraysIntersection,
|
|
25
|
+
J as asyncResult,
|
|
26
|
+
G as asyncify,
|
|
23
27
|
e as capitalize,
|
|
24
|
-
|
|
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,
|
|
39
|
+
f as randomString,
|
|
34
40
|
n as round,
|
|
35
41
|
m as secureString,
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
M as sleep,
|
|
43
|
+
b as subtractArrays,
|
|
44
|
+
C as throttle,
|
|
45
|
+
u as uniquify
|
|
38
46
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
package/dist/number/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aliexme/js-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Common JavaScript utilities",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Alexander Smirnov <al.smirnov996@gmail.com>",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"build": "vite build",
|
|
26
26
|
"ts:check": "tsc --noEmit"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "e00bfc1c4f1f64875f0e2b9c6b8119c5725fc77f"
|
|
29
29
|
}
|