1
0
mirror of https://github.com/thangisme/notes.git synced 2024-06-09 12:10:42 +00:00
notes/node_modules/clone-regexp/index.js
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00

32 lines
651 B
JavaScript

'use strict';
var isRegexp = require('is-regexp');
var isSupportedRegexpFlag = require('is-supported-regexp-flag');
var flagMap = {
global: 'g',
ignoreCase: 'i',
multiline: 'm'
};
if (isSupportedRegexpFlag('y')) {
flagMap.sticky = 'y';
}
if (isSupportedRegexpFlag('u')) {
flagMap.unicode = 'u';
}
module.exports = function (re, opts) {
if (!isRegexp(re)) {
throw new TypeError('Expected a RegExp instance');
}
opts = opts || {};
var flags = Object.keys(flagMap).map(function (el) {
return (typeof opts[el] === 'boolean' ? opts[el] : re[el]) ? flagMap[el] : '';
}).join('');
return new RegExp(opts.source || re.source, flags);
};