@nemigo/helpers 2.8.1 → 2.9.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/aggregator.d.ts +2 -2
- package/dist/aggregator.js +2 -2
- package/dist/async/index.d.ts +1 -1
- package/dist/emitter.js +7 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/promoter.js +3 -1
- package/dist/string.d.ts +4 -0
- package/dist/string.js +10 -0
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
package/dist/aggregator.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CanBePromise } from "./types.js";
|
|
2
|
-
export type AFunc = () => CanBePromise
|
|
1
|
+
import type { CanBeNullable, CanBePromise } from "./types.js";
|
|
2
|
+
export type AFunc = CanBeNullable<() => CanBePromise>;
|
|
3
3
|
/**
|
|
4
4
|
* Aggregator для группового выполнения функций
|
|
5
5
|
*
|
package/dist/aggregator.js
CHANGED
|
@@ -32,12 +32,12 @@ export class Aggregator {
|
|
|
32
32
|
if (promise) {
|
|
33
33
|
return (async () => {
|
|
34
34
|
// oxlint-disable-next-line eslint/require-await
|
|
35
|
-
await Promise.allSettled(this.__calls.map(async (f) => f()));
|
|
35
|
+
await Promise.allSettled(this.__calls.map(async (f) => f?.()));
|
|
36
36
|
this.__calls.length = 0;
|
|
37
37
|
})();
|
|
38
38
|
}
|
|
39
39
|
for (const call of this.__calls)
|
|
40
|
-
void call();
|
|
40
|
+
void call?.();
|
|
41
41
|
this.__calls.length = 0;
|
|
42
42
|
}
|
|
43
43
|
}
|
package/dist/async/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare const useStateGuard: <F extends AnyFunc>(func: F, state: IState<b
|
|
|
39
39
|
* * Аргументы обновляются
|
|
40
40
|
* - `"urgent"`:
|
|
41
41
|
* * Первый вызов исполняется сразу
|
|
42
|
-
* * Повторные вызовы возвращают тот же промис в течение `ms`
|
|
42
|
+
* * Повторные вызовы возвращают тот же промис в течение `ms` (задержка до следующего вызова, без учёта времени на выполнение)
|
|
43
43
|
* * Аргументы обновляются, но не влияют, если функция уже выполняется
|
|
44
44
|
*/
|
|
45
45
|
export type ThrottleMode = "urgent" | "delay";
|
package/dist/emitter.js
CHANGED
|
@@ -6,11 +6,14 @@
|
|
|
6
6
|
export class Emitter {
|
|
7
7
|
__listeners = new Map();
|
|
8
8
|
dispatch(event, data) {
|
|
9
|
-
for (const [key, handler] of this.__listeners.entries()) {
|
|
10
|
-
if (
|
|
9
|
+
for (const [key, handler] of Array.from(this.__listeners.entries())) {
|
|
10
|
+
if (!this.__listeners.has(key))
|
|
11
|
+
continue; // мог быть снят другим хендлером
|
|
12
|
+
if (handler.event === event) {
|
|
11
13
|
handler.callback(data);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
if (handler.once)
|
|
15
|
+
this.__listeners.delete(key);
|
|
16
|
+
}
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyFunc } from "./types.js";
|
|
1
|
+
import type { AnyFunc, CanBeNullable, CanBePromise } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Преобразует число в строку, добавляя ведущие нули для достижения указанной длины
|
|
4
4
|
*
|
|
@@ -17,7 +17,7 @@ export declare const parsify: <T>(v: T) => T;
|
|
|
17
17
|
/**
|
|
18
18
|
* Агрегация функций в одну
|
|
19
19
|
*/
|
|
20
|
-
export declare const aggregate: (...args: (
|
|
20
|
+
export declare const aggregate: (...args: CanBeNullable<() => CanBePromise>[]) => (() => void);
|
|
21
21
|
/**
|
|
22
22
|
* Проверяет, является ли значение объектом
|
|
23
23
|
*
|
package/dist/index.js
CHANGED
package/dist/promoter.js
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
export class Promoter {
|
|
5
5
|
__subs = new Map();
|
|
6
6
|
notify(event) {
|
|
7
|
-
for (const [key, { callback, once }] of this.__subs.entries()) {
|
|
7
|
+
for (const [key, { callback, once }] of Array.from(this.__subs.entries())) {
|
|
8
|
+
if (!this.__subs.has(key))
|
|
9
|
+
continue; // мог быть снят другим хендлером
|
|
8
10
|
callback(event);
|
|
9
11
|
if (once)
|
|
10
12
|
this.__subs.delete(key);
|
package/dist/string.d.ts
CHANGED
|
@@ -101,3 +101,7 @@ export declare const toCapitalCaseMap: (str?: string) => string;
|
|
|
101
101
|
* ```
|
|
102
102
|
*/
|
|
103
103
|
export declare const repeat: (str: string, length: number, separator?: string) => string;
|
|
104
|
+
/**
|
|
105
|
+
* Создает на основе строки UUID по DJB2
|
|
106
|
+
*/
|
|
107
|
+
export declare const toUUID: (key: string) => string;
|
package/dist/string.js
CHANGED
|
@@ -101,3 +101,13 @@ export const toCapitalCaseMap = (str = "") => str.split(" ").map(toCapitalCase).
|
|
|
101
101
|
* ```
|
|
102
102
|
*/
|
|
103
103
|
export const repeat = (str, length, separator = "") => Array.from({ length }).fill(str).join(separator);
|
|
104
|
+
/**
|
|
105
|
+
* Создает на основе строки UUID по DJB2
|
|
106
|
+
*/
|
|
107
|
+
export const toUUID = (key) => {
|
|
108
|
+
let hash = 5381; // DJB2
|
|
109
|
+
for (let i = 0; i < key.length; i++)
|
|
110
|
+
hash = ((hash << 5) + hash) ^ (key.codePointAt(i) ?? 0);
|
|
111
|
+
const hex = Math.trunc(hash).toString(16).padStart(8, "0");
|
|
112
|
+
return `${hex}-0000-0000-0000-000000000000`;
|
|
113
|
+
};
|
package/dist/types.d.ts
CHANGED
|
@@ -152,6 +152,12 @@ export type Exist<T> = Exclude<T, undefined>;
|
|
|
152
152
|
* ```
|
|
153
153
|
*/
|
|
154
154
|
export type KEYS<O> = keyof O extends infer Key ? (Key extends string ? Key : never) : never;
|
|
155
|
+
/**
|
|
156
|
+
* Убирает все never-значения из объекта
|
|
157
|
+
*/
|
|
158
|
+
export type NeverKeysFilterType<T> = {
|
|
159
|
+
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
160
|
+
};
|
|
155
161
|
/**
|
|
156
162
|
* Примитив для всех записей с идентификатором
|
|
157
163
|
*/
|