Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "delims", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": [ | ||
@@ -5,0 +5,0 @@ "index.js" |
43
index.js
@@ -13,37 +13,8 @@ /* | ||
var _ = require('lodash'); | ||
var utils = require('./lib/utils'); | ||
var arrayify = function(arr) { | ||
return !Array.isArray(arr) ? [arr] : _.compact(arr); | ||
}; | ||
// Escape custom template delimiters | ||
var escapeDelim = function (re) { | ||
return re.replace(/(.)/g, '\\$1'); | ||
}; | ||
// Build RegExp patterns for delimiters | ||
var buildRegexGroup = function (re, options) { | ||
var opts = _.extend({ | ||
escape: false, // Escape delimiter regex | ||
noncapture: false // Build a non-capture group | ||
}, options); | ||
re = arrayify(re); | ||
var len = re.length; | ||
re = (len > 0) ? re.join('|') : re; | ||
re = (opts.escape === true) ? escapeDelim(re) : re; | ||
if(opts.noncapture === true || len > 1) { | ||
re = '(?:' + re + ')'; | ||
} | ||
return re; | ||
}; | ||
// Generate RegExp patterns dynamically. By default, patterns use | ||
// [\s\S] instead to avoid the need for multiline and dotall flags. | ||
module.exports = function (delims, options) { | ||
var delims = module.exports = function (delims, options) { | ||
if(!_.isArray(delims)) {options = delims; delims = ['---', '---'];} | ||
@@ -62,4 +33,4 @@ | ||
// Generate regex ections | ||
var open = buildRegexGroup(delims[0], opts); | ||
var close = buildRegexGroup(delims[1], opts); | ||
var open = utils.buildRegexGroup(delims[0], opts); | ||
var close = utils.buildRegexGroup(delims[1], opts); | ||
var block = opts.matter + close + opts.body + opts.end; | ||
@@ -73,2 +44,6 @@ | ||
}; | ||
}; | ||
}; | ||
delims.arrayify = utils.arrayify; | ||
delims.escapeDelim = utils.escapeDelim; | ||
delims.buildRegexGroup = utils.buildRegexGroup; |
{ | ||
"name": "delims", | ||
"description": "Generate RegExp for delimiters, to be used with templates, files or data streams.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/jonschlinkert/delims", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -135,2 +135,4 @@ # delims [![NPM version](https://badge.fury.io/js/delims.png)](http://badge.fury.io/js/delims) | ||
*** | ||
### Lo-Dash Templates | ||
@@ -141,3 +143,5 @@ | ||
*** | ||
## Author | ||
@@ -144,0 +148,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13736
8
176
155