@nemigo/helpers 0.11.4 → 0.11.5
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/cleanup.d.ts +9 -0
- package/dist/cleanup.js +18 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -2
- package/package.json +5 -1
package/dist/cleanup.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class Cleanup {
|
|
2
|
+
calls = [];
|
|
3
|
+
constructor(...args) {
|
|
4
|
+
this.calls = args;
|
|
5
|
+
}
|
|
6
|
+
push(...args) {
|
|
7
|
+
this.calls = this.calls.concat(args);
|
|
8
|
+
}
|
|
9
|
+
run() {
|
|
10
|
+
for (const call of this.calls)
|
|
11
|
+
call();
|
|
12
|
+
this.calls.length = 0;
|
|
13
|
+
}
|
|
14
|
+
update(...args) {
|
|
15
|
+
this.run();
|
|
16
|
+
this.calls = args;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -51,9 +51,10 @@ export declare const useConditionGuard: (condition: unknown, ...args: any[]) =>
|
|
|
51
51
|
/**
|
|
52
52
|
* Сортирует ключи объекта в алфавитном порядке и возвращает новый объект с отсортированными ключами
|
|
53
53
|
*/
|
|
54
|
-
export declare
|
|
54
|
+
export declare const sortObjectByKeys: <T>(obj: T) => T;
|
|
55
55
|
export type BoundaryFallback<E> = E | ((err: unknown) => CanBePromise<E>);
|
|
56
56
|
/**
|
|
57
57
|
* Приведение коллбэка к промису с отловом ошибок и fallback-ом
|
|
58
58
|
*/
|
|
59
59
|
export declare const boundary: <R = undefined, E = R>(call: () => CanBePromise<R>, fallback?: BoundaryFallback<E>) => Promise<R | E>;
|
|
60
|
+
export declare const cleanup: (...args: (() => void)[]) => () => void;
|
package/dist/index.js
CHANGED
|
@@ -60,13 +60,13 @@ export const useConditionGuard = (condition, ...args) => {
|
|
|
60
60
|
/**
|
|
61
61
|
* Сортирует ключи объекта в алфавитном порядке и возвращает новый объект с отсортированными ключами
|
|
62
62
|
*/
|
|
63
|
-
export
|
|
63
|
+
export const sortObjectByKeys = (obj) => {
|
|
64
64
|
const keys = Object.keys(obj).sort();
|
|
65
65
|
const result = {};
|
|
66
66
|
for (const key of keys)
|
|
67
67
|
result[key] = obj[key];
|
|
68
68
|
return result;
|
|
69
|
-
}
|
|
69
|
+
};
|
|
70
70
|
/**
|
|
71
71
|
* Приведение коллбэка к промису с отловом ошибок и fallback-ом
|
|
72
72
|
*/
|
|
@@ -83,3 +83,8 @@ export const boundary = async (call, fallback) => {
|
|
|
83
83
|
return fallback;
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
|
+
//...
|
|
87
|
+
export const cleanup = (...args) => () => {
|
|
88
|
+
for (const call of args)
|
|
89
|
+
call();
|
|
90
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nemigo/helpers",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Vlad Logvin",
|
|
@@ -39,6 +39,10 @@
|
|
|
39
39
|
"types": "./dist/clean.d.ts",
|
|
40
40
|
"default": "./dist/clean.js"
|
|
41
41
|
},
|
|
42
|
+
"./cleanup": {
|
|
43
|
+
"types": "./dist/cleanup.d.ts",
|
|
44
|
+
"default": "./dist/cleanup.js"
|
|
45
|
+
},
|
|
42
46
|
"./cookie": {
|
|
43
47
|
"types": "./dist/cookie.d.ts",
|
|
44
48
|
"default": "./dist/cookie.js"
|