Socket
Socket
Sign inDemoInstall

unist-util-flat-filter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-flat-filter

[**unist**][unist] utility to create a new tree with all nodes that pass the given test.


Version published
Weekly downloads
990
decreased by-40.43%
Maintainers
1
Weekly downloads
 
Created
Source

unist-util-filter

[unist][unist] utility to create a new tree with all nodes that pass the given test.

Install

[npm][]:

npm install unist-util-flat-filter

Usage

var u = require('unist-builder')
var flatFilter = require('unist-util-flat-filter')

var tree = u('root', [
  u('leaf', '1'),
  u('node', [u('leaf', '2'), u('node', [u('leaf', '3')])]),
  u('leaf', '4')
])

var newTree = flatFilter(tree, node => node.type === 'leaf')

console.dir(newTree, {depth: null})

Yields:

{
  type: 'root',
  children: [
    { type: 'leaf', value: '1' },
    { type: 'leaf', value: '2' },
    { type: 'leaf', value: '3' },
    { type: 'leaf', value: '4' }
  ]
}

API

filter(tree[, test])

Create a new [tree][] consisting of copies of all nodes that pass test. The tree is walked in [order][], visiting the parent, then the children nodes node itself, etc.

Parameters
  • tree ([Node?][node]) — [Tree][] to filter
  • test ([Test][is], optional) — [is][is]-compatible test (such as a [type][])
Returns

[Node?][node] — New filtered [tree][]. null is returned if tree itself didn’t pass the test, or is cascaded away.

Keywords

FAQs

Package last updated on 15 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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