Socket
Socket
Sign inDemoInstall

snapdragon-util

Package Overview
Dependencies
13
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    snapdragon-util

Utilities for the snapdragon parser/compiler.


Version published
Weekly downloads
10M
decreased by-10.43%
Maintainers
1
Install size
142 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 05 Feb 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc