json-to-regex

0.0.2 • Public • Published

This library is a simple wrapper around new RegExp(pattern, options) primarily intended for use with regexes from JSON config files.

Installation

npm install json-to-regex

Quick Start

const jsonToRegex = require('json-to-regex');
 
const regex = jsonToRegex('foo.*bar$');
const moreRegexes = [ 'ab?c', 'de+\\D' ].map(jsonToRegex);
const caseInsensitiveRegex = jsonToRegex([ '^hello', 'i' ]);

Usage

jsonToRegex(value)

Passing in a string value will result in the string being converted to a regex, e.g. '^hello.*!$' => /^hello.*!$/. To set regex options such as case insensitivity, pass in an array where the first element is the regex string and the second element is the options, e.g. ['^hello.*!$', 'i'] => /^hello.*!$/i

Readme

Keywords

none

Package Sidebar

Install

npm i json-to-regex

Weekly Downloads

1

Version

0.0.2

License

ISC

Last publish

Collaborators

  • nathantreid