delimiter-regex
Advanced tools
Comparing version 1.3.1 to 2.0.0
47
index.js
'use strict'; | ||
var util = require('util'); | ||
var isObject = require('isobject'); | ||
var extend = require('extend-shallow'); | ||
module.exports = function delimiters(open, close, options) { | ||
if (open instanceof RegExp) { | ||
return open; | ||
module.exports = function delimiterRegex(open, close, options) { | ||
if (open instanceof RegExp) return open; | ||
if (typeof open === 'undefined') { | ||
return /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; | ||
} | ||
if (typeof close !== 'string') { | ||
options = close; | ||
close = null; | ||
if (typeof open === 'string' && typeof close === 'string') { | ||
return createRegex(open, close, options); | ||
} | ||
if (typeof open === 'object' && !Array.isArray(open)) { | ||
options = open; | ||
open = null; | ||
close = null; | ||
} | ||
if (Array.isArray(open)) { | ||
var syntax = open.slice(); | ||
open = syntax[0]; | ||
close = syntax[1]; | ||
return createRegex(open[0], open[1], close); | ||
} | ||
if (isObject(open)) { | ||
return createRegex(null, null, open); | ||
} | ||
var args = [].slice.call(arguments); | ||
throw new Error('cannot created delimiters from: ' + util.inspect(args)); | ||
}; | ||
function createRegex(open, close, options) { | ||
var opts = extend({flags: ''}, options); | ||
var body = '([\\s\\S]+?)'; | ||
var tagname = opts.tagname ? createTag(opts.tagname) : '([\\s\\S]+?)'; | ||
open = open || opts.open || '\\$\\{'; | ||
close = close || opts.close || '\\}'; | ||
return new RegExp(open + tagname + close, opts.flags); | ||
} | ||
open = open ? open : '\\${'; | ||
close = close ? close : '}'; | ||
return new RegExp(open + body + close, opts.flags); | ||
}; | ||
function createTag(str) { | ||
return ` (${str.trim()}) `; | ||
} |
{ | ||
"name": "delimiter-regex", | ||
"description": "Create regex for template delimiters.", | ||
"version": "1.3.1", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/jonschlinkert/delimiter-regex", | ||
"author": { | ||
"name": "Jon Schlinkert", | ||
"url": "https://github.com/jonschlinkert" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jonschlinkert/delimiter-regex.git" | ||
}, | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"repository": "jonschlinkert/delimiter-regex", | ||
"bugs": { | ||
"url": "https://github.com/jonschlinkert/delimiter-regex/issues" | ||
}, | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/delimiter-regex/blob/master/LICENSE" | ||
}, | ||
"license": "MIT", | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
@@ -31,3 +24,8 @@ "main": "index.js", | ||
}, | ||
"dependencies": { | ||
"extend-shallow": "^1.1.2", | ||
"isobject": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"gulp-format-md": "^0.1.9", | ||
"mocha": "*" | ||
@@ -48,5 +46,22 @@ }, | ||
], | ||
"dependencies": { | ||
"extend-shallow": "^1.1.2" | ||
"verb": { | ||
"toc": false, | ||
"layout": "default", | ||
"tasks": [ | ||
"readme" | ||
], | ||
"plugins": [ | ||
"gulp-format-md" | ||
], | ||
"lint": { | ||
"reflinks": true | ||
}, | ||
"related": { | ||
"list": [] | ||
}, | ||
"reflinks": [ | ||
"verb", | ||
"verb-generate-readme" | ||
] | ||
} | ||
} |
@@ -1,12 +0,13 @@ | ||
# delimiter-regex [![NPM version](https://badge.fury.io/js/delimiter-regex.svg)](http://badge.fury.io/js/delimiter-regex) [![Build Status](https://travis-ci.org/jonschlinkert/delimiter-regex.svg)](https://travis-ci.org/jonschlinkert/delimiter-regex) | ||
# delimiter-regex [![NPM version](https://img.shields.io/npm/v/delimiter-regex.svg?style=flat)](https://www.npmjs.com/package/delimiter-regex) [![NPM downloads](https://img.shields.io/npm/dm/delimiter-regex.svg?style=flat)](https://npmjs.org/package/delimiter-regex) [![Build Status](https://img.shields.io/travis/jonschlinkert/delimiter-regex.svg?style=flat)](https://travis-ci.org/jonschlinkert/delimiter-regex) | ||
> Create regex for template delimiters. | ||
Create regex for template delimiters. | ||
## Install with [npm](npmjs.org) | ||
## Install | ||
```bash | ||
npm i delimiter-regex --save | ||
Install with [npm](https://www.npmjs.com/): | ||
```sh | ||
$ npm install --save delimiter-regex | ||
``` | ||
## Usage | ||
@@ -36,4 +37,4 @@ | ||
- **delimiters** `{String|Array}`: supports array format (`delims(['{{', '}}'])`) or list (`delims('{{', '}}')`) | ||
- **options**: currently RegExp `flags` is the only option | ||
* **delimiters** `{String|Array}`: supports array format (`delims([''])`) or list (`delims('')`) | ||
* **options**: currently RegExp `flags` is the only option | ||
@@ -43,30 +44,53 @@ **Flags example** | ||
```js | ||
delims('{{', '}}', {flags: 'gm'}); | ||
delims('', {flags: 'gm'}); | ||
//=> /\{\{([^}}]*)\}\}/gm | ||
``` | ||
## Running tests | ||
Install dev dependencies. | ||
## About | ||
```bash | ||
npm i -d && npm test | ||
### Related projects | ||
Are you using Update in your project? Have you published an [updater](https://github.com/update/update/blob/master/docs/updaters.md) and want to share your Update project with the world? Here are some suggestions: | ||
* If you get like Update and want to tweet about it, please use the hashtag `#updatejs` (not `@`) | ||
* Get implementation help on [StackOverflow](http://stackoverflow.com/questions/tagged/update) (please use the `updatejs` tag in questions) | ||
* **Gitter** Discuss Update with us on [Gitter](https://gitter.im/update/update) | ||
* If you publish an updater, thank you! To make your project as discoverable as possible, please add the keyword `updateupdater` to package.json. | ||
### Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
### Building docs | ||
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_ | ||
To generate the readme and API documentation with [verb](https://github.com/verbose/verb): | ||
```sh | ||
$ npm install -g verb verb-generate-readme && verb | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/delimiter-regex/issues) | ||
### Running tests | ||
## Author | ||
Install dev dependencies: | ||
```sh | ||
$ npm install -d && npm test | ||
``` | ||
### Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright (c) 2014-2015 Jon Schlinkert | ||
Released under the MIT license | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
### License | ||
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT license](https://github.com/jonschlinkert/delimiter-regex/blob/master/LICENSE). | ||
*** | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 18, 2015._ | ||
<!-- deps:mocha --> | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on July 22, 2016._ |
Sorry, the diff of this file is not supported yet
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 repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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 bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
6273
31
94
2
2
1
+ Addedisobject@^2.1.0
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.0(transitive)