isvalid 2.10.3 → 2.10.4

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/key-paths.js +24 -10
  2. package/package.json +1 -1
package/lib/key-paths.js CHANGED
@@ -8,7 +8,17 @@ exports = module.exports = (schema, formalizeOptions) => {
8
8
  schema = formalize(schema, formalizeOptions);
9
9
 
10
10
  return {
11
- all: (types, keyPath = []) => {
11
+ all: (types, options, keyPath = [], level = 0) => {
12
+
13
+ if (typeof types === 'object' && types !== null && !Array.isArray(types)) {
14
+ options = types;
15
+ types = [];
16
+ }
17
+
18
+ options = options || {};
19
+ options.maxDepth = typeof options.maxDepth !== 'undefined' ? options.maxDepth : Infinity;
20
+
21
+ if (typeof options.maxDepth !== 'number') throw new Error('Maximum depth must be a number.');
12
22
 
13
23
  if (!types) types = [];
14
24
  if (!Array.isArray(types)) types = [types];
@@ -21,15 +31,19 @@ exports = module.exports = (schema, formalizeOptions) => {
21
31
 
22
32
  if (types.length == 0 || types.includes(typeName)) result.push(keyPath.join('.'));
23
33
 
24
- switch (typeName) {
25
- case 'object':
26
- result = result.concat(...Object.keys(schema.schema).map((key) => {
27
- return exports(schema.schema[key]).all(types, keyPath.concat([key]));
28
- }));
29
- break;
30
- case 'array':
31
- result = result.concat(exports(schema.schema).all(types, keyPath));
32
- break;
34
+ if (level < options.maxDepth) {
35
+
36
+ switch (typeName) {
37
+ case 'object':
38
+ result = result.concat(...Object.keys(schema.schema).map((key) => {
39
+ return exports(schema.schema[key]).all(types, options, keyPath.concat([key]), level + 1);
40
+ }));
41
+ break;
42
+ case 'array':
43
+ result = result.concat(exports(schema.schema).all(types, options, keyPath, level + 1));
44
+ break;
45
+ }
46
+
33
47
  }
34
48
 
35
49
  let uniqueResult = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isvalid",
3
- "version": "2.10.3",
3
+ "version": "2.10.4",
4
4
  "description": "Async JSON validation library for node.js.",
5
5
  "main": "./index.js",
6
6
  "keywords": [