.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / clone-regexp / index.js
1 'use strict';
2 var isRegexp = require('is-regexp');
3 var isSupportedRegexpFlag = require('is-supported-regexp-flag');
4
5 var flagMap = {
6         global: 'g',
7         ignoreCase: 'i',
8         multiline: 'm'
9 };
10
11 if (isSupportedRegexpFlag('y')) {
12         flagMap.sticky = 'y';
13 }
14
15 if (isSupportedRegexpFlag('u')) {
16         flagMap.unicode = 'u';
17 }
18
19 module.exports = function (re, opts) {
20         if (!isRegexp(re)) {
21                 throw new TypeError('Expected a RegExp instance');
22         }
23
24         opts = opts || {};
25
26         var flags = Object.keys(flagMap).map(function (el) {
27                 return (typeof opts[el] === 'boolean' ? opts[el] : re[el]) ? flagMap[el] : '';
28         }).join('');
29
30         return new RegExp(opts.source || re.source, flags);
31 };