visit-values
Advanced tools
Comparing version 1.0.4 to 2.0.0
20
index.js
@@ -0,1 +1,3 @@ | ||
'use strict' | ||
/* | ||
@@ -8,6 +10,7 @@ visit all the children of a javascript object | ||
*/ | ||
var visit = module.exports = function (current, fn) { | ||
let visit = module.exports = (current, fn) => { | ||
for (var k in current) { | ||
var value = current[k] | ||
for (let i = 0, keys = Object.keys(current); i < keys.length; i++) { | ||
let key = keys[i] | ||
let value = current[key] | ||
@@ -17,8 +20,15 @@ if (value === undefined || value === null) continue | ||
if (typeof value === 'object' || typeof value === 'function') { | ||
visit(current[k], fn) | ||
visit(current[key], fn) | ||
continue | ||
} | ||
fn(current[k], k, current) | ||
let proceed = fn(current[key], key, current) | ||
// returning false (and only false) | ||
// from the visitor function will stop the | ||
// visitations | ||
if (proceed === false) { | ||
break; | ||
} | ||
} | ||
} |
{ | ||
"name": "visit-values", | ||
"version": "1.0.4", | ||
"version": "2.0.0", | ||
"description": "visit all the children of a javascript object", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
10
test.js
@@ -1,7 +0,9 @@ | ||
var assert = require('assert') | ||
var visitValues = require('./index.js') | ||
'use strict' | ||
const assert = require('assert') | ||
const visitValues = require('./index.js') | ||
describe('visit', function () { | ||
it('visits', function() { | ||
var tree = { | ||
let tree = { | ||
a: { | ||
@@ -19,3 +21,3 @@ b: { | ||
var results = [] | ||
let results = [] | ||
@@ -22,0 +24,0 @@ visitValues(tree, function(v, k, p) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3326
51
1