nox-validation 1.7.5 → 1.7.7

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.
Files changed (2) hide show
  1. package/lib/validate.js +14 -7
  2. package/package.json +2 -2
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
  }
@@ -540,7 +544,10 @@ const validateMetaRules = (
540
544
  if (!currentPath.includes(fPath)) {
541
545
  fPath = `${currentPath}.${fPath}`;
542
546
  }
543
- } else if (fPath !== currentPath) {
547
+ } else if (
548
+ fPath !== currentPath &&
549
+ fPath?.length < currentPath?.length
550
+ ) {
544
551
  fPath = currentPath;
545
552
  }
546
553
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nox-validation",
3
- "version": "1.7.5",
3
+ "version": "1.7.7",
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
+ }