-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
26 lines (26 loc) · 977 Bytes
/
index.js
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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function regexifyString(props) {
var pattern = props.pattern, decorator = props.decorator, input = props.input;
var output = [];
var matchIndex = 0;
var processedInput = input;
var result = pattern.exec(processedInput);
while (result !== null) {
var matchStartAt = result.index;
var match = result[0];
var contentBeforeMatch = processedInput.substring(0, matchStartAt);
var decoratedMatch = decorator(match, matchIndex, result);
output.push(contentBeforeMatch);
output.push(decoratedMatch);
processedInput = processedInput.substring(matchStartAt + match.length, processedInput.length + 1);
pattern.lastIndex = 0;
result = pattern.exec(processedInput);
++matchIndex;
}
if (processedInput) {
output.push(processedInput);
}
return output;
}
exports.default = regexifyString;