JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9847985
  • Score
    100M100P100Q235261F
  • License MIT

Utilities for the snapdragon parser/compiler.

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 NPM version NPM monthly downloads NPM total downloads Linux Build Status

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

.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', helpers.emit('<i>'))
  .set('i.close', helpers.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) {
    utils.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) {
    utils.mapVisit(node, function(node2) {
      // do stuff with "node2"
      return node2;
    });
  })

.wrapNodes

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}

.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 = utils.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 document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT license.


This file was generated by verb-generate-readme, v0.4.1, on January 21, 2017.