snapdragon-node
Snapdragon utility for creating a new AST node in custom code, such as plugins.
Install
Install with npm:
Usage
With snapdragon v0.9.0 and higher you can use this.node()
to create a new Node
, whenever it makes sense.
API
Create a new AST Node
with the given val
and type
.
Params
val
{String|Object}: Pass a matched substring, or an object to merge onto the node.type
{String}: The node type to use whenval
is a string.returns
{Object}: node instance
Example
Returns true if the given value is a node.
Params
node
{Object}returns
{Boolean}
Example
Define a non-enumberable property on the node instance. Useful for adding properties that shouldn't be extended or visible during debugging.
Params
name
{String}val
{any}returns
{Object}: returns the node instance
Example
Returns true if node.val
is an empty string, or node.nodes
does not contain any non-empty text nodes.
Params
fn
{Function}: (optional) Filter function that is called onnode
and/or child nodes.isEmpty
will return false immediately when the filter function returns false on any nodes.returns
{Boolean}
Example
Given node foo
and node bar
, push node bar
onto foo.nodes
, and set foo
as bar.parent
.
Params
node
{Object}returns
{Number}: Returns the length ofnode.nodes
Example
Given node foo
and node bar
, unshift node bar
onto foo.nodes
, and set foo
as bar.parent
.
Params
node
{Object}returns
{Number}: Returns the length ofnode.nodes
Example
Pop a node from node.nodes
.
returns
{Number}: Returns the poppednode
Example
Shift a node from node.nodes
.
returns
{Object}: Returns the shiftednode
Example
Remove node
from node.nodes
.
Params
node
{Object}returns
{Object}: Returns the removed node.
Example
Get the first child node from node.nodes
that matches the given type
. If type
is a number, the child node at that index is returned.
Params
type
{String}returns
{Object}: Returns a child node or undefined.
Example
Return true if the node is the given type
.
Params
type
{String}returns
{Boolean}
Example
Return true if the node.nodes
has the given type
.
Params
type
{String}returns
{Boolean}
Example
returns
{Array}
Example
returns
{Number}
Example
returns
{Object}
Example
returns
{Object}
Example
returns
{Object}: The first node, or undefiend
Example
returns
{Object}: The last node, or undefiend
Example
returns
{Object}: The last node, or undefiend
Example
Release history
Changelog entries are classified using the following labels from keep-a-changelog:
added
: for new featureschanged
: for changes in existing functionalitydeprecated
: for once-stable features removed in upcoming releasesremoved
: for deprecated features removed in this releasefixed
: for any bug fixes
Custom labels used in this changelog:
dependencies
: bumps dependencieshousekeeping
: code re-organization, minor edits, or other changes that don't fit in one of the other categories.
[2.0.0] - 2017-05-01
Changed
Added
[0.1.0]
First release.
About
Related projects
breakdance: Breakdance is a node.js library for converting HTML to markdown. Highly pluggable, flexible and easy… more | homepage
snapdragon-capture: Snapdragon plugin that adds a capture method to the parser instance. | homepage
snapdragon-cheerio: Snapdragon plugin for converting a cheerio AST to a snapdragon AST. | homepage
snapdragon-util: Utilities for the snapdragon parser/compiler. | homepage
snapdragon: Easy-to-use plugin system for creating powerful, fast and versatile parsers and compilers, with built-in source-map… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on June 25, 2017.
Last updated