@nemigo/helpers 0.2.0 → 0.3.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.js +1 -0
- package/dist/datetime.js +3 -1
- package/dist/format.d.ts +1 -2
- package/dist/html.js +8 -8
- package/dist/queue.d.ts +4 -0
- package/dist/queue.js +11 -5
- package/dist/url.js +5 -5
- package/package.json +1 -1
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);
|
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/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/queue.d.ts
CHANGED
package/dist/queue.js
CHANGED
|
@@ -27,22 +27,28 @@ export class Queue {
|
|
|
27
27
|
* Запускает обработку очереди с задержкой
|
|
28
28
|
*/
|
|
29
29
|
run() {
|
|
30
|
-
this.
|
|
30
|
+
this.stop();
|
|
31
31
|
this.timeout = setTimeout(() => {
|
|
32
32
|
if (this._queue.length === 0)
|
|
33
|
-
return this.
|
|
33
|
+
return this.stop();
|
|
34
34
|
const item = this._queue.shift();
|
|
35
35
|
this.handle(item);
|
|
36
|
-
this._queue.length > 0 ? this.run() : this.
|
|
36
|
+
this._queue.length > 0 ? this.run() : this.stop();
|
|
37
37
|
}, this._delay);
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* Сброс
|
|
40
|
+
* Сброс таймера шага
|
|
41
41
|
*/
|
|
42
|
-
|
|
42
|
+
stop() {
|
|
43
43
|
if (this.timeout)
|
|
44
44
|
clearTimeout(this.timeout);
|
|
45
45
|
this.timeout = 0;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Сброс очереди
|
|
49
|
+
*/
|
|
50
|
+
reset() {
|
|
51
|
+
this.stop();
|
|
46
52
|
this._queue.length = 0;
|
|
47
53
|
}
|
|
48
54
|
}
|
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;
|