We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents d9cea9e + fd3c058 commit 83211a1Copy full SHA for 83211a1
3 files changed
packages/core/src/lib/utils/normalizedStringValue.ts
@@ -1,3 +1,4 @@
1
+import { isUndefined } from 'lodash';
2
import { UserError } from './errors';
3
4
export const canBeNormalized = (type: string) => {
@@ -7,10 +8,14 @@ export const canBeNormalized = (type: string) => {
7
8
};
9
10
export const normalizeStringValue = (
- value: string,
11
+ value: string | undefined,
12
dataName: string,
13
dataType: string
14
) => {
15
+ if (isUndefined(value)) {
16
+ return undefined;
17
+ }
18
+
19
switch (dataType.toLowerCase()) {
20
case 'number': {
21
if (value === '') {
packages/core/src/lib/validators/built-in-validators/dateTypeValidator.ts
@@ -39,6 +39,8 @@ export class DateTypeValidator extends InputValidator {
39
}
40
41
public validateData(value: string, args?: DateInputArgs) {
42
+ if (isUndefined(value)) return;
43
44
let valid = dayjs(value).isValid();
45
// if there are args passed
46
if (!isUndefined(args)) {
packages/core/test/utils/normalizedStringValue.spec.ts
@@ -22,15 +22,19 @@ it.each([
22
['number', '1234', 1234],
23
['number', '-1234', -1234],
24
['number', '0', 0],
25
+ ['number', undefined, undefined],
26
['boolean', '', true],
27
['boolean', '1', true],
28
['boolean', 'true', true],
29
['boolean', '0', false],
30
['boolean', 'false', false],
31
+ ['boolean', undefined, undefined],
32
['date', '2022-08-23 14:44:23', new Date('2022-08-23 14:44:23')],
33
+ ['date', undefined, undefined],
34
['string', '1234', '1234'],
35
['string', 'true', 'true'],
36
['string', '', ''],
37
+ ['string', undefined, undefined],
38
])(
`Normalizer should return correct value with type %s and value %p`,
(type, value, expectedValue) => {
0 commit comments