41 lines
1.1 KiB
Plaintext
41 lines
1.1 KiB
Plaintext
'use strict';
|
|
|
|
var _const = require('../../data/const.cjs');
|
|
var helper = require('../../utils/helper.cjs');
|
|
var types = require('../../types.cjs');
|
|
|
|
/*
|
|
* -------------------------------------------------------------------------------
|
|
* regex matching ---------------------------------------------------------------
|
|
* -------------------------------------------------------------------------------
|
|
*/
|
|
class MatchRegex extends types.MatcherBaseClass {
|
|
match({
|
|
password
|
|
}) {
|
|
const matches = [];
|
|
Object.keys(_const.REGEXEN).forEach(name => {
|
|
const regex = _const.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 helper.sorted(matches);
|
|
}
|
|
}
|
|
|
|
module.exports = MatchRegex;
|
|
//# sourceMappingURL=matching.cjs.map
|