Comparing version 0.1.0 to 0.1.1
@@ -16,3 +16,3 @@ // | ||
var exists = module.exports.exists = function exists(object, path) { | ||
var exists = (module.exports.exists = function exists(object, path) { | ||
if (typeof path === "string") { | ||
@@ -39,3 +39,3 @@ path = path.split("."); | ||
} | ||
}; | ||
}); | ||
@@ -47,3 +47,3 @@ // | ||
// `undefined` if it can't be found. This means you won't be able to tell | ||
// the difference between an unresolved path and an undefined property, so you | ||
// the difference between an unresolved path and an undefined property, so you | ||
// should not use `get` to check for the existence of a property. Use `exists` | ||
@@ -53,3 +53,3 @@ // instead. | ||
var get = module.exports.get = function get(object, path) { | ||
var get = (module.exports.get = function get(object, path) { | ||
if (typeof path === "string") { | ||
@@ -78,3 +78,3 @@ path = path.split("."); | ||
} | ||
}; | ||
}); | ||
@@ -93,3 +93,3 @@ // | ||
var search = module.exports.search = function search(object, path, action) { | ||
var search = (module.exports.search = function search(object, path, action) { | ||
if (typeof path === "string") { | ||
@@ -120,13 +120,22 @@ path = path.split("."); | ||
if (path.length === 0) { | ||
return Object.keys(object).filter(key.test.bind(key)).map(function(k) { | ||
var value = object[k]; | ||
if(action){ | ||
action(value, object, k); | ||
} | ||
return value; | ||
}); | ||
return Object.keys(object) | ||
.filter(key.test.bind(key)) | ||
.map(function (k) { | ||
var value = object[k]; | ||
if (action) { | ||
action(value, object, k); | ||
} | ||
return value; | ||
}); | ||
} else { | ||
return Array.prototype.concat.apply([], Object.keys(object).filter(key.test.bind(key)).map(function(k) { return search(object[k], path, action); })); | ||
return Array.prototype.concat.apply( | ||
[], | ||
Object.keys(object) | ||
.filter(key.test.bind(key)) | ||
.map(function (k) { | ||
return search(object[k], path, action); | ||
}) | ||
); | ||
} | ||
}; | ||
}); | ||
@@ -138,8 +147,11 @@ // | ||
var removeSearch = module.exports.removeSearch = function removeSearch(object, path){ | ||
search(object, path, function(value, object, key){ | ||
var removeSearch = (module.exports.removeSearch = function removeSearch( | ||
object, | ||
path | ||
) { | ||
search(object, path, function (value, object, key) { | ||
delete object[key]; | ||
}); | ||
return object; | ||
}; | ||
}); | ||
@@ -158,3 +170,3 @@ // | ||
var put = module.exports.put = function put(object, path, value) { | ||
var put = (module.exports.put = function put(object, path, value) { | ||
if (typeof path === "string") { | ||
@@ -167,3 +179,3 @@ path = path.split("."); | ||
} | ||
path = path.slice(); | ||
@@ -173,6 +185,5 @@ | ||
if (typeof object !== "object" || object === null) { | ||
if (typeof object !== "object" || object === null || key === "__proto__") { | ||
return false; | ||
} | ||
if (path.length === 0) { | ||
@@ -191,3 +202,3 @@ object[key] = value; | ||
} | ||
}; | ||
}); | ||
@@ -201,3 +212,3 @@ // | ||
var remove = module.exports.remove = function remove(object, path, value) { | ||
var remove = (module.exports.remove = function remove(object, path, value) { | ||
if (typeof path === "string") { | ||
@@ -210,3 +221,3 @@ path = path.split("."); | ||
} | ||
path = path.slice(); | ||
@@ -231,3 +242,3 @@ | ||
} | ||
}; | ||
}); | ||
@@ -249,3 +260,7 @@ // | ||
var deepKeys = module.exports.deepKeys = function deepKeys(object, options, prefix) { | ||
var deepKeys = (module.exports.deepKeys = function deepKeys( | ||
object, | ||
options, | ||
prefix | ||
) { | ||
options = options || {}; | ||
@@ -269,3 +284,9 @@ | ||
if (typeof object[k] === "object" && object[k] !== null) { | ||
keys = keys.concat(deepKeys(object[k], {leavesOnly: options.leavesOnly}, prefix.concat([k]))); | ||
keys = keys.concat( | ||
deepKeys( | ||
object[k], | ||
{ leavesOnly: options.leavesOnly }, | ||
prefix.concat([k]) | ||
) | ||
); | ||
} | ||
@@ -275,6 +296,8 @@ } | ||
if (options.asStrings) { | ||
keys = keys.map(function(e) { return e.join("."); }); | ||
keys = keys.map(function (e) { | ||
return e.join("."); | ||
}); | ||
} | ||
return keys; | ||
}; | ||
}); |
{ | ||
"name": "dotty", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Access properties of nested objects using dot-path notation", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -0,0 +0,0 @@ Dotty [![build status](https://secure.travis-ci.org/deoxxa/dotty.png)](http://travis-ci.org/deoxxa/dotty) [![npm](https://img.shields.io/npm/v/dotty.svg)](https://www.npmjs.com/package/dotty) |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
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
10749
4
233
2