snapdragon-util
Utilities for the snapdragon parser/compiler.
Table of Contents
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [About](#about)
Install
Install with npm:
$ npm install --save snapdragon-util
Usage
var util = require('snapdragon-util');
API
Emit an empty string to effectively "skip" the string for the given node
, but still emit the position and node type.
Params
Example
snapdragon.compiler.set('bos', utils.noop);
Emit an empty string to effectively "skip" the string for the given node
, but still emit the position and node type.
Params
Example
snapdragon.compiler
.set('i', function(node) {
this.mapVisit(node);
})
.set('i.open', utils.emit('<i>'))
.set('i.close', utils.emit('</i>'))
Converts an AST node into an empty text
node and delete node.nodes
.
Params
Example
utils.toNoop(node);
utils.toNoop(node, true);
Visit node
with the given fn
. The built-in .visit
method in snapdragon automatically calls registered compilers, this allows you to pass a visitor function.
Params
node
{Object}fn
{Function}returns
{Object}: returns the node
Example
snapdragon.compiler
.set('i', function(node) {
exports.visit(node, function(node2) {
return node2;
});
})
Map visit with the given fn
over an array of AST nodes
.
Example
snapdragon.compiler
.set('i', function(node) {
exports.mapVisit(node, function(node2) {
return node2;
});
})
Wrap the given node
with *.open
and *.close
tags.
Params
node
{Object}filter
{Function}: Optionaly specify a filter function to exclude the node.returns
{undefined}
Unshift an *.open
node onto node.nodes
.
Params
node
{Object}filter
{Function}: Optionaly specify a filter function to exclude the node.returns
{undefined}
Push a *.close
node onto node.nodes
.
Params
node
{Object}filter
{Function}: Optionaly specify a filter function to exclude the node.returns
{undefined}
Push node
onto parent.nodes
.
Params
node
{Object}filter
{Function}: Optionaly specify a filter function to exclude the node.returns
{undefined}
Example
var parent = new Node({type: 'foo'});
var node = new Node({type: 'bar'});
utils.pushNode(parent, node);
console.log(parent.nodes[0].type)
Unshift node
onto parent.nodes
.
Params
node
{Object}returns
{undefined}
Example
var parent = new Node({type: 'foo'});
var node = new Node({type: 'bar'});
utils.unshiftNode(parent, node);
console.log(parent.nodes[0].type)
Return the first node from nodes
of the given type
Params
nodes
{Array}type
{String}returns
{Object}: Returns a node, if found
Example
snapdragon.set('div', function(node) {
var textNode = exports.firstOfType(node.nodes, 'text');
if (textNode) {
}
});
Cast the given val
to an array.
Params
Convert the given val
to a string by joining with ,
. Useful
for creating a selector from a list of strings.
Params
About
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:
$ npm install -g verbose/verb
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:
$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert.
MIT
This file was generated by verb-generate-readme, v0.4.2, on February 15, 2017.