Package Exports
- snapdragon-util
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (snapdragon-util) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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-utilUsage
var util = require('snapdragon-util');API
.noop
Emit an empty string to effectively "skip" the string for the given node, but still emit the position and node type.
Params
- {Object}: node
Example
// do nothing for beginning-of-string
snapdragon.compiler.set('bos', utils.noop);.emit
Emit an empty string to effectively "skip" the string for the given node, but still emit the position and node type.
Params
- {Object}: node
Example
snapdragon.compiler
.set('i', function(node) {
this.mapVisit(node);
})
.set('i.open', utils.emit('<i>'))
.set('i.close', utils.emit('</i>')).toNoop
Converts an AST node into an empty text node and delete node.nodes.
Params
node{Object}
Example
utils.toNoop(node);
utils.toNoop(node, true); // convert `node.nodes` to an empty array.visit
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) {
// do stuff with "node2"
return node2;
});
}).mapVisit
Map visit with the given fn over an array of AST nodes.
Example
snapdragon.compiler
.set('i', function(node) {
exports.mapVisit(node, function(node2) {
// do stuff with "node2"
return node2;
});
}).wrapNodes
Wrap the given node with *.open and *.close tags.
Params
node{Object}: (required)Node{Function}: (required)filter{Function}: Optionaly specify a filter function to exclude the node.returns{undefined}
.addOpen
Unshift an *.open node onto node.nodes.
Params
node{Object}filter{Function}: Optionaly specify a filter function to exclude the node.returns{undefined}
.addClose
Push a *.close node onto node.nodes.
Params
node{Object}filter{Function}: Optionaly specify a filter function to exclude the node.returns{undefined}
.pushNode
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) // 'bar'.unshiftNode
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) // 'bar'.firstOfType
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) {
// do stuff with text node
}
});.arrayify
Cast the given val to an array.
Params
val{any}returns{Array}
.stringify
Convert the given val to a string by joining with ,. Useful
for creating a selector from a list of strings.
Params
val{any}returns{Array}
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#dev verb-generate-readme && verbRunning 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 testAuthor
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert. MIT
This file was generated by verb-generate-readme, v0.4.2, on February 15, 2017.