File: support.js

package info (click to toggle)
node-regex-cache 0.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 180 kB
  • ctags: 25
  • sloc: makefile: 4; sh: 2
file content (54 lines) | stat: -rw-r--r-- 1,113 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';

exports.toRegex = function toRegex(str, opts) {
  if (typeof str !== 'string') {
    opts = str;
    str = '';
  }
  opts = opts || {};
  var re = str || '';

  if (opts.a) re += 'a';
  if (opts.b) re += 'b';
  if (opts.c) re += 'c';
  if (opts.d && opts.d.e) re += opts.d.e;

  if (opts.e) re += 'e';
  if (opts.f) re += 'f';
  if (opts.g) re += 'g';
  if (opts.h) re += 'h';
  if (opts.i) re += 'i';
  if (opts.j) re += 'j';
  if (opts.k) re += 'k';
  if (opts.l) re += 'l';
  if (opts.m) re += 'm';
  if (opts.n) re += 'n';
  if (opts.o) re += 'o';
  if (opts.p) re += 'p';
  if (opts.q) re += 'q';
  if (opts.r) re += 'r';
  if (opts.s) re += 's';
  if (opts.t) re += 't';

  if (opts.x) re += 'x';
  if (opts.y) re += 'y';
  if (opts.z) re += 'z';

  var f = opts.flags || '';
  re = re
    ? '(' + re + ')'
    : '([^\W]?)';

  // filler for some other logic
  if (re.indexOf('x') !== -1) {
    re = re.replace(/x/g, '');
  }
  if (re.indexOf('y') !== -1) {
    re = re.replace(/y/g, '');
  }
  if (re.indexOf('z') !== -1) {
    re = re.replace(/z/g, '');
  }

  return new RegExp(re, f);
};