Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

libnested

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libnested - npm Package Compare versions

Comparing version 1.1.0 to 1.2.1

33

index.js

@@ -5,5 +5,5 @@ function isObject (o) {

function get (obj, path) {
function get (obj, path, dft) {
for(var i = 0; i < path.length; i++) {
if(null == (obj = obj[path[i]])) return obj
if(null == (obj = obj[path[i]])) return dft
}

@@ -14,3 +14,3 @@ return obj

function set (obj, path, value) {
if(!obj) throw new Error('must be a an object')
if(!obj) throw new Error('libnested.set: first arg must be an object')
for(var i = 0; i < path.length; i++)

@@ -26,9 +26,9 @@ if(i === path.length - 1)

function each (obj, iter, _a) {
_a = _a || []
function each (obj, iter, path) {
path = path || []
for(var k in obj) {
if(isObject(obj[k])) {
if(false === each(obj[k], iter, _a.concat(k))) return false
if(false === each(obj[k], iter, path.concat(k))) return false
} else {
if(false === iter(obj[k], _a.concat(k))) return false
if(false === iter(obj[k], path.concat(k))) return false
}

@@ -39,16 +39,16 @@ }

function map (obj, iter) {
var o = {}
each(obj, function (v, path) {
set(o, path, iter(v, path))
function map (obj, iter, out) {
var out = out || {}
each(obj, function (val, path) {
set(out, path, iter(val, path))
})
return o
return out
}
function paths (obj) {
var p = []
var out = []
each(obj, function (_, path) {
p.push(path)
out.push(path)
})
return p
return out
}

@@ -61,4 +61,1 @@

exports.paths = paths
{
"name": "libnested",
"description": "",
"version": "1.1.0",
"version": "1.2.1",
"homepage": "https://github.com/dominictarr/libnested",

@@ -6,0 +6,0 @@ "repository": {

@@ -15,5 +15,5 @@ # libnested

### map (object, iter(value, path) => _value) => _object
### map (object, iter(value, path) => nextValue, output) => output
map over a nested object (depth first). A new object is returned, containing values returned by `iter`.
map over a nested object (depth first). A new object is returned (unless `output` is given), containing values returned by `iter`.

@@ -24,6 +24,6 @@ ### paths (object) => [path...]

### get(object, path) => value
### get(object, path, default) => value
get the `value` at `path` within object.
if `path` does not exist in the `object`, return null.
if `path` does not exist in the `object`, return `default`.

@@ -30,0 +30,0 @@ ### set(object, path, value)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc