source: trip-planner-front/node_modules/regex-parser/lib/index.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 694 bytes
Line 
1"use strict";
2
3/**
4 * RegexParser
5 * Parses a string input.
6 *
7 * @name RegexParser
8 * @function
9 * @param {String} input The string input that should be parsed as regular
10 * expression.
11 * @return {RegExp} The parsed regular expression.
12 */
13var RegexParser = module.exports = function (input) {
14
15 // Validate input
16 if (typeof input !== "string") {
17 throw new Error("Invalid input. Input must be a string");
18 }
19
20 // Parse input
21 var m = input.match(/(\/?)(.+)\1([a-z]*)/i);
22
23 // Invalid flags
24 if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) {
25 return RegExp(input);
26 }
27
28 // Create the regular expression
29 return new RegExp(m[2], m[3]);
30};
Note: See TracBrowser for help on using the repository browser.