-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSDoc added, include/exclude array functionality for depth and comple…
…xity methods
- Loading branch information
Showing
4 changed files
with
86 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
const determineDepth = (jt, obj) => { | ||
const determineDepth = (jt, obj, includeArrays) => { | ||
let depth = 0; | ||
jt.traverse(obj, { enterLevel: (level, path) => { if (level > depth) depth = level; } }); | ||
jt.traverse(obj, { enterLevel: (level, path) => { if (level > depth) depth = level; } }, !includeArrays); | ||
return depth; | ||
} | ||
|
||
module.exports.getDepth = (jt, obj) => { | ||
return determineDepth(jt, obj); | ||
module.exports.getDepth = (jt, obj, includeArrays) => { | ||
return determineDepth(jt, obj, includeArrays); | ||
} | ||
|
||
module.exports.isSimple = (jt, obj) => { | ||
return determineDepth(jt, obj) === 0; | ||
module.exports.isSimple = (jt, obj, includeArrays) => { | ||
return determineDepth(jt, obj, includeArrays) === 0; | ||
} | ||
|
||
module.exports.isComplex = (jt, obj) => { | ||
return determineDepth(jt, obj) > 0; | ||
module.exports.isComplex = (jt, obj, includeArrays) => { | ||
return determineDepth(jt, obj, includeArrays) > 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"testArray": [ | ||
1, | ||
2, | ||
{ | ||
"firstName": "Dow", | ||
"lastName": "Jones", | ||
"country": { | ||
"name": "United States", | ||
"code": "US" | ||
} | ||
}, | ||
"four" | ||
] | ||
} |