Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
701 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var regexParser = require('regex-parser');
|
---|
4 |
|
---|
5 | var REGEXP = /(\/?)(.+)\1([a-z]*)/i;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Parse the give value as a regular expression or give a pass-none expression where it is invalid
|
---|
9 | * @param {RegExp|string|*} value An existing expression, or its string representation, or degenerate value
|
---|
10 | * @returns {RegExp} The given expression or one matching the RegExp string else a pass-none expression
|
---|
11 | */
|
---|
12 | function toRegExp(value) {
|
---|
13 | return ((typeof value === 'object') && (typeof value.test === 'function') && value) ||
|
---|
14 | ((typeof value === 'string') && REGEXP.test(value) && regexParser(value)) ||
|
---|
15 | (/^true$|^$/.test(value) && /.*/) ||
|
---|
16 | /matchnone^/;
|
---|
17 | }
|
---|
18 |
|
---|
19 | module.exports = toRegExp; |
---|
Note:
See
TracBrowser
for help on using the repository browser.