delimiter-regex
Advanced tools
Comparing version 0.1.0 to 1.0.0
27
.verb.md
@@ -5,11 +5,5 @@ # {%= name %} {%= badge("fury") %} | ||
## Install | ||
{%= include("install-npm", {save: true}) %} | ||
## Run tests | ||
```bash | ||
npm test | ||
``` | ||
## Usage | ||
@@ -21,7 +15,16 @@ | ||
**Example**: | ||
Get a regex for matching front-matter: | ||
```js | ||
delims('---', '---'); | ||
//=> /---\s*([\s\S]*?)\s*---/ | ||
``` | ||
If no args are passed, es6 delimiter regex is returned: | ||
```js | ||
console.log(delims()); | ||
//=> /\$\{([^}]*)\}/g | ||
delims(); | ||
//=> /\$\{\s*([\s\S]*?)\s*\}/ | ||
``` | ||
@@ -34,3 +37,3 @@ | ||
### Example | ||
**Flags example** | ||
@@ -42,2 +45,8 @@ ```js | ||
## Run tests | ||
```bash | ||
npm test | ||
``` | ||
## Contributing | ||
@@ -44,0 +53,0 @@ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue]({%= bugs.url %}) |
16
index.js
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = function(open, close, options) { | ||
module.exports = function delimiters(open, close, options) { | ||
if (typeof close !== 'string') { | ||
@@ -19,3 +19,3 @@ options = close; | ||
if (Array.isArray(open)) { | ||
var syntax = open; | ||
var syntax = open.slice(); | ||
open = syntax[0]; | ||
@@ -25,14 +25,14 @@ close = syntax[1]; | ||
var opts = options || {}; | ||
close = close || '}'; | ||
options = options || {}; | ||
var body = '\\s*([\\s\\S]*?)\\s*'; | ||
var body = '([^' + close + ']*)'; | ||
open = open ? esc(open) : '\\$\\{'; | ||
close = close ? esc(close) : '\\}'; | ||
open = esc(open ? open : '${'); | ||
close = esc(close ? close : '}'); | ||
return new RegExp(open + body + close, opts.flags || ''); | ||
return new RegExp(open + body + close, options.flags || ''); | ||
}; | ||
function esc(str) { | ||
return str.replace(chars, '\\$&'); | ||
} |
{ | ||
"name": "delimiter-regex", | ||
"description": "Create regex for template delimiters.", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/jonschlinkert/delimiter-regex", | ||
@@ -17,8 +17,6 @@ "author": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/delimiter-regex/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/delimiter-regex/blob/master/LICENSE" | ||
}, | ||
"main": "index.js", | ||
@@ -31,5 +29,7 @@ "engines": { | ||
}, | ||
"dependencies": { | ||
"regexp-special-chars": "^0.1.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*" | ||
"mocha": "*" | ||
}, | ||
@@ -48,6 +48,3 @@ "keywords": [ | ||
"template" | ||
], | ||
"dependencies": { | ||
"regexp-special-chars": "^0.1.0" | ||
} | ||
} | ||
] | ||
} |
@@ -5,4 +5,3 @@ # delimiter-regex [![NPM version](https://badge.fury.io/js/delimiter-regex.svg)](http://badge.fury.io/js/delimiter-regex) | ||
## Install | ||
### Install with [npm](npmjs.org) | ||
## Install with [npm](npmjs.org) | ||
@@ -13,8 +12,3 @@ ```bash | ||
## Run tests | ||
```bash | ||
npm test | ||
``` | ||
## Usage | ||
@@ -26,7 +20,16 @@ | ||
**Example**: | ||
Get a regex for matching front-matter: | ||
```js | ||
delims('---', '---'); | ||
//=> /---\s*([\s\S]*?)\s*---/ | ||
``` | ||
If no args are passed, es6 delimiter regex is returned: | ||
```js | ||
console.log(delims()); | ||
//=> /\$\{([^}]*)\}/g | ||
delims(); | ||
//=> /\$\{\s*([\s\S]*?)\s*\}/ | ||
``` | ||
@@ -39,3 +42,3 @@ | ||
### Example | ||
**Flags example** | ||
@@ -47,2 +50,8 @@ ```js | ||
## Run tests | ||
```bash | ||
npm test | ||
``` | ||
## Contributing | ||
@@ -59,3 +68,3 @@ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/delimiter-regex/issues) | ||
## License | ||
Copyright (c) 2014 Jon Schlinkert | ||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license | ||
@@ -65,2 +74,2 @@ | ||
_This file was generated by [verb](https://github.com/assemble/verb) on November 23, 2014._ | ||
_This file was generated by [verb](https://github.com/assemble/verb) on January 15, 2015._ |
28
test.js
/*! | ||
* delimiter-regex <https://github.com/jonschlinkert/delimiter-regex> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert, contributors. | ||
* Copyright (c) 2014-2015, Jon Schlinkert. | ||
* Licensed under the MIT License | ||
@@ -11,21 +11,37 @@ */ | ||
var assert = require('assert'); | ||
var should = require('should'); | ||
var delims = require('./'); | ||
function match(str, re) { | ||
return re.exec(str); | ||
} | ||
describe('delims', function () { | ||
it('should return default es6 regex:', function () { | ||
delims().should.eql(/\$\{([^}]*)\}/); | ||
assert.deepEqual(/\$\{\s*([\s\S]*?)\s*\}/, delims()); | ||
}); | ||
it('should match correctly:', function () { | ||
assert.equal(match('abc/${foo}/xyz', delims())[0], '${foo}'); | ||
assert.equal(match('abc/${foo}/xyz', delims())[1], 'foo'); | ||
assert.equal(match('abc/${foo}/${bar}/xyz', delims())[0], '${foo}'); | ||
assert.equal(match('abc/${foo}/${bar}/xyz', delims())[1], 'foo'); | ||
assert.equal(match('---\na: b\nc: d\n---\ncontent', delims('---', '---'))[0], '---\na: b\nc: d\n---'); | ||
assert.equal(match('---\na: b\nc: d\n---\ncontent', delims('---', '---'))[1], 'a: b\nc: d'); | ||
assert.equal(match('abc/${foo}/${bar}/xyz', delims())[1], 'foo'); | ||
}); | ||
it('should support regexp flags:', function () { | ||
delims({flags: 'gm'}).should.eql(/\$\{([^}]*)\}/gm); | ||
assert.deepEqual(/---\s*([\s\S]*?)\s*---/g, delims('---', '---', {flags: 'g'})); | ||
assert.deepEqual(/\$\{\s*([\s\S]*?)\s*\}/gm, delims({flags: 'gm'})); | ||
}); | ||
it('should support list format:', function () { | ||
delims('{{', '}}').should.eql(/\{\{([^}}]*)\}\}/); | ||
assert.deepEqual(/---\s*([\s\S]*?)\s*---/, delims('---', '---')); | ||
assert.deepEqual(/\{\{\s*([\s\S]*?)\s*\}\}/, delims('{{', '}}')); | ||
}); | ||
it('should support array format:', function () { | ||
delims(['{{', '}}']).should.eql(/\{\{([^}}]*)\}\}/); | ||
assert.deepEqual(/---\s*([\s\S]*?)\s*---/, delims(['---', '---'])); | ||
assert.deepEqual(/\{\{\s*([\s\S]*?)\s*\}\}/, delims(['{{', '}}'])); | ||
}); | ||
}); |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
7338
1
63
0
68