A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/syntax-tree/unist-util-size below:

syntax-tree/unist-util-size: utility to calculate the number of nodes in a tree

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

This is a tiny utility that you can use to count nodes (that pass a test) in a tree.

This is super tiny but a sometimes common problem. You can use unist-util-visit yourself as well.

This package is ESM only. In Node.js (version 16+), install with npm:

npm install unist-util-size

In Deno with esm.sh:

import {size} from 'https://esm.sh/unist-util-size@4'

In browsers with esm.sh:

<script type="module">
  import {size} from 'https://esm.sh/unist-util-size@4?bundle'
</script>
import {h} from 'hastscript'
import {size} from 'unist-util-size'

const 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

This package exports the identifier size. There is no default export.

Calculate the number of nodes in tree.

Number of exclusive descendants of tree that pass test (number).

This package is fully typed with TypeScript. It exports no additional types.

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, unist-util-size@^4, compatible with Node.js 16.

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.

MIT © Titus Wormer


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4