summaryrefslogtreecommitdiffstats
path: root/node_modules/mongoose/lib/helpers/arrayDepth.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/mongoose/lib/helpers/arrayDepth.js')
-rw-r--r--node_modules/mongoose/lib/helpers/arrayDepth.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/node_modules/mongoose/lib/helpers/arrayDepth.js b/node_modules/mongoose/lib/helpers/arrayDepth.js
new file mode 100644
index 0000000..2c6f2e5
--- /dev/null
+++ b/node_modules/mongoose/lib/helpers/arrayDepth.js
@@ -0,0 +1,30 @@
+'use strict';
+
+module.exports = arrayDepth;
+
+function arrayDepth(arr) {
+ if (!Array.isArray(arr)) {
+ return { min: 0, max: 0, containsNonArrayItem: true };
+ }
+ if (arr.length === 0) {
+ return { min: 1, max: 1, containsNonArrayItem: false };
+ }
+
+ const res = arrayDepth(arr[0]);
+
+ for (let i = 1; i < arr.length; ++i) {
+ const _res = arrayDepth(arr[i]);
+ if (_res.min < res.min) {
+ res.min = _res.min;
+ }
+ if (_res.max > res.max) {
+ res.max = _res.max;
+ }
+ res.containsNonArrayItem = res.containsNonArrayItem || _res.containsNonArrayItem;
+ }
+
+ res.min = res.min + 1;
+ res.max = res.max + 1;
+
+ return res;
+} \ No newline at end of file