escape-delims
v0.4.0
Published
Escape and un-escape delimiters in templates. Tested with Lo-Dash, underscore and Handlebars syntax, but could be used with other template engines/syntaxes as well. This is similar to the process used by Yeoman on escaped templates in generators.
Downloads
367
Maintainers
Keywords
Readme
escape-delims
Escape and un-escape delimiters in templates. Tested with Lo-Dash, underscore and Handlebars syntax, but could be used with other template engines/syntaxes as well. This is similar to the process used by Yeoman on escaped templates in generators.
Install
Install with npm:
npm i escape-delims --save-dev
Usage
var EscapeDelims = require('escape-delims');
API
EscapeDelims
Create a new instance of EscapeDelims()
:
from
{Array}: Optionally pass delimiters to use for escaping. Defaults to['{%%', '%}']
.to
{Array}: Optionally pass delimiters to use for un-escaping. Defaults to['{%%', '%}']
.
var EscapeDelims = require('escape-delims');
var escapeDelims = new EscapeDelims();
Optionally pass the "escape delimiters" to use as an array:
var escapeDelims = new EscapeDelims(['<%%', '%>']);
.escape
Escape the given str
, optionally passing a delimiter syntax
to use if not defined in the constructor.
str
{String}: The string with delimiters to escape.from
{Array}: The delimiter syntax to use.
Example:
escapeDelims.escape('<%%= first %><%= last %>', ['<%%', '%>']);
//=> '(;^__^;) first (;\^_\^;)<%= last %>'
.unescape
Un-escape previously escaped delimiters in the given str
. Optionally pass the syntax
to use if they have not already been defined.
str
{String}: The string with delimiters that need to be escaped.to
{Array}: The delimiter syntax to use for un-escaping.
Example:
escapeDelims.unescape('(;^__^;) first (;\^_\^;)<%= last %>', ['<%%', '%>']);
//=> '<%= first %><%= last %>'
Author
Jon Schlinkert
License
Copyright (c) 2014 Jon Schlinkert
Released under the MIT license
This file was generated by verb on November 11, 2014.