index.js 463 B

123456789101112131415161718192021
  1. var toString = Object.prototype.toString;
  2. function isRegExp (o) {
  3. return 'object' == typeof o
  4. && '[object RegExp]' == toString.call(o);
  5. }
  6. module.exports = exports = function (regexp) {
  7. if (!isRegExp(regexp)) {
  8. throw new TypeError('Not a RegExp');
  9. }
  10. var flags = [];
  11. if (regexp.global) flags.push('g');
  12. if (regexp.multiline) flags.push('m');
  13. if (regexp.ignoreCase) flags.push('i');
  14. return new RegExp(regexp.source, flags.join(''));
  15. }