@nemigo/helpers 2.2.0 → 2.2.2

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.
@@ -14,7 +14,7 @@ export type QueueHandler<T> = (item: T, abort: () => void) => CanBePromise;
14
14
  * const queue = new Queue(async (url, abort) => {
15
15
  * try {
16
16
  * await fetch(url);
17
- * } catch (e) {
17
+ * } catch {
18
18
  * abort(); // прекращает обработку оставшихся URL
19
19
  * }
20
20
  * }, 50);
@@ -12,7 +12,7 @@
12
12
  * const queue = new Queue(async (url, abort) => {
13
13
  * try {
14
14
  * await fetch(url);
15
- * } catch (e) {
15
+ * } catch {
16
16
  * abort(); // прекращает обработку оставшихся URL
17
17
  * }
18
18
  * }, 50);
package/dist/emitter.js CHANGED
@@ -6,14 +6,12 @@
6
6
  export class Emitter {
7
7
  __listeners = new Map();
8
8
  dispatch(event, data) {
9
- // oxlint-disable-next-line unicorn/no-array-for-each
10
- // eslint-disable-next-line unicorn/no-array-for-each
11
- this.__listeners.forEach((handler, key) => {
9
+ for (const [key, handler] of this.__listeners.entries()) {
12
10
  if (event === handler.event)
13
11
  handler.callback(data);
14
12
  if (handler.once)
15
13
  this.__listeners.delete(key);
16
- });
14
+ }
17
15
  }
18
16
  /**
19
17
  * @param event - Ключ события
package/dist/mutate.js CHANGED
@@ -78,9 +78,7 @@ export const deepMutateArray = (source, target) => {
78
78
  source.splice(target.length, source.length - target.length);
79
79
  }
80
80
  // Обновление элементов
81
- // oxlint-disable-next-line unicorn/no-array-for-each
82
- // eslint-disable-next-line unicorn/no-array-for-each
83
- target.forEach((targetItem, index) => {
81
+ for (const [index, targetItem] of target.entries()) {
84
82
  const sourceItem = source[index];
85
83
  if (Array.isArray(targetItem)) {
86
84
  if (!Array.isArray(sourceItem))
@@ -95,7 +93,7 @@ export const deepMutateArray = (source, target) => {
95
93
  else if (sourceItem !== targetItem) {
96
94
  source[index] = targetItem;
97
95
  }
98
- });
96
+ }
99
97
  // Добавление новых элементов
100
98
  while (source.length < target.length) {
101
99
  source.push(target[source.length]);
package/dist/omitter.js CHANGED
@@ -41,18 +41,14 @@ export class Omitter {
41
41
  const keys = Object.keys(obj);
42
42
  if (schema < keys.length) {
43
43
  // Стратегия по схеме: итерируемся по ключам схемы
44
- // oxlint-disable-next-line unicorn/no-array-for-each
45
- // eslint-disable-next-line unicorn/no-array-for-each
46
- structure.keys.forEach((key) => {
44
+ for (const key of structure.keys) {
47
45
  delete obj[key];
48
- });
49
- // oxlint-disable-next-line unicorn/no-array-for-each
50
- // eslint-disable-next-line unicorn/no-array-for-each
51
- structure.nested.forEach((omitter, key) => {
46
+ }
47
+ for (const [key, omitter] of structure.nested.entries()) {
52
48
  const nested = obj[key];
53
49
  if (nested && typeof nested === "object")
54
50
  omitter.#process(nested, omitter.__structure);
55
- });
51
+ }
56
52
  }
57
53
  else {
58
54
  // Стратегия по объекту: итерируемся по ключам объекта
package/dist/promoter.js CHANGED
@@ -4,13 +4,11 @@
4
4
  export class Promoter {
5
5
  __subs = new Map();
6
6
  notify(event) {
7
- // oxlint-disable-next-line unicorn/no-array-for-each
8
- // eslint-disable-next-line unicorn/no-array-for-each
9
- this.__subs.forEach(({ callback, once }, key) => {
7
+ for (const [key, { callback, once }] of this.__subs.entries()) {
10
8
  callback(event);
11
9
  if (once)
12
10
  this.__subs.delete(key);
13
- });
11
+ }
14
12
  }
15
13
  /**
16
14
  * @param callback - Функция подписчика
package/dist/script.js CHANGED
@@ -1,3 +1,5 @@
1
+ /* eslint-disable no-console */
2
+ // oxlint-disable no-console
1
3
  import { exec } from "node:child_process";
2
4
  import { MS_IN_MINUTE } from "./datetime/delta.js";
3
5
  /**
@@ -60,8 +62,6 @@ export { getProcessFlag };
60
62
  * ```
61
63
  */
62
64
  export const execute = (path, command, { logger = {}, timeout = 5 * MS_IN_MINUTE } = {}) => new Promise((resolve, reject) => {
63
- // oxlint-disable-next-line no-console
64
- // eslint-disable-next-line no-console
65
65
  if (logger.before)
66
66
  console.log(logger.before(path));
67
67
  let process = null;
@@ -75,8 +75,6 @@ export const execute = (path, command, { logger = {}, timeout = 5 * MS_IN_MINUTE
75
75
  if (timeout) {
76
76
  timer = setTimeout(() => {
77
77
  process?.kill("SIGTERM");
78
- // oxlint-disable-next-line no-console
79
- // eslint-disable-next-line no-console
80
78
  if (logger.ontimeout)
81
79
  console.error(logger.ontimeout());
82
80
  reject(new Error("TIMEOUT"));
@@ -84,17 +82,11 @@ export const execute = (path, command, { logger = {}, timeout = 5 * MS_IN_MINUTE
84
82
  }
85
83
  process = exec(command, { cwd: path }, (error, stdout, stderr) => {
86
84
  cleanup();
87
- // oxlint-disable-next-line no-console
88
- // eslint-disable-next-line no-console
89
85
  if (stderr)
90
86
  console.warn(stderr);
91
- // oxlint-disable-next-line no-console
92
- // eslint-disable-next-line no-console
93
87
  if (stdout)
94
88
  console.log(stdout);
95
89
  if (error) {
96
- // oxlint-disable-next-line no-console
97
- // eslint-disable-next-line no-console
98
90
  if (logger.onerror)
99
91
  console.error(logger.onerror(error));
100
92
  reject(error);
package/dist/veil.d.ts CHANGED
@@ -1,10 +1,18 @@
1
1
  import type { Serializable } from "./types.js";
2
+ /**
3
+ * Декодирует строку, закодированную функцией {@link veil} в сериализованное значение
4
+ */
5
+ export declare const __unveil: (veiled: string) => string;
2
6
  /**
3
7
  * Декодирует строку, закодированную функцией {@link veil}, в исходное значение и десериализует
4
8
  *
5
9
  * @remarks Для десериализации используется {@link JSON.parse}
6
10
  */
7
11
  export declare const unveil: <T = string>(veiled: string) => T;
12
+ /**
13
+ * Кодирует сериализованное в URL-safe base64-строку
14
+ */
15
+ export declare const __veil: (data: string) => string;
8
16
  /**
9
17
  * Кодирует serializable-значение в URL-safe base64-строку
10
18
  *
package/dist/veil.js CHANGED
@@ -1,26 +1,34 @@
1
- const encoder = new TextEncoder();
2
1
  const decoder = new TextDecoder();
3
2
  /**
4
- * Декодирует строку, закодированную функцией {@link veil}, в исходное значение и десериализует
5
- *
6
- * @remarks Для десериализации используется {@link JSON.parse}
3
+ * Декодирует строку, закодированную функцией {@link veil} в сериализованное значение
7
4
  */
8
- export const unveil = (veiled) => {
5
+ export const __unveil = (veiled) => {
9
6
  const decoded = atob(decodeURIComponent(veiled));
10
7
  const bytes = new Uint8Array(decoded.length);
11
8
  for (let i = 0; i < decoded.length; i++)
12
9
  bytes[i] = decoded.codePointAt(i);
13
- return JSON.parse(decoder.decode(bytes));
10
+ return decoder.decode(bytes);
14
11
  };
15
12
  /**
16
- * Кодирует serializable-значение в URL-safe base64-строку
13
+ * Декодирует строку, закодированную функцией {@link veil}, в исходное значение и десериализует
17
14
  *
18
- * @remarks Для сериализации используется {@link JSON.stringify}
19
- * @remarks Поддерживает полный Unicode, включая смайлики и символы вне BMP
15
+ * @remarks Для десериализации используется {@link JSON.parse}
20
16
  */
21
- export const veil = (snap) => {
22
- const str = JSON.stringify(snap);
23
- const bytes = encoder.encode(str);
17
+ export const unveil = (veiled) => JSON.parse(__unveil(veiled));
18
+ //...
19
+ const encoder = new TextEncoder();
20
+ /**
21
+ * Кодирует сериализованное в URL-safe base64-строку
22
+ */
23
+ export const __veil = (data) => {
24
+ const bytes = encoder.encode(data);
24
25
  const binary = String.fromCodePoint(...bytes);
25
26
  return encodeURIComponent(btoa(binary));
26
27
  };
28
+ /**
29
+ * Кодирует serializable-значение в URL-safe base64-строку
30
+ *
31
+ * @remarks Для сериализации используется {@link JSON.stringify}
32
+ * @remarks Поддерживает полный Unicode, включая смайлики и символы вне BMP
33
+ */
34
+ export const veil = (snap) => __veil(JSON.stringify(snap));
package/dist/xod.d.ts CHANGED
@@ -244,4 +244,3 @@ export declare const xod: {
244
244
  height: typeof numberStrictSchema;
245
245
  }, z.core.$strip>]>;
246
246
  };
247
- export default xod;
package/dist/xod.js CHANGED
@@ -239,5 +239,3 @@ export const xod = {
239
239
  lwhStrict: lwhStrictSchema,
240
240
  lwhStrictOptional: lwhStrictSchemaOptional,
241
241
  };
242
- // oxlint-disable-next-line import/no-default-export
243
- export default xod;
package/dist/zipper.d.ts CHANGED
@@ -6,14 +6,18 @@ export type ZIP = string;
6
6
  /**
7
7
  * Предварительно вычисленный массив из 256 32-битных значений полинома 0xEDB88320 (стандартный для {@link http://create.stephan-brumme.com/crc32 CRC32})
8
8
  */
9
- export declare const polynomial: Uint32Array<ArrayBuffer>;
9
+ export declare const __polynomial: Uint32Array<ArrayBuffer>;
10
+ /**
11
+ * Генерирует хэш на основе алгоритма {@link http://create.stephan-brumme.com/crc32 CRC32}
12
+ */
13
+ export declare const __zipper: (data: string) => string;
10
14
  /**
11
15
  * Генерирует хэш в формате `${prefix}{hash}` на основе алгоритма {@link http://create.stephan-brumme.com/crc32 CRC32}
12
16
  *
13
17
  * @remarks Для сериализации используется {@link JSON.stringify}
14
18
  * @remarks Порядок свойств в объектах **влияет** на результат
15
19
  *
16
- * @param data - Данные для хэширования
20
+ * @param [data="undefined"] - Данные для хэширования
17
21
  * @param [prefix="zip:"] - Префикс для идентификации хэша
18
22
  *
19
23
  * @example
@@ -27,4 +31,4 @@ export declare const polynomial: Uint32Array<ArrayBuffer>;
27
31
  * const hash3 = zipper(obj3); // "zip:6b9g4d3f" (другой хэш)
28
32
  * ```
29
33
  */
30
- export declare const zipper: (data: Serializable, prefix?: string) => ZIP;
34
+ export declare const zipper: (data?: Serializable, prefix?: string) => ZIP;
package/dist/zipper.js CHANGED
@@ -1,19 +1,30 @@
1
1
  /**
2
2
  * Предварительно вычисленный массив из 256 32-битных значений полинома 0xEDB88320 (стандартный для {@link http://create.stephan-brumme.com/crc32 CRC32})
3
3
  */
4
- export const polynomial = Uint32Array.from({ length: 256 }, (_, i) => {
4
+ export const __polynomial = Uint32Array.from({ length: 256 }, (_, i) => {
5
5
  let crc = i;
6
6
  for (let j = 8; j--;)
7
7
  crc = (crc >>> 1) ^ (0xed_b8_83_20 & -(crc & 1));
8
8
  return crc;
9
9
  });
10
+ /**
11
+ * Генерирует хэш на основе алгоритма {@link http://create.stephan-brumme.com/crc32 CRC32}
12
+ */
13
+ export const __zipper = (data) => {
14
+ let crc = 0 ^ -1;
15
+ for (let i = data.length - 1; i >= 0; i--)
16
+ crc = (crc >>> 8) ^ __polynomial[(crc ^ data.codePointAt(i)) & 0xff];
17
+ return Math.trunc(crc ^ -1)
18
+ .toString(16)
19
+ .padStart(8, "0");
20
+ };
10
21
  /**
11
22
  * Генерирует хэш в формате `${prefix}{hash}` на основе алгоритма {@link http://create.stephan-brumme.com/crc32 CRC32}
12
23
  *
13
24
  * @remarks Для сериализации используется {@link JSON.stringify}
14
25
  * @remarks Порядок свойств в объектах **влияет** на результат
15
26
  *
16
- * @param data - Данные для хэширования
27
+ * @param [data="undefined"] - Данные для хэширования
17
28
  * @param [prefix="zip:"] - Префикс для идентификации хэша
18
29
  *
19
30
  * @example
@@ -27,13 +38,4 @@ export const polynomial = Uint32Array.from({ length: 256 }, (_, i) => {
27
38
  * const hash3 = zipper(obj3); // "zip:6b9g4d3f" (другой хэш)
28
39
  * ```
29
40
  */
30
- export const zipper = (data, prefix = "zip:") => {
31
- const str = JSON.stringify(data);
32
- let crc = 0 ^ -1;
33
- for (let i = str.length - 1; i >= 0; i--)
34
- crc = (crc >>> 8) ^ polynomial[(crc ^ str.codePointAt(i)) & 0xff];
35
- const hash = Math.trunc(crc ^ -1)
36
- .toString(16)
37
- .padStart(8, "0");
38
- return prefix + hash;
39
- };
41
+ export const zipper = (data = "undefined", prefix = "zip:") => prefix + __zipper(JSON.stringify(data));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/helpers",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",
@@ -206,6 +206,6 @@
206
206
  "@std/msgpack": "npm:@jsr/std__msgpack"
207
207
  },
208
208
  "devDependencies": {
209
- "@nemigo/configs": "2.2.0"
209
+ "@nemigo/configs": "2.2.3"
210
210
  }
211
211
  }