@bouko/react 2.3.8 → 2.4.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.
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const useForm: <T>(init: Partial<T>) => {
|
|
3
|
-
data: Partial<T>;
|
|
4
|
-
update: import("react").Dispatch<import("react").SetStateAction<Partial<T>>>;
|
|
5
|
-
clear: () => void;
|
|
6
|
-
setField: (name: string, value: unknown) => void;
|
|
7
|
-
};
|
|
8
|
-
export declare const setField: <T>(update: SetState<T>, id: string, value: unknown) => void;
|
|
9
|
-
export declare const parseData: <T extends Record<string, unknown>>(data: T) => T;
|
|
1
|
+
export declare const parseData: <T extends Record<string, unknown>>(data: T) => T;
|
|
@@ -1,47 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
return copy;
|
|
31
|
-
};
|
|
32
|
-
function parseAllowedDate(input) {
|
|
33
|
-
// ISO 8601 strict (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss+hh:mm)
|
|
34
|
-
const isoStrictRegex = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?(Z|[+-]\d{2}:\d{2}))?$/;
|
|
35
|
-
// MySQL/Postgres style with space + offset without colon (YYYY-MM-DD HH:mm:ss+hhmm)
|
|
36
|
-
const spaceOffsetRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}[+-]\d{4}$/;
|
|
37
|
-
let normalized = input;
|
|
38
|
-
if (spaceOffsetRegex.test(input)) {
|
|
39
|
-
// Convert to ISO by replacing space with T and adding colon in offset
|
|
40
|
-
normalized = input.replace(" ", "T").replace(/([+-]\d{2})(\d{2})$/, "$1:$2");
|
|
41
|
-
}
|
|
42
|
-
else if (!isoStrictRegex.test(input)) {
|
|
43
|
-
return null; // Not allowed format
|
|
44
|
-
}
|
|
45
|
-
const date = new Date(normalized);
|
|
46
|
-
return !isNaN(date.getTime()) ? date : null;
|
|
47
|
-
}
|
|
1
|
+
export const parseData = (data) => {
|
|
2
|
+
const copy = JSON.parse(JSON.stringify(data));
|
|
3
|
+
for (const [key, value] of Object.entries(data)) {
|
|
4
|
+
if (key === "created_at")
|
|
5
|
+
copy[key] = new Date(value);
|
|
6
|
+
else if (key === "timestamp")
|
|
7
|
+
copy[key] = new Date(value.replaceAll("'", ""));
|
|
8
|
+
else if (parseAllowedDate(value))
|
|
9
|
+
copy[key] = new Date(value);
|
|
10
|
+
}
|
|
11
|
+
return copy;
|
|
12
|
+
};
|
|
13
|
+
function parseAllowedDate(input) {
|
|
14
|
+
// ISO 8601 strict (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss+hh:mm)
|
|
15
|
+
const isoStrictRegex = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?(Z|[+-]\d{2}:\d{2}))?$/;
|
|
16
|
+
// MySQL/Postgres style with space + offset without colon (YYYY-MM-DD HH:mm:ss+hhmm)
|
|
17
|
+
const spaceOffsetRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}[+-]\d{4}$/;
|
|
18
|
+
let normalized = input;
|
|
19
|
+
if (spaceOffsetRegex.test(input)) {
|
|
20
|
+
// Convert to ISO by replacing space with T and adding colon in offset
|
|
21
|
+
normalized = input.replace(" ", "T").replace(/([+-]\d{2})(\d{2})$/, "$1:$2");
|
|
22
|
+
}
|
|
23
|
+
else if (!isoStrictRegex.test(input)) {
|
|
24
|
+
return null; // Not allowed format
|
|
25
|
+
}
|
|
26
|
+
const date = new Date(normalized);
|
|
27
|
+
return !isNaN(date.getTime()) ? date : null;
|
|
28
|
+
}
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
declare type Props = {
|
|
2
|
+
action: () => Promise<boolean | void>;
|
|
3
|
+
duration: number;
|
|
4
|
+
deps: unknown[];
|
|
5
|
+
oops?: (x: string) => void;
|
|
6
|
+
};
|
|
7
|
+
export default function useInterval({ action, duration, deps, oops }: Props): void;
|
|
8
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
|
-
export default function useInterval(action,
|
|
3
|
+
export default function useInterval({ action, duration, deps = [], oops }) {
|
|
4
4
|
const ref = useRef(async () => false);
|
|
5
5
|
useEffect(() => {
|
|
6
6
|
ref.current = action;
|
|
@@ -9,12 +9,17 @@ export default function useInterval(action, delay, deps = []) {
|
|
|
9
9
|
if (deps.some(v => v === undefined || v === null))
|
|
10
10
|
return;
|
|
11
11
|
const tick = async () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
try {
|
|
13
|
+
const stop = await ref.current();
|
|
14
|
+
if (stop && id)
|
|
15
|
+
clearInterval(id);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
oops?.(err.message);
|
|
19
|
+
}
|
|
15
20
|
};
|
|
16
|
-
const id = setInterval(tick,
|
|
21
|
+
const id = setInterval(tick, duration);
|
|
17
22
|
tick();
|
|
18
23
|
return () => clearInterval(id);
|
|
19
|
-
}, [
|
|
24
|
+
}, [duration, ...deps]);
|
|
20
25
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED