You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
757 B
33 lines
757 B
5 years ago
|
'use strict';
|
||
|
|
||
|
// MODULES //
|
||
|
|
||
|
var isString = require( 'validate.io-string-primitive' ),
|
||
|
RE = require( 'regex-regex' );
|
||
|
|
||
|
|
||
|
// REGEX //
|
||
|
|
||
|
/**
|
||
|
* FUNCTION: regex( str )
|
||
|
* Parses a regular expression string and returns a new regular expression.
|
||
|
*
|
||
|
* @param {String} str - regular expression string
|
||
|
* @returns {RegExp|Null} regular expression or null
|
||
|
*/
|
||
|
function regex( str ) {
|
||
|
if ( !isString( str ) ) {
|
||
|
throw new TypeError( 'invalid input argument. Must provide a regular expression string. Value: `' + str + '`.' );
|
||
|
}
|
||
|
// Capture the regular expression pattern and any flags:
|
||
|
str = RE.exec( str );
|
||
|
|
||
|
// Create a new regular expression:
|
||
|
return ( str ) ? new RegExp( str[1], str[2] ) : null;
|
||
|
} // end FUNCTION regex()
|
||
|
|
||
|
|
||
|
// EXPORTS //
|
||
|
|
||
|
module.exports = regex;
|