blob: 599ff5126b0af335664318ec17972a8c189637b5 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var toRegex = require('to-regex');
4var regexNot = require('regex-not');
5var cached;
6
7/**
8 * Get the last element from `array`
9 * @param {Array} `array`
10 * @return {*}
11 */
12
13exports.last = function(arr) {
14 return arr[arr.length - 1];
15};
16
17/**
18 * Create and cache regex to use for text nodes
19 */
20
21exports.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};