inject-snippet

0.3.0 • Public • Published

inject-snippet NPM version

Inject a snippet of code or content into a string.

Install

Install with npm

$ npm i inject-snippet --save

Usage

var inject = require('inject-snippet');

Keep placeholders

Inject a snippet into a string with placeholders (used for subsequent insertions):

var str = 'before <!-- snippet --> after';
inject(str, 'foo');
//=> 'before <!-- snippet -->\nfoo\n<!-- endsnippet --> after'

Strip placeholders

Inject a snippet into a string without placeholders:

var str = 'before <!-- snippet --> after';
inject(str, 'foo', {stripTags: true})
//=> 'before foo after'

Use a custom tag name

Customize the placeholder name:

var str = 'before <!-- xyz --> after';
inject(str, 'foo', {tag: 'xyz'})
//=> 'before foo after'

Use custom delimiters

Customize the placeholder delimiters:

var str = '<body>\n\n</body>';
inject(str, 'foo', {delimiters: ['']});
// results in:
// <body>
// foo
// </body>

Related projects

  • assemble: Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt,… more
  • boilerplate: Easily create, share and use boilerplates for node.js and web projects.
  • snippet: CLI and API for easily creating, reusing, sharing and generating snippets of code from the… more
  • scaffold: Generate a project or files from scaffolds.
  • verb: Documentation generator for GitHub projects. Extremely powerful, easy to use, can generate anything from API… more

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 17, 2015.

Package Sidebar

Install

npm i inject-snippet

Weekly Downloads

78

Version

0.3.0

License

MIT

Last publish

Collaborators

  • jonschlinkert
  • doowb