Skip to content

Commit 72d86e0

Browse files
committed
Fix helpers function. Add regexps
1 parent 90f477c commit 72d86e0

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

frontend/src/helpers/transform.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@ import dayjs from "dayjs";
33
import slugify from "slugify";
44

55
export const isDayJs = (v: any): boolean => {
6-
return !Number.isNaN(new Date(v).getDate());
6+
const iso8601Regex =
7+
/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:\d{2}))$/;
8+
if (iso8601Regex.test(v)) {
9+
return true;
10+
}
11+
return false;
712
};
813

914
export const isNumeric = (v: any): boolean => {
10-
return !Number.isNaN(Number.parseFloat(v)) && Number.isFinite(v);
15+
const numericRegex = /^[+-]?(\d+(\.\d*)?|\.\d+)$/;
16+
return numericRegex.test(v);
1117
};
1218

1319
export const isArray = (v: any): boolean => {
1420
return Array.isArray(v);
1521
};
1622

1723
export const isBoolean = (v: any): boolean => {
18-
return v === "true" || v === "false" || typeof v === "boolean" || !!v === v;
24+
const booleanRegex = /^(true|false)$/i;
25+
return booleanRegex.test(v);
1926
};
2027

2128
export const isString = (v: any): boolean => {
@@ -96,9 +103,6 @@ export const transformValueFromServer = (value: any): any => {
96103
if (isArray(value)) {
97104
return value.map(transformValueFromServer);
98105
}
99-
if (isNumeric(value)) {
100-
return value;
101-
}
102106
if (isBoolean(value)) {
103107
return value !== "false" && !!value;
104108
}
@@ -147,9 +151,6 @@ export const transformColumnValueFromServer = (
147151
);
148152
});
149153
}
150-
if (isNumeric(value)) {
151-
return value;
152-
}
153154
if (isBoolean(value)) {
154155
return <Checkbox checked={value} />;
155156
}

0 commit comments

Comments
 (0)