Comparing version 2.0.0 to 2.0.1
{ | ||
"name": "regexp-tpl", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Templated regular expressions.", | ||
"main": "src/index.js", | ||
"files": [ | ||
"src/index.js", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"scripts": { | ||
@@ -34,13 +39,13 @@ "test": "mocha src/*.mocha.js", | ||
"devDependencies": { | ||
"coveralls": "^2.11.2", | ||
"eslint": "^3.2.2", | ||
"eslint-config-simplifield": "^3.0.0", | ||
"istanbul": "^0.4.4", | ||
"mocha": "^3.0.1" | ||
"coveralls": "^3.0.2", | ||
"eslint": "^5.8.0", | ||
"eslint-config-simplifield": "^8.1.0", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^5.2.0" | ||
}, | ||
"dependencies": { | ||
"debug": "^2.2.0", | ||
"escape-regexp-component": "^1.0.2", | ||
"miniquery": "^1.0.0" | ||
"debug": "^4.1.0", | ||
"escape-string-regexp": "^1.0.5", | ||
"miniquery": "^1.1.2" | ||
} | ||
} |
@@ -11,3 +11,4 @@ # regexp-tpl | ||
[![Code Climate](https://codeclimate.com/github/SimpliField/regexp-tpl.svg)](https://codeclimate.com/github/SimpliField/regexp-tpl) | ||
[![Package Quality](http://npm.packagequality.com/badge/regexp-tpl.png)](http://packagequality.com/#?package=regexp-tpl) | ||
[![Package Quality](http://npm.packagequality.com/shield/regexp-tpl.png)](http://packagequality.com/#?package=regexp-tpl) | ||
[![Dependency Status](https://dependencyci.com/github/SimpliField/regexp-tpl/badge)](https://dependencyci.com/github/SimpliField/regexp-tpl) | ||
@@ -14,0 +15,0 @@ ## Installation |
'use strict'; | ||
const escRegExp = require('escape-regexp-component'); | ||
const escRegExp = require('escape-string-regexp'); | ||
const miniquery = require('miniquery'); | ||
const debug = require('debug')('regexp-tpl'); | ||
const DEFAULT_TEMPLATE = /(.*|^)\{([a-z0-9_\-\.\*\@\#]+)\}(.*|$)/i; | ||
const DEFAULT_TEMPLATE = /(.*|^)\{([a-z0-9_\-.*@#]+)\}(.*|$)/i; | ||
function regexpTpl(objs, regExpTemplate, regExpFlags, templateRegExp) { | ||
let hasUnmatchedTemplateValues = false; | ||
let regExp; | ||
if(!(objs instanceof Array)) { | ||
if (!(objs instanceof Array)) { | ||
throw Error('`objs` must be an instanceof `Array`'); | ||
} | ||
if('string' !== typeof regExpTemplate) { | ||
if ('string' !== typeof regExpTemplate) { | ||
throw Error('`regExpTemplate` must be a string'); | ||
@@ -27,6 +26,6 @@ } | ||
if(values.length) { | ||
if (values.length) { | ||
return $1 + (1 === values.length ? | ||
escRegExp(values[0]) : | ||
'(' + values.map(escRegExp).join('|') + ')') + $3; | ||
`(${values.map(escRegExp).join('|')})`) + $3; | ||
} | ||
@@ -38,3 +37,3 @@ | ||
while((templateRegExp || DEFAULT_TEMPLATE).test(regExpTemplate)) { | ||
while ((templateRegExp || DEFAULT_TEMPLATE).test(regExpTemplate)) { | ||
regExpTemplate = regExpTemplate.replace( | ||
@@ -46,3 +45,3 @@ (templateRegExp || DEFAULT_TEMPLATE), | ||
if(hasUnmatchedTemplateValues) { | ||
if (hasUnmatchedTemplateValues) { | ||
debug('Could not build (unmatched template value):', regExpTemplate); | ||
@@ -52,3 +51,4 @@ return {}.undef; | ||
regExp = new RegExp(regExpTemplate, regExpFlags); | ||
// eslint-disable-next-line | ||
const regExp = new RegExp(regExpTemplate, regExpFlags); | ||
@@ -55,0 +55,0 @@ debug('Built:', regExp); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
79
0
6636
4
41
+ Addedescape-string-regexp@^1.0.5
+ Addeddebug@4.3.7(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedms@2.1.3(transitive)
- Removedescape-regexp-component@^1.0.2
- Removeddebug@2.6.9(transitive)
- Removedescape-regexp-component@1.0.2(transitive)
- Removedms@2.0.0(transitive)
Updateddebug@^4.1.0
Updatedminiquery@^1.1.2