@nemigo/helpers 0.11.3 → 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.
@@ -0,0 +1,9 @@
1
+ type CleanupFunc = () => void;
2
+ export declare class Cleanup {
3
+ private calls;
4
+ constructor(...args: CleanupFunc[]);
5
+ push(...args: CleanupFunc[]): void;
6
+ run(): void;
7
+ update(...args: CleanupFunc[]): void;
8
+ }
9
+ export {};
@@ -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/html.d.ts CHANGED
@@ -37,7 +37,7 @@ export declare const preventStopHook: <T extends Event = Event>(call?: CanBeNull
37
37
  * @param usePreventStop - Условие для вызова {@link preventStop}
38
38
  * @param condition - Условие для вызова основного коллбэка
39
39
  */
40
- export declare const enterKeyHook: <T extends TargetKeyboardEvent = TargetKeyboardEvent>(call?: CanBeNullable<(e: T) => CanBePromise>, { onkeydown, usePreventStop, condition, }?: {
40
+ export declare const enterKeyHook: <T extends KeyboardEvent = KeyboardEvent>(call?: CanBeNullable<(e: T) => CanBePromise>, { onkeydown, usePreventStop, condition, }?: {
41
41
  onkeydown?: (e: T) => void;
42
42
  usePreventStop?: "enter" | unknown | ((e: T, isEnter: boolean) => unknown);
43
43
  condition?: ((e: T) => unknown) | unknown;
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 function sortObjectByKeys<T>(obj: T): T;
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 function sortObjectByKeys(obj) {
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",
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"