@nemigo/helpers 0.1.0 → 0.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.
- package/dist/async.d.ts +2 -2
- package/dist/async.js +3 -2
- package/dist/datetime.js +3 -1
- package/dist/format.d.ts +1 -2
- package/dist/format.js +1 -1
- package/dist/html.d.ts +1 -1
- package/dist/html.js +8 -8
- package/dist/url.js +5 -5
- package/dist/xod.d.ts +7 -5
- package/dist/xod.js +7 -5
- package/package.json +1 -1
package/dist/async.d.ts
CHANGED
|
@@ -25,10 +25,10 @@ export declare const debounce: <T extends (...args: any[]) => any>(call: T, dela
|
|
|
25
25
|
*
|
|
26
26
|
* mode = `"urgent"`:
|
|
27
27
|
* - первый вызов исполняется сразу
|
|
28
|
-
* - повторные вызовы возвращают тот же
|
|
28
|
+
* - повторные вызовы возвращают тот же промисс в течение `ms` (даже после завершения)
|
|
29
29
|
* - после `ms` можно снова вызвать
|
|
30
30
|
*/
|
|
31
|
-
export declare const
|
|
31
|
+
export declare const throttle: <F extends (...args: any[]) => any>(call: F, mode: "urgent" | "delay", ms: number) => ((...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>>);
|
|
32
32
|
/**
|
|
33
33
|
* Создаёт функцию-замыкание, которая гарантирует однократное выполнение асинхронной операции
|
|
34
34
|
*
|
package/dist/async.js
CHANGED
|
@@ -16,6 +16,7 @@ export const delay = (ms) => new Promise((ready) => setTimeout(ready, ms));
|
|
|
16
16
|
export const debounce = (call, delay) => {
|
|
17
17
|
let timeout;
|
|
18
18
|
return (...args) => {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
19
20
|
if (timeout)
|
|
20
21
|
clearTimeout(timeout);
|
|
21
22
|
timeout = setTimeout(() => call(...args), delay);
|
|
@@ -32,10 +33,10 @@ export const debounce = (call, delay) => {
|
|
|
32
33
|
*
|
|
33
34
|
* mode = `"urgent"`:
|
|
34
35
|
* - первый вызов исполняется сразу
|
|
35
|
-
* - повторные вызовы возвращают тот же
|
|
36
|
+
* - повторные вызовы возвращают тот же промисс в течение `ms` (даже после завершения)
|
|
36
37
|
* - после `ms` можно снова вызвать
|
|
37
38
|
*/
|
|
38
|
-
export const
|
|
39
|
+
export const throttle = (call, mode, ms) => {
|
|
39
40
|
let _promise = null;
|
|
40
41
|
let _args = [];
|
|
41
42
|
return (...args) => {
|
package/dist/datetime.js
CHANGED
|
@@ -99,7 +99,9 @@ export const formatDateTime = (datetime = Date.now(), format = "DD.DM.DY TH:TM")
|
|
|
99
99
|
* const timestamp = toTimeStamp("11.02.2012", "13:45");
|
|
100
100
|
* console.log(timestamp); // Выведет {@link Timestamp} для "11.02.2012 13:45"
|
|
101
101
|
*/
|
|
102
|
-
export const toTimeStamp =
|
|
102
|
+
export const toTimeStamp =
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
104
|
+
(date, time = "00:00") => {
|
|
103
105
|
const [day, month, year] = date.split(".").map(Number);
|
|
104
106
|
const [hours, minutes] = time.split(":").map(Number);
|
|
105
107
|
// Проверка на корректность ввода (если хотя бы одно значение не число)
|
package/dist/format.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CanBeNullable } from "./types.js";
|
|
2
|
-
interface FormatNumberConfig {
|
|
2
|
+
export interface FormatNumberConfig {
|
|
3
3
|
/**
|
|
4
4
|
* @default 2
|
|
5
5
|
*/
|
|
@@ -28,4 +28,3 @@ export declare const FormatNumberRegExp: RegExp;
|
|
|
28
28
|
* @example "1 234" или "1 234,56"
|
|
29
29
|
*/
|
|
30
30
|
export declare const formatNumber: (amount: CanBeNullable<number | string>, { fraction, fallback, zero, postfix }?: FormatNumberConfig) => string;
|
|
31
|
-
export {};
|
package/dist/format.js
CHANGED
|
@@ -7,7 +7,7 @@ export const FormatNumberRegExp = /\B(?=(\d{3})+(?!\d))/g;
|
|
|
7
7
|
* @example "1 234" или "1 234,56"
|
|
8
8
|
*/
|
|
9
9
|
export const formatNumber = (amount, { fraction = 2, fallback = "---", zero = "value", postfix } = {}) => caseNumber(amount, (v) => {
|
|
10
|
-
if (v ===
|
|
10
|
+
if (v === null)
|
|
11
11
|
return zero === "always" ? (postfix ? "0 " + postfix : "0") : fallback;
|
|
12
12
|
if (v === 0)
|
|
13
13
|
return zero === "never" ? fallback : postfix ? "0 " + postfix : "0";
|
package/dist/html.d.ts
CHANGED
package/dist/html.js
CHANGED
|
@@ -26,26 +26,26 @@ export const preventStopHook = (call, load) => (e) => {
|
|
|
26
26
|
*/
|
|
27
27
|
export const enterKeyHook = (call, config = { usePreventStop: "enter" }) => (e) => {
|
|
28
28
|
const isEnter = e.key === "Enter";
|
|
29
|
-
if (config
|
|
29
|
+
if (config.usePreventStop === "enter") {
|
|
30
30
|
if (isEnter)
|
|
31
31
|
preventStop(e);
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
|
-
if (config
|
|
35
|
-
if (typeof config
|
|
36
|
-
if (config
|
|
34
|
+
if (config.usePreventStop !== undefined) {
|
|
35
|
+
if (typeof config.usePreventStop === "boolean") {
|
|
36
|
+
if (config.usePreventStop)
|
|
37
37
|
preventStop(e);
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
|
-
if (config
|
|
40
|
+
if (config.usePreventStop(e, isEnter))
|
|
41
41
|
preventStop(e);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
if (config
|
|
45
|
+
if (config.load?.())
|
|
46
46
|
return;
|
|
47
|
-
if (config
|
|
48
|
-
Promise.resolve(config
|
|
47
|
+
if (config.prepare) {
|
|
48
|
+
void Promise.resolve(config.prepare(e)).then((next) => {
|
|
49
49
|
if (next && isEnter)
|
|
50
50
|
call?.(e);
|
|
51
51
|
});
|
package/dist/url.js
CHANGED
|
@@ -24,10 +24,10 @@ export const pushParams = (url, params, unsafe = false) => {
|
|
|
24
24
|
url.searchParams.set(param, unsafe ? "" : "true");
|
|
25
25
|
continue;
|
|
26
26
|
}
|
|
27
|
-
if (!param
|
|
27
|
+
if (!param.key)
|
|
28
28
|
continue;
|
|
29
29
|
if (typeof param.value !== "object") {
|
|
30
|
-
if (unsafe && (param
|
|
30
|
+
if (unsafe && (param.value === undefined || param.value === true || param.value === "")) {
|
|
31
31
|
url.searchParams.set(param.key, "");
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
@@ -66,9 +66,9 @@ export const mergePushParams = (...args) => {
|
|
|
66
66
|
acc.push({ key: param, value: true });
|
|
67
67
|
continue;
|
|
68
68
|
}
|
|
69
|
-
if (!param
|
|
69
|
+
if (!param.key)
|
|
70
70
|
continue;
|
|
71
|
-
if (typeof param
|
|
71
|
+
if (typeof param.value !== "object") {
|
|
72
72
|
const existed = acc.find((v) => v.key === param.key);
|
|
73
73
|
if (param.value === undefined || param.value === true || param.value === "") {
|
|
74
74
|
if (existed)
|
|
@@ -107,7 +107,7 @@ export const clearParams = (url, params) => {
|
|
|
107
107
|
url.searchParams.delete(param);
|
|
108
108
|
continue;
|
|
109
109
|
}
|
|
110
|
-
if (param
|
|
110
|
+
if (param.key)
|
|
111
111
|
url.searchParams.delete(param.key);
|
|
112
112
|
}
|
|
113
113
|
return url;
|
package/dist/xod.d.ts
CHANGED
|
@@ -15,10 +15,12 @@ declare const _default: {
|
|
|
15
15
|
message: string;
|
|
16
16
|
expected: string;
|
|
17
17
|
}) => never;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
null: z.ZodPipe<z.ZodOptional<z.ZodNull>, z.ZodTransform<undefined, null | undefined>>;
|
|
19
|
+
boolean: z.ZodPipe<z.ZodBoolean, z.ZodTransform<boolean, boolean>>;
|
|
20
|
+
booleanOptional: z.ZodUnion<readonly [z.ZodPipe<z.ZodOptional<z.ZodNull>, z.ZodTransform<undefined, null | undefined>>, z.ZodPipe<z.ZodBoolean, z.ZodTransform<boolean, boolean>>]>;
|
|
21
|
+
number: z.ZodPipe<z.ZodUnion<[z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>;
|
|
22
|
+
numberOptional: z.ZodUnion<readonly [z.ZodPipe<z.ZodOptional<z.ZodNull>, z.ZodTransform<undefined, null | undefined>>, z.ZodPipe<z.ZodUnion<[z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>]>;
|
|
23
|
+
string: z.ZodUnion<[z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>;
|
|
24
|
+
stringOptional: z.ZodUnion<readonly [z.ZodPipe<z.ZodOptional<z.ZodNull>, z.ZodTransform<undefined, null | undefined>>, z.ZodUnion<[z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>]>;
|
|
23
25
|
};
|
|
24
26
|
export default _default;
|
package/dist/xod.js
CHANGED
|
@@ -53,9 +53,11 @@ export const stringSchemaOptional = z.union([nullSchema, stringSchema]);
|
|
|
53
53
|
//...
|
|
54
54
|
export default {
|
|
55
55
|
invalid,
|
|
56
|
-
nullSchema,
|
|
57
|
-
booleanSchema,
|
|
58
|
-
booleanSchemaOptional,
|
|
59
|
-
numberSchema,
|
|
60
|
-
numberSchemaOptional,
|
|
56
|
+
null: nullSchema,
|
|
57
|
+
boolean: booleanSchema,
|
|
58
|
+
booleanOptional: booleanSchemaOptional,
|
|
59
|
+
number: numberSchema,
|
|
60
|
+
numberOptional: numberSchemaOptional,
|
|
61
|
+
string: stringSchema,
|
|
62
|
+
stringOptional: stringSchemaOptional,
|
|
61
63
|
};
|