Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
664 bytes
|
Rev | Line | |
---|
[6a3a178] | 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 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.