@aliexme/js-utils 2.4.1 → 3.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/dist/array/arraysIntersection.js +8 -10
- package/dist/array/groupArrayItems.js +9 -9
- package/dist/array/randomArrayItem.js +4 -7
- package/dist/array/subtractArrays.js +8 -8
- package/dist/array/uniquify.js +4 -4
- package/dist/async/asyncResult.js +5 -5
- package/dist/async/asyncify.js +5 -5
- package/dist/async/sleep.js +4 -4
- package/dist/function/debounce.js +23 -25
- package/dist/function/noop.js +4 -5
- package/dist/function/throttle.js +20 -22
- package/dist/index.js +24 -50
- package/dist/number/clamp.js +4 -4
- package/dist/number/floor.js +4 -4
- package/dist/number/lerp.js +4 -4
- package/dist/number/randomInt.js +5 -5
- package/dist/number/randomNumber.js +6 -6
- package/dist/number/round.js +4 -4
- package/dist/object/findObjectKey.js +4 -4
- package/dist/object/getObjectKey.js +5 -5
- package/dist/object/objectForEach.js +11 -8
- package/dist/object/omitObjectProperties.js +9 -9
- package/dist/object/omitUndefinedObjectValues.js +9 -9
- package/dist/string/capitalize.js +4 -4
- package/dist/string/randomString.js +43 -18
- package/dist/string/secureString.js +8 -9
- package/package.json +4 -7
- package/dist/array/arraysIntersection.cjs +0 -1
- package/dist/array/groupArrayItems.cjs +0 -1
- package/dist/array/randomArrayItem.cjs +0 -1
- package/dist/array/subtractArrays.cjs +0 -1
- package/dist/array/uniquify.cjs +0 -1
- package/dist/async/asyncResult.cjs +0 -1
- package/dist/async/asyncify.cjs +0 -1
- package/dist/async/sleep.cjs +0 -1
- package/dist/function/debounce.cjs +0 -1
- package/dist/function/noop.cjs +0 -1
- package/dist/function/throttle.cjs +0 -1
- package/dist/index.cjs +0 -1
- package/dist/number/clamp.cjs +0 -1
- package/dist/number/floor.cjs +0 -1
- package/dist/number/lerp.cjs +0 -1
- package/dist/number/randomInt.cjs +0 -1
- package/dist/number/randomNumber.cjs +0 -1
- package/dist/number/round.cjs +0 -1
- package/dist/object/findObjectKey.cjs +0 -1
- package/dist/object/getObjectKey.cjs +0 -1
- package/dist/object/objectForEach.cjs +0 -1
- package/dist/object/omitObjectProperties.cjs +0 -1
- package/dist/object/omitUndefinedObjectValues.cjs +0 -1
- package/dist/string/capitalize.cjs +0 -1
- package/dist/string/randomString.cjs +0 -1
- package/dist/string/secureString.cjs +0 -1
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return Array.from(e);
|
|
1
|
+
//#region src/array/arraysIntersection.ts
|
|
2
|
+
function e(e, t, ...n) {
|
|
3
|
+
if (e.length === 0 || t.length === 0 || n.some((e) => e.length === 0)) return [];
|
|
4
|
+
let r = new Set(e), i = [t, ...n];
|
|
5
|
+
for (let e of i) for (let t of r) e.includes(t) || r.delete(t);
|
|
6
|
+
return Array.from(r);
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { e as arraysIntersection };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export {
|
|
9
|
-
n as groupArrayItems
|
|
1
|
+
//#region src/array/groupArrayItems.ts
|
|
2
|
+
var e = (e, t) => {
|
|
3
|
+
let n = {};
|
|
4
|
+
return e.forEach((e) => {
|
|
5
|
+
let r = e[t], i = n[r];
|
|
6
|
+
i ? i.push(e) : n[r] = [e];
|
|
7
|
+
}), n;
|
|
10
8
|
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { e as groupArrayItems };
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
export {
|
|
6
|
-
t as randomArrayItem
|
|
7
|
-
};
|
|
1
|
+
//#region src/array/randomArrayItem.ts
|
|
2
|
+
var e = (e) => e[Math.floor(Math.random() * e.length)];
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as randomArrayItem };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region src/array/subtractArrays.ts
|
|
2
|
+
function e(e, t, ...n) {
|
|
3
|
+
if (e.length === 0) return [];
|
|
4
|
+
if (t.length === 0) return [...e];
|
|
5
|
+
let r = [t, ...n], i = new Set(r.flat());
|
|
6
|
+
return e.filter((e) => !i.has(e));
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { e as subtractArrays };
|
package/dist/array/uniquify.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
//#region src/array/uniquify.ts
|
|
2
|
+
var e = (e) => [...new Set(e)];
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as uniquify };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { asyncify as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
1
|
+
import { asyncify as e } from "./asyncify.js";
|
|
2
|
+
//#region src/async/asyncResult.ts
|
|
3
|
+
var t = (t) => e(t)();
|
|
4
|
+
//#endregion
|
|
5
|
+
export { t as asyncResult };
|
package/dist/async/asyncify.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/async/asyncify.ts
|
|
2
|
+
var e = (e) => (...t) => new Promise((n) => {
|
|
3
|
+
setTimeout(() => n(e(...t)), 0);
|
|
3
4
|
});
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
5
|
+
//#endregion
|
|
6
|
+
export { e as asyncify };
|
package/dist/async/sleep.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
//#region src/async/sleep.ts
|
|
2
|
+
var e = async (e) => new Promise((t) => setTimeout(t, e));
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as sleep };
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import { clamp as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return s.cancel = T, s;
|
|
23
|
-
};
|
|
24
|
-
export {
|
|
25
|
-
p as debounce
|
|
1
|
+
import { clamp as e } from "../number/clamp.js";
|
|
2
|
+
//#region src/function/debounce.ts
|
|
3
|
+
var t = (t, n, r = {}) => {
|
|
4
|
+
let { maxWait: i, withLeading: a = !1 } = r, o = null, s = null, c = () => {
|
|
5
|
+
o !== null && (clearTimeout(o), o = null);
|
|
6
|
+
}, l = () => {
|
|
7
|
+
s = null;
|
|
8
|
+
}, u = () => {
|
|
9
|
+
c(), l();
|
|
10
|
+
}, d = (...r) => {
|
|
11
|
+
c();
|
|
12
|
+
let u = Date.now(), d = s ? u - s : 0, f = i ? e(i - d, 0, n) : n;
|
|
13
|
+
if (!s && (s = u, a)) {
|
|
14
|
+
t(...r), o = setTimeout(l, f);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
o = setTimeout(() => {
|
|
18
|
+
t(...r), l();
|
|
19
|
+
}, f);
|
|
20
|
+
};
|
|
21
|
+
return d.cancel = u, d;
|
|
26
22
|
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { t as debounce };
|
package/dist/function/noop.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
};
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
1
|
+
//#region src/function/noop.ts
|
|
2
|
+
var e = () => {};
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as noop };
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return i.cancel = a, i;
|
|
20
|
-
};
|
|
21
|
-
export {
|
|
22
|
-
f as throttle
|
|
1
|
+
//#region src/function/throttle.ts
|
|
2
|
+
var e = (e, t, n = {}) => {
|
|
3
|
+
let { withTrailing: r = !1 } = n, i = null, a = null, o = !1, s = () => {
|
|
4
|
+
i !== null && (clearTimeout(i), i = null);
|
|
5
|
+
}, c = () => {
|
|
6
|
+
a !== null && (clearTimeout(a), a = null);
|
|
7
|
+
}, l = () => {
|
|
8
|
+
o = !1;
|
|
9
|
+
}, u = () => {
|
|
10
|
+
s(), c(), l();
|
|
11
|
+
}, d = (...n) => {
|
|
12
|
+
if (o) {
|
|
13
|
+
r && (s(), i = setTimeout(() => e(...n), t));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
s(), e(...n), o = !0, a = setTimeout(l, t);
|
|
17
|
+
};
|
|
18
|
+
return d.cancel = u, d;
|
|
23
19
|
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { e as throttle };
|
package/dist/index.js
CHANGED
|
@@ -1,52 +1,26 @@
|
|
|
1
1
|
import { arraysIntersection as e } from "./array/arraysIntersection.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { groupArrayItems as t } from "./array/groupArrayItems.js";
|
|
3
|
+
import { randomArrayItem as n } from "./array/randomArrayItem.js";
|
|
4
|
+
import { subtractArrays as r } from "./array/subtractArrays.js";
|
|
5
|
+
import { uniquify as i } from "./array/uniquify.js";
|
|
6
|
+
import { asyncify as a } from "./async/asyncify.js";
|
|
7
|
+
import { asyncResult as o } from "./async/asyncResult.js";
|
|
8
|
+
import { sleep as s } from "./async/sleep.js";
|
|
5
9
|
import { clamp as c } from "./number/clamp.js";
|
|
6
|
-
import { debounce as
|
|
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 {
|
|
20
|
-
import {
|
|
21
|
-
import { secureString as
|
|
22
|
-
|
|
23
|
-
import { subtractArrays as Q } from "./array/subtractArrays.js";
|
|
24
|
-
import { throttle as W } from "./function/throttle.js";
|
|
25
|
-
import { uniquify as Y } from "./array/uniquify.js";
|
|
26
|
-
export {
|
|
27
|
-
e as arraysIntersection,
|
|
28
|
-
m as asyncResult,
|
|
29
|
-
f as asyncify,
|
|
30
|
-
n as capitalize,
|
|
31
|
-
c as clamp,
|
|
32
|
-
s as debounce,
|
|
33
|
-
y as findObjectKey,
|
|
34
|
-
b as floor,
|
|
35
|
-
j as getObjectKey,
|
|
36
|
-
I as groupArrayItems,
|
|
37
|
-
A as lerp,
|
|
38
|
-
K as noop,
|
|
39
|
-
q as objectForEach,
|
|
40
|
-
E as omitObjectProperties,
|
|
41
|
-
N as omitUndefinedObjectValues,
|
|
42
|
-
R as randomArrayItem,
|
|
43
|
-
V as randomInt,
|
|
44
|
-
v as randomNumber,
|
|
45
|
-
B as randomString,
|
|
46
|
-
D as round,
|
|
47
|
-
H as secureString,
|
|
48
|
-
L as sleep,
|
|
49
|
-
Q as subtractArrays,
|
|
50
|
-
W as throttle,
|
|
51
|
-
Y as uniquify
|
|
52
|
-
};
|
|
10
|
+
import { debounce as l } from "./function/debounce.js";
|
|
11
|
+
import { noop as u } from "./function/noop.js";
|
|
12
|
+
import { throttle as d } from "./function/throttle.js";
|
|
13
|
+
import { floor as f } from "./number/floor.js";
|
|
14
|
+
import { lerp as p } from "./number/lerp.js";
|
|
15
|
+
import { randomNumber as m } from "./number/randomNumber.js";
|
|
16
|
+
import { randomInt as h } from "./number/randomInt.js";
|
|
17
|
+
import { round as g } from "./number/round.js";
|
|
18
|
+
import { findObjectKey as _ } from "./object/findObjectKey.js";
|
|
19
|
+
import { getObjectKey as v } from "./object/getObjectKey.js";
|
|
20
|
+
import { objectForEach as y } from "./object/objectForEach.js";
|
|
21
|
+
import { omitObjectProperties as b } from "./object/omitObjectProperties.js";
|
|
22
|
+
import { omitUndefinedObjectValues as x } from "./object/omitUndefinedObjectValues.js";
|
|
23
|
+
import { capitalize as S } from "./string/capitalize.js";
|
|
24
|
+
import { randomString as C } from "./string/randomString.js";
|
|
25
|
+
import { secureString as w } from "./string/secureString.js";
|
|
26
|
+
export { e as arraysIntersection, o as asyncResult, a as asyncify, S as capitalize, c as clamp, l as debounce, _ as findObjectKey, f as floor, v as getObjectKey, t as groupArrayItems, p as lerp, u as noop, y as objectForEach, b as omitObjectProperties, x as omitUndefinedObjectValues, n as randomArrayItem, h as randomInt, m as randomNumber, C as randomString, g as round, w as secureString, s as sleep, r as subtractArrays, d as throttle, i as uniquify };
|
package/dist/number/clamp.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
//#region src/number/clamp.ts
|
|
2
|
+
var e = (e, t, n) => Math.min(Math.max(e, t), n);
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as clamp };
|
package/dist/number/floor.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
//#region src/number/floor.ts
|
|
2
|
+
var e = (e, t = 0) => Math.floor(e * 10 ** t) / 10 ** t;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as floor };
|
package/dist/number/lerp.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
//#region src/number/lerp.ts
|
|
2
|
+
var e = (e, t, n) => (1 - n) * e + n * t;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as lerp };
|
package/dist/number/randomInt.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { randomNumber as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
1
|
+
import { randomNumber as e } from "./randomNumber.js";
|
|
2
|
+
//#region src/number/randomInt.ts
|
|
3
|
+
var t = (t = 0, n = 999999) => e(t, n, { precision: 0 });
|
|
4
|
+
//#endregion
|
|
5
|
+
export { t as randomInt };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { floor as e } from "./floor.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
a as randomNumber
|
|
2
|
+
//#region src/number/randomNumber.ts
|
|
3
|
+
var t = (t = 0, n = 999999, r = {}) => {
|
|
4
|
+
let { precision: i = 2 } = r;
|
|
5
|
+
return e(Math.random() * (n - t + 1), i) + t;
|
|
8
6
|
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { t as randomNumber };
|
package/dist/number/round.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
//#region src/number/round.ts
|
|
2
|
+
var e = (e, t = 0) => Math.round(e * 10 ** t) / 10 ** t;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as round };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
//#region src/object/findObjectKey.ts
|
|
2
|
+
var e = (e, t) => Object.entries(e).find(([, e]) => t(e))?.[0];
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as findObjectKey };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { findObjectKey as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
1
|
+
import { findObjectKey as e } from "./findObjectKey.js";
|
|
2
|
+
//#region src/object/getObjectKey.ts
|
|
3
|
+
var t = (t, n) => e(t, (e) => e === n);
|
|
4
|
+
//#endregion
|
|
5
|
+
export { t as getObjectKey };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//#region src/object/objectForEach.ts
|
|
2
|
+
var e = (e, t) => {
|
|
3
|
+
Object.keys(e).forEach((n) => {
|
|
4
|
+
let r = e[n];
|
|
5
|
+
t({
|
|
6
|
+
key: n,
|
|
7
|
+
value: r
|
|
8
|
+
});
|
|
9
|
+
});
|
|
9
10
|
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { e as objectForEach };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { objectForEach as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export {
|
|
9
|
-
a as omitObjectProperties
|
|
1
|
+
import { objectForEach as e } from "./objectForEach.js";
|
|
2
|
+
//#region src/object/omitObjectProperties.ts
|
|
3
|
+
var t = (t, n) => {
|
|
4
|
+
let r = {};
|
|
5
|
+
return e(t, ({ key: e, value: t }) => {
|
|
6
|
+
(Array.isArray(n) ? n.some((t) => String(t) === e) : String(n) === e) || (r[e] = t);
|
|
7
|
+
}), r;
|
|
10
8
|
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { t as omitObjectProperties };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { objectForEach as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export {
|
|
9
|
-
n as omitUndefinedObjectValues
|
|
1
|
+
import { objectForEach as e } from "./objectForEach.js";
|
|
2
|
+
//#region src/object/omitUndefinedObjectValues.ts
|
|
3
|
+
var t = (t) => {
|
|
4
|
+
let n = {};
|
|
5
|
+
return e(t, ({ key: e, value: t }) => {
|
|
6
|
+
t !== void 0 && (n[e] = t);
|
|
7
|
+
}), n;
|
|
10
8
|
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { t as omitUndefinedObjectValues };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
//#region src/string/capitalize.ts
|
|
2
|
+
var e = (e) => e.charAt(0).toUpperCase() + e.slice(1);
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as capitalize };
|
|
@@ -1,19 +1,44 @@
|
|
|
1
|
-
import { randomArrayItem as
|
|
2
|
-
import { randomInt as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { randomArrayItem as e } from "../array/randomArrayItem.js";
|
|
2
|
+
import { randomInt as t } from "../number/randomInt.js";
|
|
3
|
+
//#region src/string/randomString.ts
|
|
4
|
+
var n = {
|
|
5
|
+
1: /* @__PURE__ */ "abcdefghijklmnopqrstuvwxyz".split(""),
|
|
6
|
+
2: /* @__PURE__ */ "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),
|
|
7
|
+
3: [
|
|
8
|
+
"0",
|
|
9
|
+
"1",
|
|
10
|
+
"2",
|
|
11
|
+
"3",
|
|
12
|
+
"4",
|
|
13
|
+
"5",
|
|
14
|
+
"6",
|
|
15
|
+
"7",
|
|
16
|
+
"8",
|
|
17
|
+
"9"
|
|
18
|
+
],
|
|
19
|
+
4: [
|
|
20
|
+
"!",
|
|
21
|
+
"#",
|
|
22
|
+
"@",
|
|
23
|
+
"~",
|
|
24
|
+
"$",
|
|
25
|
+
"^",
|
|
26
|
+
".",
|
|
27
|
+
",",
|
|
28
|
+
"-",
|
|
29
|
+
"+",
|
|
30
|
+
"%",
|
|
31
|
+
"?",
|
|
32
|
+
"*",
|
|
33
|
+
"="
|
|
34
|
+
]
|
|
35
|
+
}, r = (r = {}) => {
|
|
36
|
+
let { length: i = 16 } = r, a = "";
|
|
37
|
+
for (let r = 0; r < i; r++) {
|
|
38
|
+
let r = n[t(1, 4)], i = e(r);
|
|
39
|
+
a += i;
|
|
40
|
+
}
|
|
41
|
+
return a;
|
|
19
42
|
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { r as randomString };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export {
|
|
9
|
-
s as secureString
|
|
1
|
+
//#region src/string/secureString.ts
|
|
2
|
+
var e = (e, t = {}) => {
|
|
3
|
+
let { maxInsecureChars: n = 4 } = t;
|
|
4
|
+
if (!e) return e;
|
|
5
|
+
let r = Math.min(Math.floor(e.length / 2), n);
|
|
6
|
+
return `****${e.slice(e.length - r)}`;
|
|
10
7
|
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { e as secureString };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aliexme/js-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Common JavaScript utilities",
|
|
6
6
|
"homepage": "https://github.com/aliexme/web-shared/tree/main/packages/js-utils",
|
|
@@ -14,12 +14,9 @@
|
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
|
-
".":
|
|
18
|
-
"import": "./dist/index.js",
|
|
19
|
-
"require": "./dist/index.cjs"
|
|
20
|
-
}
|
|
17
|
+
".": "./dist/index.js"
|
|
21
18
|
},
|
|
22
|
-
"main": "./dist/index.
|
|
19
|
+
"main": "./dist/index.js",
|
|
23
20
|
"module": "./dist/index.js",
|
|
24
21
|
"types": "./dist/index.d.ts",
|
|
25
22
|
"files": [
|
|
@@ -32,5 +29,5 @@
|
|
|
32
29
|
"publishConfig": {
|
|
33
30
|
"access": "public"
|
|
34
31
|
},
|
|
35
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "c32af348e1669e9dca51811a810abff6ba7de279"
|
|
36
33
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function c(n,o,...r){if(n.length===0||o.length===0||r.some(t=>t.length===0))return[];const e=new Set(n),s=[o,...r];for(const t of s)for(const i of e)t.includes(i)||e.delete(i);return Array.from(e)}exports.arraysIntersection=c;
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function c(t,e,...r){if(t.length===0)return[];if(e.length===0)return[...t];const n=[e,...r],s=new Set(n.flat());return t.filter(u=>!s.has(u))}exports.subtractArrays=c;
|
package/dist/array/uniquify.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=e=>[...new Set(e)];exports.uniquify=t;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./asyncify.cjs"),e=n=>s.asyncify(n)();exports.asyncResult=e;
|
package/dist/async/asyncify.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;
|
package/dist/async/sleep.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=async e=>new Promise(t=>setTimeout(t,e));exports.sleep=s;
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
package/dist/function/noop.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=()=>{};exports.noop=o;
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./array/arraysIntersection.cjs"),r=require("./async/asyncResult.cjs"),t=require("./async/asyncify.cjs"),o=require("./string/capitalize.cjs"),n=require("./number/clamp.cjs"),c=require("./function/debounce.cjs"),i=require("./object/findObjectKey.cjs"),s=require("./number/floor.cjs"),u=require("./object/getObjectKey.cjs"),a=require("./array/groupArrayItems.cjs"),y=require("./number/lerp.cjs"),m=require("./function/noop.cjs"),d=require("./object/objectForEach.cjs"),q=require("./object/omitObjectProperties.cjs"),l=require("./object/omitUndefinedObjectValues.cjs"),b=require("./array/randomArrayItem.cjs"),p=require("./number/randomInt.cjs"),f=require("./number/randomNumber.cjs"),j=require("./string/randomString.cjs"),g=require("./number/round.cjs"),O=require("./string/secureString.cjs"),I=require("./async/sleep.cjs"),A=require("./array/subtractArrays.cjs"),S=require("./function/throttle.cjs"),h=require("./array/uniquify.cjs");exports.arraysIntersection=e.arraysIntersection;exports.asyncResult=r.asyncResult;exports.asyncify=t.asyncify;exports.capitalize=o.capitalize;exports.clamp=n.clamp;exports.debounce=c.debounce;exports.findObjectKey=i.findObjectKey;exports.floor=s.floor;exports.getObjectKey=u.getObjectKey;exports.groupArrayItems=a.groupArrayItems;exports.lerp=y.lerp;exports.noop=m.noop;exports.objectForEach=d.objectForEach;exports.omitObjectProperties=q.omitObjectProperties;exports.omitUndefinedObjectValues=l.omitUndefinedObjectValues;exports.randomArrayItem=b.randomArrayItem;exports.randomInt=p.randomInt;exports.randomNumber=f.randomNumber;exports.randomString=j.randomString;exports.round=g.round;exports.secureString=O.secureString;exports.sleep=I.sleep;exports.subtractArrays=A.subtractArrays;exports.throttle=S.throttle;exports.uniquify=h.uniquify;
|
package/dist/number/clamp.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;
|
package/dist/number/floor.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=(t,o=0)=>Math.floor(t*10**o)/10**o;exports.floor=r;
|
package/dist/number/lerp.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=(r,t,e)=>(1-e)*r+e*t;exports.lerp=o;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./randomNumber.cjs"),o=(r=0,e=999999)=>n.randomNumber(r,e,{precision:0});exports.randomInt=o;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./floor.cjs"),u=(r=0,o=999999,e={})=>{const{precision:t=2}=e;return n.floor(Math.random()*(o-r+1),t)+r};exports.randomNumber=u;
|
package/dist/number/round.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=(r,t=0)=>Math.round(r*10**t)/10**t;exports.round=e;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=(e,t)=>Object.entries(e).find(([,n])=>t(n))?.[0];exports.findObjectKey=i;
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=e=>e.charAt(0).toUpperCase()+e.slice(1);exports.capitalize=t;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../array/randomArrayItem.cjs"),u=require("../number/randomInt.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=u.randomInt(1,4),s=p[e],c=a.randomArrayItem(s);r+=c}return r};exports.randomString=g;
|
|
@@ -1 +0,0 @@
|
|
|
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;
|