Files
SnowLuma/.pnpm-store/v11/files/95/3932db1794365a3ae938c5ba167ffa231d98cfd9e76b33ecb1d3b4435e1339f92e3f5b0df8a459bcaf3ce662f8c6f2eb2ad639583b4d44fa83c6984f06b110
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

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