option-tree-filter

filter an option tree

Usage no npm install needed!

<script type="module">
  import optionTreeFilter from 'https://cdn.skypack.dev/option-tree-filter';
</script>

README

option-tree-filter build status

Filter an option tree


var FilterTree = require('option-tree-filter')
var assert = require('assert')

var tree = FilterTree([{
  id: '1',
  options: [
    {id: 'a'},
    {id: 'b'}
  ]
}, {
  id: '2',
  options: [{
    id: 'c',
    options: [
      {id: 'd'}
    ]
  }]
}, {
  id: '3',
  options: [
    {id: 'e'},
    {id: 'f'}
  ]
}], function idExact (opt, query) {
  return opt.id && opt.id === query
})

// returns a copy. original data is unchanged.
assert.deepEqual(tree.query('e'), [{
  id: '3',
  options: [
    {
      id: 'e',
      passes: true,
      keep: true
    }
  ],
  passes: false,
  keep: true
}])

usage