source: trip-planner-front/node_modules/expand-brackets/lib/utils.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 664 bytes
RevLine 
[6a3a178]1'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};
Note: See TracBrowser for help on using the repository browser.