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

breadth-filter

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

breadth-filter - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

15

index.js

@@ -1,8 +0,11 @@

function targetFor (source) {
if (Array.isArray(source)) return []
if (typeof source === 'object') return {}
function targetFor (source, destructive) {
if (Array.isArray(source)) {
return destructive ? source : []
} else if (typeof source === 'object') {
return destructive ? source : {}
}
}
module.exports = function breadthFilter (root, fn) {
const target = targetFor(root)
module.exports = function breadthFilter (root, fn, destructive) {
const target = targetFor(root, destructive)
if (!target) return root

@@ -17,3 +20,3 @@

const fieldPath = path.concat(key)
const newTarget = targetFor(value)
const newTarget = targetFor(value, destructive)
if (newTarget) {

@@ -20,0 +23,0 @@ target[key] = newTarget

2

package.json
{
"name": "breadth-filter",
"version": "1.0.0",
"version": "1.1.0",
"description": "Breadth-first deep object filter",

@@ -5,0 +5,0 @@ "author": "Stephen Belanger <admin@stephenbelanger.com> (https://github.com/qard)",

@@ -123,3 +123,3 @@ const tap = require('tap')

tap.test('does not mutate', (t) => {
tap.test('does not mutate by default', (t) => {
const input = {

@@ -148,1 +148,26 @@ foo: {

})
tap.test('mutates in destructive mode', (t) => {
const input = {
foo: {
bar: {
baz: 'buz'
},
bux: 'bax'
}
}
breadthFilter(input, reverse, true)
const expected = {
foo: {
bar: {
baz: 'zub'
},
bux: 'xab'
}
}
t.deepEqual(input, expected, 'matches expected output')
t.end()
})
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