Awesome
snippet
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
oryaml
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
Snippets
Create an instance of Snippets
with the given options.
Params
options
{Object}
Example
var Snippets = require('snippets');
var snippets = new Snippets();
.set
Cache a snippet or arbitrary value in memory.
Params
name
{String}: The snippet nameval
{any}returns
{Object}: Returns theSnippet
instance for chaining
.addSnippet
Cache a snippet in memory. Creates a Snippet
instance
with the given value
.
Params
name
{String}: The snippet nameval
{any}returns
{Object}: Returns theSnippet
instance for chaining
.addSnippets
Create a new Snippet()
from a snippet object,
or array of snippet objects.
Params
snippets
{Object|Array}
.save
Persist a snippet or arbitrary value to disk.
Params
name
{String}val
{any}returns
{Object}: Returns theSnippet
instance for chaining
.get
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.
.del
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 deletereturns
{Object}Snippets
: instance, for chaining
.load
Load a glob of snippets.
Params
- {String|Array}: `snippets
options
{Object}returns
{Object}Snippets
: for chaining
.read
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}
.preset
Set a preset config
for downloading snippets from a remote URL.
Params
name
{String}config
{Object}returns
{Object}
.queue
Queue a remote snippet to be downloaded from the given URL, and
optional preset
.
Params
url
{String}preset
{Object}: The namereturns
{Object}: Returns a snippet object.
.fetch
Fetch a remote snippet from the given URL.
Params
url
{String}preset
{Object}returns
{Object}: Returns a snippet object.
.expand
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.