Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

to-regex

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

to-regex - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2

15

index.js
'use strict';
var safe = require('safe-regex');
var define = require('define-property');

@@ -89,6 +90,12 @@ var extend = require('extend-shallow');

}
var str = open + '(?:' + pattern + ')' + close;
regex = new RegExp(str, flags);
if (opts.safe === true && safe(regex) === false) {
throw new Error('potentially unsafe regular expression: ' + regex.source);
}
} catch (err) {
if (opts.strictErrors === true) {
if (opts.strictErrors === true || opts.safe === true) {
err.key = key;

@@ -109,3 +116,3 @@ err.pattern = pattern;

if (opts.cache !== false) {
cacheRegex(regex, key, pattern, opts);
memoize(regex, key, pattern, opts);
}

@@ -116,3 +123,3 @@ return regex;

/**
* Cache generated regex. This can result in dramatic speed improvements
* Memoize generated regex. This can result in dramatic speed improvements
* and simplify debugging by adding options and pattern to the regex. It can be

@@ -122,3 +129,3 @@ * disabled by passing setting `options.cache` to false.

function cacheRegex(regex, key, pattern, options) {
function memoize(regex, key, pattern, options) {
define(regex, 'cached', true);

@@ -125,0 +132,0 @@ define(regex, 'pattern', pattern);

{
"name": "to-regex",
"description": "Generate a regex from a string or array of strings.",
"version": "3.0.1",
"version": "3.0.2",
"homepage": "https://github.com/jonschlinkert/to-regex",

@@ -23,13 +23,10 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"dependencies": {
"define-property": "^0.2.5",
"extend-shallow": "^2.0.1",
"regex-not": "^1.0.0"
"define-property": "^2.0.2",
"extend-shallow": "^3.0.2",
"regex-not": "^1.0.2",
"safe-regex": "^1.1.0"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-format-md": "^0.1.10",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^3.0.1",
"mocha": "^3.0.2"
"gulp-format-md": "^1.0.0",
"mocha": "^3.5.3"
},

@@ -62,6 +59,2 @@ "keywords": [

},
"reflinks": [
"verb",
"verb-generate-readme"
],
"lint": {

@@ -68,0 +61,0 @@ "reflinks": true

@@ -1,6 +0,6 @@

# to-regex [![NPM version](https://img.shields.io/npm/v/to-regex.svg?style=flat)](https://www.npmjs.com/package/to-regex) [![NPM downloads](https://img.shields.io/npm/dm/to-regex.svg?style=flat)](https://npmjs.org/package/to-regex) [![Build Status](https://img.shields.io/travis/jonschlinkert/to-regex.svg?style=flat)](https://travis-ci.org/jonschlinkert/to-regex)
# to-regex [![NPM version](https://img.shields.io/npm/v/to-regex.svg?style=flat)](https://www.npmjs.com/package/to-regex) [![NPM monthly downloads](https://img.shields.io/npm/dm/to-regex.svg?style=flat)](https://npmjs.org/package/to-regex) [![NPM total downloads](https://img.shields.io/npm/dt/to-regex.svg?style=flat)](https://npmjs.org/package/to-regex) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/to-regex.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/to-regex)
> Generate a regex from a string or array of strings.
## Table of Contents
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.

@@ -15,7 +15,5 @@ - [Install](#install)

* [options.cache](#optionscache)
* [options.safe](#optionssafe)
- [About](#about)
* [Related projects](#related-projects)
* [Contributing](#contributing)
* [Building docs](#building-docs)
* [Running tests](#running-tests)
* [Author](#author)

@@ -133,33 +131,62 @@ * [License](#license)

## About
### options.safe
### Related projects
**Type**: `Boolean`
* [has-glob](https://www.npmjs.com/package/has-glob): Returns `true` if an array has a glob pattern. | [homepage](https://github.com/jonschlinkert/has-glob "Returns `true` if an array has a glob pattern.")
* [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern or an extglob pattern… [more](https://github.com/jonschlinkert/is-glob) | [homepage](https://github.com/jonschlinkert/is-glob "Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a bet")
* [path-regex](https://www.npmjs.com/package/path-regex): Regular expression for matching the parts of a file path. | [homepage](https://github.com/regexps/path-regex "Regular expression for matching the parts of a file path.")
* [to-regex-range](https://www.npmjs.com/package/to-regex-range): Returns a regex-compatible range from two numbers, min and max, with 855,412 generated unit tests… [more](https://github.com/jonschlinkert/to-regex-range) | [homepage](https://github.com/jonschlinkert/to-regex-range "Returns a regex-compatible range from two numbers, min and max, with 855,412 generated unit tests to validate it's accuracy! Useful for creating regular expressions to validate numbers, ranges, years, etc. Returns a string, allowing the returned value to ")
**Default**: `undefined`
### Contributing
Check the generated regular expression with [safe-regex](https://github.com/substack/safe-regex) and throw an error if the regex is potentially unsafe.
**Examples**
```js
console.log(toRegex('(x+x+)+y'));
//=> /^(?:(x+x+)+y)$/
// The following would throw an error
toRegex('(x+x+)+y', {safe: true});
```
## About
<details>
<summary><strong>Contributing</strong></summary>
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
### Building docs
</details>
_(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).)_
<details>
<summary><strong>Running Tests</strong></summary>
To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install -g verb verb-generate-readme && verb
$ npm install && npm test
```
### Running tests
</details>
Install dev dependencies:
<details>
<summary><strong>Building docs</strong></summary>
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -d && npm test
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
</details>
### Related projects
You might also be interested in these projects:
* [has-glob](https://www.npmjs.com/package/has-glob): Returns `true` if an array has a glob pattern. | [homepage](https://github.com/jonschlinkert/has-glob "Returns `true` if an array has a glob pattern.")
* [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern or an extglob pattern… [more](https://github.com/jonschlinkert/is-glob) | [homepage](https://github.com/jonschlinkert/is-glob "Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a bet")
* [path-regex](https://www.npmjs.com/package/path-regex): Regular expression for matching the parts of a file path. | [homepage](https://github.com/regexps/path-regex "Regular expression for matching the parts of a file path.")
* [to-regex-range](https://www.npmjs.com/package/to-regex-range): Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than… [more](https://github.com/micromatch/to-regex-range) | [homepage](https://github.com/micromatch/to-regex-range "Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than 2.78 million test assertions.")
### Author

@@ -169,12 +196,13 @@

* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert)
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
### License
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/to-regex/blob/master/LICENSE).
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.31, on October 16, 2016._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on February 24, 2018._

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc