39 lines
1.1 KiB
Plaintext
39 lines
1.1 KiB
Plaintext
import { REGEXEN } from '../../data/const.mjs';
|
|
import { sorted } from '../../utils/helper.mjs';
|
|
import { MatcherBaseClass } from '../../types.mjs';
|
|
|
|
/*
|
|
* -------------------------------------------------------------------------------
|
|
* regex matching ---------------------------------------------------------------
|
|
* -------------------------------------------------------------------------------
|
|
*/
|
|
class MatchRegex extends MatcherBaseClass {
|
|
match({
|
|
password
|
|
}) {
|
|
const matches = [];
|
|
Object.keys(REGEXEN).forEach(name => {
|
|
const regex = REGEXEN[name];
|
|
regex.lastIndex = 0; // keeps regexMatch stateless
|
|
let regexMatch;
|
|
while (regexMatch = regex.exec(password)) {
|
|
if (regexMatch) {
|
|
const token = regexMatch[0];
|
|
matches.push({
|
|
pattern: 'regex',
|
|
token,
|
|
i: regexMatch.index,
|
|
j: regexMatch.index + regexMatch[0].length - 1,
|
|
regexName: name,
|
|
regexMatch
|
|
});
|
|
}
|
|
}
|
|
});
|
|
return sorted(matches);
|
|
}
|
|
}
|
|
|
|
export { MatchRegex as default };
|
|
//# sourceMappingURL=matching.mjs.map
|