@nemigo/helpers 1.6.4 → 2.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/async/context.d.ts +1 -1
- package/dist/async/context.js +1 -1
- package/dist/async/index.js +3 -1
- package/dist/async/queue.js +3 -1
- package/dist/cases.js +3 -3
- package/dist/datetime/delta.js +2 -2
- package/dist/datetime/format.js +2 -28
- package/dist/files.js +3 -13
- package/dist/html/cookie.js +1 -1
- package/dist/mutate.d.ts +2 -2
- package/dist/path.js +1 -1
- package/dist/phymath/format.js +3 -3
- package/dist/phymath/index.js +2 -2
- package/dist/random.js +1 -1
- package/dist/script.js +1 -1
- package/dist/xod.js +2 -2
- package/package.json +12 -14
package/dist/async/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1
2
|
import type { CanBePromise } from "../types.js";
|
|
2
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
3
3
|
/**
|
|
4
4
|
* Создание асинхронного контекста с транзакциями без явной передачи на основе {@link AsyncLocalStorage}
|
|
5
5
|
*
|
package/dist/async/context.js
CHANGED
package/dist/async/index.js
CHANGED
|
@@ -60,7 +60,9 @@ export const throttle = (func, mode = "urgent", ms = 250) => {
|
|
|
60
60
|
let _promise;
|
|
61
61
|
let _args = [];
|
|
62
62
|
const call = async () => await func(..._args);
|
|
63
|
-
const reset = () =>
|
|
63
|
+
const reset = () => {
|
|
64
|
+
_promise = null;
|
|
65
|
+
};
|
|
64
66
|
return (...args) => {
|
|
65
67
|
_args = args;
|
|
66
68
|
if (_promise)
|
package/dist/async/queue.js
CHANGED
package/dist/cases.js
CHANGED
|
@@ -11,7 +11,7 @@ export const caseString = (value, callback) => {
|
|
|
11
11
|
case "string":
|
|
12
12
|
return callback(value, false);
|
|
13
13
|
case "number":
|
|
14
|
-
if (!isNaN(value))
|
|
14
|
+
if (!Number.isNaN(value))
|
|
15
15
|
return callback(String(value), true);
|
|
16
16
|
}
|
|
17
17
|
return callback(undefined, false);
|
|
@@ -28,13 +28,13 @@ export const caseString = (value, callback) => {
|
|
|
28
28
|
export const caseNumber = (value, callback) => {
|
|
29
29
|
switch (typeof value) {
|
|
30
30
|
case "number":
|
|
31
|
-
return callback(isNaN(value) ? undefined : value, false);
|
|
31
|
+
return callback(Number.isNaN(value) ? undefined : value, false);
|
|
32
32
|
case "string": {
|
|
33
33
|
const trimmed = value.trim();
|
|
34
34
|
// Проверяем что строка не пустая и преобразуется в валидное число
|
|
35
35
|
if (trimmed !== "") {
|
|
36
36
|
const number = Number(trimmed);
|
|
37
|
-
if (!isNaN(number))
|
|
37
|
+
if (!Number.isNaN(number))
|
|
38
38
|
return callback(number, true);
|
|
39
39
|
}
|
|
40
40
|
}
|
package/dist/datetime/delta.js
CHANGED
|
@@ -7,8 +7,8 @@ export const MS_IN_WEEK = 7 * MS_IN_DAY;
|
|
|
7
7
|
export const formatPerformanceDelta = (start, end = Date.now()) => {
|
|
8
8
|
const diff = end - start;
|
|
9
9
|
if (diff < 1000)
|
|
10
|
-
return diff
|
|
11
|
-
return diff / 1000
|
|
10
|
+
return `${diff}ms`;
|
|
11
|
+
return `${diff / 1000}s`;
|
|
12
12
|
};
|
|
13
13
|
export const timeDeltaObjectToTimestamp = (obj, options = {}) => {
|
|
14
14
|
const { round_key, round_method, in_seconds = false } = options;
|
package/dist/datetime/format.js
CHANGED
|
@@ -3,37 +3,11 @@ import { pad } from "../index.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Полные названия месяцев на русском языке (родительный падеж)
|
|
5
5
|
*/
|
|
6
|
-
export const months = [
|
|
7
|
-
"января",
|
|
8
|
-
"февраля",
|
|
9
|
-
"марта",
|
|
10
|
-
"апреля",
|
|
11
|
-
"мая",
|
|
12
|
-
"июня",
|
|
13
|
-
"июля",
|
|
14
|
-
"августа",
|
|
15
|
-
"сентября",
|
|
16
|
-
"октября",
|
|
17
|
-
"ноября",
|
|
18
|
-
"декабря",
|
|
19
|
-
];
|
|
6
|
+
export const months = ["января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"];
|
|
20
7
|
/**
|
|
21
8
|
* Сокращенные названия месяцев на русском языке
|
|
22
9
|
*/
|
|
23
|
-
export const abbs = [
|
|
24
|
-
"янв",
|
|
25
|
-
"фев",
|
|
26
|
-
"марта",
|
|
27
|
-
"апр",
|
|
28
|
-
"мая",
|
|
29
|
-
"июня",
|
|
30
|
-
"июля",
|
|
31
|
-
"авг",
|
|
32
|
-
"сен",
|
|
33
|
-
"окт",
|
|
34
|
-
"ноя",
|
|
35
|
-
"дек",
|
|
36
|
-
];
|
|
10
|
+
export const abbs = ["янв", "фев", "марта", "апр", "мая", "июня", "июля", "авг", "сен", "окт", "ноя", "дек"];
|
|
37
11
|
/**
|
|
38
12
|
* Шаблонизатор для форматирования даты и времени
|
|
39
13
|
*
|
package/dist/files.js
CHANGED
|
@@ -26,17 +26,7 @@ export const isAudio = (file) => file.type.startsWith("audio/");
|
|
|
26
26
|
/**
|
|
27
27
|
* Словарь степеней байтов для {@link getFileSize}
|
|
28
28
|
*/
|
|
29
|
-
export const BYTES_UNITS = [
|
|
30
|
-
"B",
|
|
31
|
-
"kB",
|
|
32
|
-
"MB",
|
|
33
|
-
"GB",
|
|
34
|
-
"TB",
|
|
35
|
-
"PB",
|
|
36
|
-
"EB",
|
|
37
|
-
"ZB",
|
|
38
|
-
"YB",
|
|
39
|
-
];
|
|
29
|
+
export const BYTES_UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
40
30
|
/**
|
|
41
31
|
* Форматирует размер файла в читаемом виде
|
|
42
32
|
*
|
|
@@ -53,8 +43,8 @@ export const BYTES_UNITS = [
|
|
|
53
43
|
export const getFileSize = (size, dictionary = BYTES_UNITS) => {
|
|
54
44
|
const bytes = Math.round(size);
|
|
55
45
|
if (bytes < 1000)
|
|
56
|
-
return bytes.toString()
|
|
46
|
+
return `${bytes.toString()} B`;
|
|
57
47
|
const exponent = Math.min(Math.floor(Math.log10(bytes) / 3), dictionary.length - 1);
|
|
58
48
|
const result = bytes / 1000 ** exponent;
|
|
59
|
-
return Math.round(result)
|
|
49
|
+
return `${Math.round(result)} ${dictionary[exponent]}`;
|
|
60
50
|
};
|
package/dist/html/cookie.js
CHANGED
|
@@ -21,7 +21,7 @@ export const setDocumentCookie = (name, value, options = {}) => {
|
|
|
21
21
|
document.cookie = acc;
|
|
22
22
|
};
|
|
23
23
|
export const getDocumentCookie = (name) => {
|
|
24
|
-
const search = name
|
|
24
|
+
const search = `${name}=`;
|
|
25
25
|
const cookies = document.cookie.split(";");
|
|
26
26
|
for (const raw of cookies) {
|
|
27
27
|
const cookie = raw.trim();
|
package/dist/mutate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyFunc, Args,
|
|
1
|
+
import type { AnyFunc, Args, FuncCopy, Return } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Рекурсивно модифицирует объект, приводя его структуру к виду целевого объекта.
|
|
4
4
|
* Использует внутри {@link deepMutateArray}
|
|
@@ -51,7 +51,7 @@ export declare const deepMutateArray: (source: unknown[], target: unknown[]) =>
|
|
|
51
51
|
*/
|
|
52
52
|
export interface InjectContext<O extends Record<K, AnyFunc>, K extends keyof O> {
|
|
53
53
|
self: O;
|
|
54
|
-
method:
|
|
54
|
+
method: FuncCopy<O[K]>;
|
|
55
55
|
args: Args<O[K]>;
|
|
56
56
|
}
|
|
57
57
|
/**
|
package/dist/path.js
CHANGED
|
@@ -21,6 +21,6 @@ export const toUnixPath = (path) => path.replaceAll("\\", "/");
|
|
|
21
21
|
*/
|
|
22
22
|
export const isChildPath = (parentPath, childPath) => {
|
|
23
23
|
const uChildPath = toUnixPath(childPath);
|
|
24
|
-
const nParentPath = toUnixPath(parentPath)
|
|
24
|
+
const nParentPath = `${toUnixPath(parentPath)}/`;
|
|
25
25
|
return uChildPath.startsWith(nParentPath);
|
|
26
26
|
};
|
package/dist/phymath/format.js
CHANGED
|
@@ -22,13 +22,13 @@ export const NumberFormatRegExp = /\B(?=(\d{3})+(?!\d))/g;
|
|
|
22
22
|
*/
|
|
23
23
|
export const toNumberFormat = (value, { fraction = 2, fallback = "---", zero = "value", postfix, fractional = ",", separator = " " } = {}) => caseNumber(value, (v) => {
|
|
24
24
|
if (v === undefined)
|
|
25
|
-
return zero === "always" ? (postfix ?
|
|
25
|
+
return zero === "always" ? (postfix ? `0 ${postfix}` : "0") : fallback;
|
|
26
26
|
if (v === 0)
|
|
27
|
-
return zero === "never" ? fallback : postfix ?
|
|
27
|
+
return zero === "never" ? fallback : postfix ? `0 ${postfix}` : "0";
|
|
28
28
|
if (fraction === 0)
|
|
29
29
|
return Math.round(v).toString().replace(NumberFormatRegExp, separator);
|
|
30
30
|
const { 0: integer, 1: float = "" } = round(v, fraction).toString().split(".");
|
|
31
31
|
const result = integer.replace(NumberFormatRegExp, separator);
|
|
32
32
|
const formatted = float ? `${result}${fractional}${float}` : result;
|
|
33
|
-
return postfix ? formatted
|
|
33
|
+
return postfix ? `${formatted} ${postfix}` : formatted;
|
|
34
34
|
});
|
package/dist/phymath/index.js
CHANGED
|
@@ -14,9 +14,9 @@ export const normalizero = (value) => (value === 0 ? 0 : value);
|
|
|
14
14
|
* @param [method="math"] - Метод округления
|
|
15
15
|
*/
|
|
16
16
|
export const round = (value, fraction = 2, method = "math") => {
|
|
17
|
-
if (isNaN(value) || value === 0)
|
|
17
|
+
if (Number.isNaN(value) || value === 0)
|
|
18
18
|
return 0;
|
|
19
|
-
const factor =
|
|
19
|
+
const factor = 10 ** fraction;
|
|
20
20
|
switch (method) {
|
|
21
21
|
case "up":
|
|
22
22
|
return Math.ceil(value * factor) / factor;
|
package/dist/random.js
CHANGED
package/dist/script.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MS_IN_MINUTE } from "./datetime/delta.js";
|
|
2
1
|
import { exec } from "node:child_process";
|
|
2
|
+
import { MS_IN_MINUTE } from "./datetime/delta.js";
|
|
3
3
|
/**
|
|
4
4
|
* @param cmd - Команда, которой скрипт был запущен (`process.argv`)
|
|
5
5
|
* @param name - Имя флага, который нужно найти
|
package/dist/xod.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { caseBoolean, caseNumber, caseString } from "./cases.js";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { caseBoolean, caseNumber, caseString } from "./cases.js";
|
|
3
3
|
/**
|
|
4
4
|
* Добавляет ошибку валидации в контекст {@link https://zod.dev Zod}-схемы через {@link RefinementCtx.addIssue} и прерывает выполнение
|
|
5
5
|
*/
|
|
@@ -27,7 +27,7 @@ export const throwValueIssue = (props) => {
|
|
|
27
27
|
* - `ETC` → ZodError
|
|
28
28
|
*/
|
|
29
29
|
export const nullSchema = z.union([
|
|
30
|
-
//
|
|
30
|
+
// biome-ignore format: потеря смысла
|
|
31
31
|
z.null().optional().transform(() => undefined),
|
|
32
32
|
z.string().transform((value, ctx) => {
|
|
33
33
|
if (!value)
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nemigo/helpers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Vlad Logvin",
|
|
7
7
|
"email": "vlad.logvin84@gmail.com"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
|
-
"engines": {
|
|
11
|
-
"node": ">=22",
|
|
12
|
-
"pnpm": ">=10.9.0"
|
|
13
|
-
},
|
|
14
10
|
"scripts": {
|
|
15
11
|
"build": "svelte-package && rimraf .svelte-kit",
|
|
16
12
|
"check": "tsc --noemit",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
13
|
+
"eslint": "eslint ./",
|
|
14
|
+
"eslint:fix": "eslint --fix ./",
|
|
15
|
+
"lint": "biome lint",
|
|
16
|
+
"lint:fix": "biome lint --fix --unsafe",
|
|
17
|
+
"lint:fix:unsafe": "biome lint --fix --unsafe",
|
|
18
|
+
"test": "bun test",
|
|
19
|
+
"format": "biome check --write --linter-enabled=false"
|
|
20
20
|
},
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
@@ -197,20 +197,18 @@
|
|
|
197
197
|
}
|
|
198
198
|
},
|
|
199
199
|
"peerDependencies": {
|
|
200
|
-
"@std/msgpack": ">=1.0.0",
|
|
201
200
|
"zod": ">=4.0.0"
|
|
202
201
|
},
|
|
203
202
|
"peerDependenciesMeta": {
|
|
204
|
-
"@std/msgpack": {
|
|
205
|
-
"optional": true
|
|
206
|
-
},
|
|
207
203
|
"zod": {
|
|
208
204
|
"optional": true
|
|
209
205
|
}
|
|
210
206
|
},
|
|
207
|
+
"dependencies": {
|
|
208
|
+
"@std/msgpack": "npm:@jsr/std__msgpack"
|
|
209
|
+
},
|
|
211
210
|
"devDependencies": {
|
|
212
|
-
"@nemigo/configs": "
|
|
213
|
-
"@std/msgpack": "jsr:1.0.3",
|
|
211
|
+
"@nemigo/configs": "2.0.0",
|
|
214
212
|
"zod": "4.1.12"
|
|
215
213
|
}
|
|
216
214
|
}
|