UNPKG

is-equal-regex

Version:

Returns true if regular expression A is equal to regex B. Compares the expression and flags.

106 lines (77 loc) 2.58 kB
# is-equal-regex [![NPM version](https://badge.fury.io/js/is-equal-regex.svg)](http://badge.fury.io/js/is-equal-regex) > Returns true if regular expression A is equal to regex B. Compares the expression and flags. ## Install Install with [npm](https://www.npmjs.com/) ```sh $ npm i is-equal-regex --save ``` ## Usage ```js var isEqualRegex = require('is-equal-regex'); isEqualRegex(/foo/, /foo/); //=> true isEqualRegex(/foo/g, /foo/g); //=> true isEqualRegex(/foo/, /bar/); //=> false isEqualRegex(/foo/g, /foo/); //=> false ``` ## Related projects * [isobject](https://github.com/jonschlinkert/isobject): Returns true if the value is an object and not an array or null. * [is-plain-object](https://github.com/jonschlinkert/is-plain-object): Returns true if an object was created by the `Object` constructor. * [is-equal-shallow](https://github.com/jonschlinkert/is-equal-shallow): Does a shallow comparison of two objects, returning false if the keys or values differ. ## Examples **True** All of the following return `true`: ```js isEqualRegex(/foo/, /foo/); isEqualRegex(/^bar/, /^bar/); isEqualRegex(/foo/g, /foo/g); isEqualRegex(/^bar$/, new RegExp('^bar$')); isEqualRegex(/^bar$/gmi, new RegExp('^bar$', 'gmi')); isEqualRegex(new RegExp('^bar$'), /^bar$/); isEqualRegex(new RegExp('^bar$', 'gmi'), /^bar$/gmi); ``` **False** All of the following return `false`: ```js isEqualRegex(/^bar$/gmi, new RegExp('^bar$')); isEqualRegex(new RegExp('^bar$'), /^bar$/gmi); isEqualRegex('a'); isEqualRegex('a', /foo/); isEqualRegex(); isEqualRegex(/foo/); isEqualRegex(/foo/, /bar/); isEqualRegex(/foo/, /foo/gm); isEqualRegex(/foo/, 'a'); isEqualRegex(/foo/, /^foo/); isEqualRegex(/foo/, /bar/); isEqualRegex(/foo/, []); isEqualRegex(/foo/, new Date()); isEqualRegex(/foo/, null); isEqualRegex(/foo/, undefined); isEqualRegex(/foo/, {}); isEqualRegex(/foo/g, /foo/); isEqualRegex([]); isEqualRegex(new Date(), /foo/); isEqualRegex(null); isEqualRegex(undefined); isEqualRegex({}); ``` ## Running tests Install dev dependencies: ```sh $ npm i -d && npm test ``` ## Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-equal-regex/issues/new) ## Author **Jon Schlinkert** + [github/jonschlinkert](https://github.com/jonschlinkert) + [twitter/jonschlinkert](http://twitter.com/jonschlinkert) ## License Copyright © 2015 Jon Schlinkert Released under the MIT license. *** _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on July 27, 2015._