Skip to content

CLI and API for easily creating, reusing, sharing and generating snippets of code or data from the command line. WIP. Node.js/JavaScript

License

Notifications You must be signed in to change notification settings

boilerplates/snippet

Repository files navigation

snippet NPM version

CLI and API for easily creating, reusing, sharing and generating snippets of code from the command line.

  • CLI
  • API (75% done)
  • expand emmet snippets
  • expand emmet snippets in the command line.
  • set, get, and delete snippets of code or data that can easily be reused in any project
  • fetch snippets from github or other remotes using presets
  • render snippets using data from json or yaml files, or using expand-object
  • inject snippets into other files using customizable markers
  • prepend files/strings with snippets
  • append files/strings with snippets
  • Add expanded snippets to the clipboard so you can paste them wherever you want!

More to come!

Install

Install with npm

$ npm i snippet --save

Usage

var snippet = require('snippet');

Emmet

(WIP! This is just one feature of Snippet! A lot more is on the way!)

Expand emmet snippets

snippets.expand('ul>li.item$*3');

Results in:

<ul>
  <li class="item1"><%= param0 %></li>
  <li class="item2"><%= param1 %></li>
  <li class="item3"><%= param2 %></li>
</ul>

Expand emmet snippets with custom placehoders

snippets.expand('ul>li.item$*3', ['a', 'b', 'c']);

Results in:

<ul>
  <li class="item1"><%= a %></li>
  <li class="item2"><%= b %></li>
  <li class="item3"><%= c %></li>
</ul>

API

Create an instance of Snippets with the given options.

Params

  • options {Object}

Example

var Snippets = require('snippets');
var snippets = new Snippets();

Cache a snippet or arbitrary value in memory.

Params

  • name {String}: The snippet name
  • val {any}
  • returns {Object}: Returns the Snippet instance for chaining

Cache a snippet in memory. Creates a Snippet instance with the given value.

Params

  • name {String}: The snippet name
  • val {any}
  • returns {Object}: Returns the Snippet instance for chaining

Create a new Snippet() from a snippet object, or array of snippet objects.

Params

  • snippets {Object|Array}

Persist a snippet or arbitrary value to disk.

Params

  • name {String}
  • val {any}
  • returns {Object}: Returns the Snippet instance for chaining

Get a snippet or arbitrary value by name. Cached, local, or remote.

Params

  • name {String}
  • preset {Object}: Preset to use if a URL is passed.
  • returns {Object}: Returns the requested snippet.

Delete snippet name from memory and/or snippet-store. This will not delete actual snippet files saved on disk, only cached snippets.

Params

  • name {String}: The name of the snippet to delete
  • returns {Object} Snippets: instance, for chaining

Load a glob of snippets.

Params

  • {String|Array}: `snippets
  • options {Object}
  • returns {Object} Snippets: for chaining

Read a snippet from the file system. If the snippet is already in memory and is an instance of Snippet, the .read() method is called on the snippet. Otherwise, a new Snippet() is created first before calling the .read() method on the snippet.

Params

  • {Object|String}: snippet
  • returns {Object}

Set a preset config for downloading snippets from a remote URL.

Params

  • name {String}
  • config {Object}
  • returns {Object}

Queue a remote snippet to be downloaded from the given URL, and optional preset.

Params

  • url {String}
  • preset {Object}: The name
  • returns {Object}: Returns a snippet object.

Fetch a remote snippet from the given URL.

Params

  • url {String}
  • preset {Object}
  • returns {Object}: Returns a snippet object.

Expand a snippet of code or data.

Params

  • str {String}
  • {Object}: `data

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on August 13, 2015.

About

CLI and API for easily creating, reusing, sharing and generating snippets of code or data from the command line. WIP. Node.js/JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published