structured-fw 1.0.3 → 1.0.5
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,4 +1,4 @@
|
|
|
1
|
-
import { FormValidationEntry,
|
|
1
|
+
import { FormValidationEntry, LooseObject, ValidationResult, ValidationRuleWithArguments, ValidatorErrorDecorator, ValidatorFunction } from '../Types.js';
|
|
2
2
|
export declare class FormValidation {
|
|
3
3
|
fieldRules: Array<FormValidationEntry>;
|
|
4
4
|
singleError: boolean;
|
|
@@ -12,6 +12,6 @@ export declare class FormValidation {
|
|
|
12
12
|
addRule(fieldName: string, nameHumanReadable: string, rules: Array<string | ValidationRuleWithArguments | ValidatorFunction>): void;
|
|
13
13
|
registerValidator(name: string, validator: ValidatorFunction, decorator?: ValidatorErrorDecorator): void;
|
|
14
14
|
registerDecorator(name: string, decorator: ValidatorErrorDecorator): void;
|
|
15
|
-
validate(data:
|
|
15
|
+
validate(data: LooseObject): Promise<ValidationResult>;
|
|
16
16
|
private addError;
|
|
17
17
|
}
|
|
@@ -9,13 +9,18 @@ export class FormValidation {
|
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
11
11
|
const value = data[field];
|
|
12
|
-
if (
|
|
12
|
+
if (value === null ||
|
|
13
|
+
value === undefined ||
|
|
14
|
+
(typeof value === 'string' && value.trim().length === 0)) {
|
|
13
15
|
return false;
|
|
14
16
|
}
|
|
15
|
-
return
|
|
17
|
+
return true;
|
|
16
18
|
},
|
|
17
19
|
'number': async (data, field) => {
|
|
18
20
|
const value = data[field];
|
|
21
|
+
if (typeof value === 'number') {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
19
24
|
if (typeof value !== 'string') {
|
|
20
25
|
return false;
|
|
21
26
|
}
|
|
@@ -23,6 +28,9 @@ export class FormValidation {
|
|
|
23
28
|
},
|
|
24
29
|
'float': async (data, field) => {
|
|
25
30
|
const value = data[field];
|
|
31
|
+
if (typeof value === 'number') {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
26
34
|
if (typeof value !== 'string') {
|
|
27
35
|
return false;
|
|
28
36
|
}
|
|
@@ -33,6 +41,9 @@ export class FormValidation {
|
|
|
33
41
|
},
|
|
34
42
|
'min': async (data, field, arg, rules) => {
|
|
35
43
|
const value = data[field];
|
|
44
|
+
if (typeof value === 'number') {
|
|
45
|
+
return value >= arg;
|
|
46
|
+
}
|
|
36
47
|
if (typeof value !== 'string') {
|
|
37
48
|
return false;
|
|
38
49
|
}
|
|
@@ -43,6 +54,9 @@ export class FormValidation {
|
|
|
43
54
|
},
|
|
44
55
|
'max': async (data, field, arg, rules) => {
|
|
45
56
|
const value = data[field];
|
|
57
|
+
if (typeof value === 'number') {
|
|
58
|
+
return value <= arg;
|
|
59
|
+
}
|
|
46
60
|
if (typeof value !== 'string') {
|
|
47
61
|
return false;
|
|
48
62
|
}
|
|
@@ -103,7 +103,9 @@ export class HTMLParser {
|
|
|
103
103
|
throw this.error(`Found closing tag ${this.tokenCurrent}, expected ${this.context.tagName}`);
|
|
104
104
|
}
|
|
105
105
|
this.context = this.context.parentNode || this.fragment;
|
|
106
|
-
this.state = '
|
|
106
|
+
this.state = 'text';
|
|
107
|
+
this.tokenCurrent = '';
|
|
108
|
+
return true;
|
|
107
109
|
}
|
|
108
110
|
this.tokenCurrent += char;
|
|
109
111
|
}
|
package/package.json
CHANGED
|
@@ -19,12 +19,14 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"type": "module",
|
|
21
21
|
"main": "build/index",
|
|
22
|
-
"version": "1.0.
|
|
22
|
+
"version": "1.0.5",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"develop": "tsc --watch",
|
|
25
25
|
"startDev": "cd build && nodemon --watch '../app/**/*' --watch '../build/**/*' -e js,html,css index.js",
|
|
26
26
|
"start": "cd build && node index.js",
|
|
27
|
-
"prepublish": "tsc"
|
|
27
|
+
"prepublish": "tsc",
|
|
28
|
+
"pack": "tsc && npm pack",
|
|
29
|
+
"publish": "tsc && npm publish"
|
|
28
30
|
},
|
|
29
31
|
"bin": {
|
|
30
32
|
"structured": "./build/system/bin/structured.js"
|