80 lines
2.8 KiB
Plaintext
80 lines
2.8 KiB
Plaintext
import { extend, sorted } from './utils/helper.mjs';
|
|
import MatchDate from './matcher/date/matching.mjs';
|
|
import MatchDictionary from './matcher/dictionary/matching.mjs';
|
|
import MatchL33t from './matcher/dictionary/variants/matching/l33t.mjs';
|
|
import MatchReverse from './matcher/dictionary/variants/matching/reverse.mjs';
|
|
import MatchRegex from './matcher/regex/matching.mjs';
|
|
import MatchRepeat from './matcher/repeat/matching.mjs';
|
|
import MatchSequence from './matcher/sequence/matching.mjs';
|
|
import MatchSpatial from './matcher/spatial/matching.mjs';
|
|
import MatchSeparator from './matcher/separator/matching.mjs';
|
|
import MatchWordSequence from './matcher/wordSequence/matching.mjs';
|
|
|
|
/*
|
|
* -------------------------------------------------------------------------------
|
|
* Omnimatch combine matchers ---------------------------------------------------------------
|
|
* -------------------------------------------------------------------------------
|
|
*/
|
|
class Matching {
|
|
constructor(options) {
|
|
this.options = options;
|
|
this.matchers = {};
|
|
this.matchers = {
|
|
date: new MatchDate(this.options),
|
|
dictionary: new MatchDictionary(this.options),
|
|
dictionaryL33t: new MatchL33t(this.options),
|
|
dictionaryReverse: new MatchReverse(this.options),
|
|
regex: new MatchRegex(this.options),
|
|
repeat: new MatchRepeat(this.options),
|
|
sequence: new MatchSequence(this.options),
|
|
spatial: new MatchSpatial(this.options),
|
|
separator: new MatchSeparator(this.options),
|
|
wordSequence: new MatchWordSequence(this.options)
|
|
};
|
|
Object.entries(this.options.matchers).forEach(([key, Matcher]) => {
|
|
this.matchers[key] = new Matcher.Matching(this.options);
|
|
});
|
|
}
|
|
processResult(matches, promises, result) {
|
|
if (result instanceof Promise) {
|
|
const wrappedPromise = result.then(response => {
|
|
extend(matches, response);
|
|
return response;
|
|
});
|
|
promises.push(wrappedPromise);
|
|
} else {
|
|
extend(matches, result);
|
|
}
|
|
}
|
|
handlePromises(matches, promises) {
|
|
if (promises.length > 0) {
|
|
return new Promise((resolve, reject) => {
|
|
Promise.all(promises).then(() => {
|
|
resolve(sorted(matches));
|
|
}).catch(error => {
|
|
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
return sorted(matches);
|
|
}
|
|
match(password, userInputsOptions) {
|
|
const matches = [];
|
|
const promises = [];
|
|
Object.values(this.matchers).forEach(matcher => {
|
|
const result = matcher.match({
|
|
password,
|
|
omniMatch: this,
|
|
userInputsOptions
|
|
});
|
|
// extends matches and promises by references
|
|
this.processResult(matches, promises, result);
|
|
});
|
|
return this.handlePromises(matches, promises);
|
|
}
|
|
}
|
|
|
|
export { Matching as default };
|
|
//# sourceMappingURL=Matching.mjs.map
|