.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / fast-glob / node_modules / expand-brackets / lib / utils.js
1 'use strict';
2
3 var toRegex = require('to-regex');
4 var regexNot = require('regex-not');
5 var cached;
6
7 /**
8  * Get the last element from `array`
9  * @param {Array} `array`
10  * @return {*}
11  */
12
13 exports.last = function(arr) {
14   return arr[arr.length - 1];
15 };
16
17 /**
18  * Create and cache regex to use for text nodes
19  */
20
21 exports.createRegex = function(pattern, include) {
22   if (cached) return cached;
23   var opts = {contains: true, strictClose: false};
24   var not = regexNot.create(pattern, opts);
25   var re;
26
27   if (typeof include === 'string') {
28     re = toRegex('^(?:' + include + '|' + not + ')', opts);
29   } else {
30     re = toRegex(not, opts);
31   }
32
33   return (cached = re);
34 };