All Projects → syntax-tree → nlcst-to-string

syntax-tree / nlcst-to-string

Licence: MIT license
utility to transform an nlcst tree to a string

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to nlcst-to-string

hast-util-to-html
utility to serialize hast to HTML
Stars: ✭ 47 (+193.75%)
Mutual labels:  syntax-tree, util, stringify, unist
hast-util-sanitize
utility to sanitize hast nodes
Stars: ✭ 34 (+112.5%)
Mutual labels:  syntax-tree, util, unist
unist-builder
utility to create a new trees with a nice syntax
Stars: ✭ 52 (+225%)
Mutual labels:  syntax-tree, util, unist
unist-util-inspect
utility to inspect nodes
Stars: ✭ 16 (+0%)
Mutual labels:  syntax-tree, util, unist
mdast-util-to-string
utility to get the plain text content of an mdast node
Stars: ✭ 27 (+68.75%)
Mutual labels:  syntax-tree, util, unist
unist-util-map
utility to create a new tree by mapping all nodes
Stars: ✭ 30 (+87.5%)
Mutual labels:  syntax-tree, util, unist
unist-util-visit-parents
utility to recursively walk over unist nodes, with ancestral information
Stars: ✭ 25 (+56.25%)
Mutual labels:  syntax-tree, util, unist
hast-util-from-dom
utility to transform a DOM tree to hast
Stars: ✭ 20 (+25%)
Mutual labels:  syntax-tree, util, unist
unist-util-select
utility to select unist nodes with CSS-like selectors
Stars: ✭ 41 (+156.25%)
Mutual labels:  util, unist
MarkdownSyntax
☄️ A Type-safe Markdown parser in Swift.
Stars: ✭ 65 (+306.25%)
Mutual labels:  syntax-tree, unist
ntast
Notion Abstract Syntax Tree specification.
Stars: ✭ 101 (+531.25%)
Mutual labels:  syntax-tree, unist
mdast-util-to-hast
utility to transform mdast to hast
Stars: ✭ 53 (+231.25%)
Mutual labels:  syntax-tree, unist
Unified
☔️ interface for parsing, inspecting, transforming, and serializing content through syntax trees
Stars: ✭ 3,036 (+18875%)
Mutual labels:  syntax-tree, unist
xast
Extensible Abstract Syntax Tree
Stars: ✭ 32 (+100%)
Mutual labels:  syntax-tree, unist
Unist Util Visit
utility to visit nodes
Stars: ✭ 101 (+531.25%)
Mutual labels:  syntax-tree, util
sast
Parse CSS, Sass, SCSS, and Less into a unist syntax tree
Stars: ✭ 51 (+218.75%)
Mutual labels:  syntax-tree, unist
stringify-keys
Build an array of key paths from an object.
Stars: ✭ 18 (+12.5%)
Mutual labels:  stringify
await
28Kb, small memory footprint, single binary that run list of commands in parallel and waits for their termination
Stars: ✭ 73 (+356.25%)
Mutual labels:  util
Superstring
A fast and memory-optimized string library for C++
Stars: ✭ 252 (+1475%)
Mutual labels:  string
Stringsimilarity.net
A .NET port of java-string-similarity
Stars: ✭ 242 (+1412.5%)
Mutual labels:  string

nlcst-to-string

Build Coverage Downloads Size Sponsors Backers Chat

nlcst utility to serialize a node.

Contents

What is this?

This package is a utility that takes nlcst nodes and gets their plain-text value.

When should I use this?

This is a small utility that is useful when you’re dealing with ASTs.

Install

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

npm install nlcst-to-string

In Deno with esm.sh:

import {toString} from 'https://esm.sh/nlcst-to-string@3'

In browsers with esm.sh:

<script type="module">
  import {toString} from 'https://esm.sh/nlcst-to-string@3?bundle'
</script>

Use

import {toString} from 'nlcst-to-string'

console.log(
  toString({
    type: 'WordNode',
    children: [
      {type: 'TextNode', value: 'AT'},
      {type: 'PunctuationNode', value: '&'},
      {type: 'TextNode', value: 'T'}
    ]
  })
) // => 'AT&T'

API

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

toString(value[, separator])

Get the text content of a node or list of nodes.

Prefers the node’s plain-text fields, otherwise serializes its children, and if the given value is an array, serialize the nodes in it.

Parameters
  • node (Node or Array<Node>) — node to serialize.
  • separator (string, default: '') — value to delimit each item
Returns

Result (string).

Types

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

Compatibility

Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.

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, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].