unified

Project: syntax-tree/unist-util-size

Package: unist-util-size@2.0.0

  1. Dependencies: 1·Dependents: 2
  2. unist utility to calculate the number of nodes in a tree
  1. util 118
  2. utility 114
  3. unist 110
  4. unist-util 24
  5. node 21
  6. count 4
  7. size 2

unist-util-size

Build Coverage Downloads Size Sponsors Backers Chat

unist utility to calculate the number of nodes in a tree.

Install

npm:

npm install unist-util-size

Use

var h = require('hastscript')
var size = require('unist-util-size')

var tree = h('div', [
  h('p', [
    'Some ',
    h('strong', 'importance'),
    ' and ',
    h('em', 'emphasis'),
    '.'
  ]),
  h('pre', h('code', 'bar()'))
])

console.log(size(tree)) // => 11
console.log(size(tree, 'element')) // => 5

API

size(tree[, test])

Calculate the number of nodes in tree.

Parameters
Returns

number — Number of exclusive descendants passing test in tree.

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer