nox-validation 1.7.6 → 1.7.8

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/lib/helpers.js CHANGED
@@ -914,7 +914,7 @@ const buildNestedStructure = ({
914
914
  }
915
915
 
916
916
  const isArray =
917
- item.type === item?.schema_definition.type &&
917
+ item.type === item?.schema_definition?.type &&
918
918
  item.type === constants.types.ARRAY;
919
919
 
920
920
  let children = [];
package/lib/validate.js CHANGED
@@ -41,7 +41,6 @@ const typeChecks = {
41
41
  }
42
42
  return false;
43
43
  },
44
-
45
44
  [constants.types.DATE]: (val, data) => {
46
45
  if (val instanceof Date && !isNaN(val)) return true;
47
46
  if (typeof val === "string" && !isNaN(Date.parse(val))) {
@@ -86,7 +85,6 @@ const typeChecks = {
86
85
  }
87
86
  return false;
88
87
  },
89
-
90
88
  [constants.types.BOOLEAN]: (val, data) => {
91
89
  if (typeof val === "boolean") return true;
92
90
  if (typeof val === "string") {
@@ -101,10 +99,16 @@ const typeChecks = {
101
99
  return false;
102
100
  },
103
101
  [constants.types.NUMBER]: (val, data) => {
104
- if (typeof val === "number" && !isNaN(val)) return true;
105
- if (typeof val === "string" && !isNaN(parseFloat(val))) {
106
- if (data && data?.key && data?.updateValue) {
107
- data.updateValue(data.key, parseFloat(val));
102
+ if (typeof val === "number" && Number.isFinite(val)) return true;
103
+
104
+ if (
105
+ typeof val === "string" &&
106
+ val.trim() !== "" &&
107
+ /^[+-]?\d+(\.\d+)?$/.test(val)
108
+ ) {
109
+ const num = Number(val);
110
+ if (data?.key && data?.updateValue) {
111
+ data.updateValue(data.key, num);
108
112
  }
109
113
  return true;
110
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nox-validation",
3
- "version": "1.7.6",
3
+ "version": "1.7.8",
4
4
  "description": "validate dynamic schema",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,4 +18,4 @@
18
18
  ],
19
19
  "author": "NowOnline Team",
20
20
  "license": "ISC"
21
- }
21
+ }