Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index-generators.js « src « regextras « node_modules « eslint « node_modules « tools - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3dbf16414dacac6766c81fc8f5270ce909ef6193 (plain)
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
/* eslint-disable node/no-unsupported-features/es-syntax */
// We copy the regular expression so as to be able to always
// ensure the exec expression is a global one (and thereby prevent recursion)

/**
 *
 * @param {RegExtras} RegExtras
 * @returns {void}
 */
function addPrototypeMethods (RegExtras) {
  RegExtras.prototype.entries = function * (str) {
    let matches, i = 0;
    const regex = RegExtras.mixinRegex(this.regex, 'g');
    while ((matches = regex.exec(str)) !== null) {
      yield [i++, matches];
    }
  };

  RegExtras.prototype.values = function * (str) {
    let matches;
    const regex = RegExtras.mixinRegex(this.regex, 'g');
    while ((matches = regex.exec(str)) !== null) {
      yield matches;
    }
  };

  RegExtras.prototype.keys = function * (str) {
    let i = 0;
    const regex = RegExtras.mixinRegex(this.regex, 'g');
    while (regex.exec(str) !== null) {
      yield i++;
    }
  };
}

export default addPrototypeMethods;