Files
SnowLuma/.pnpm-store/v11/files/56/b0a1fcd104da529dfa9b96bae5e33ad9ab9d348e54f1bd398710519aa14e1df431afc89b4fcc7817e364925f78228a252babf8911841e6b9f00d3bd0d5b0a7
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

41 lines
1.3 KiB
Plaintext

import { REGEXEN } from '../../data/const'
import { sorted } from '../../utils/helper'
import { MatcherBaseClass, MatchOptions, RegexMatch } from '../../types'
type RegexMatchOptions = Pick<MatchOptions, 'password'>
type RegexesKeys = keyof typeof REGEXEN
/*
* -------------------------------------------------------------------------------
* regex matching ---------------------------------------------------------------
* -------------------------------------------------------------------------------
*/
class MatchRegex extends MatcherBaseClass {
match({ password }: RegexMatchOptions) {
const matches: RegexMatch[] = []
Object.keys(REGEXEN).forEach((name) => {
const regex = REGEXEN[name as RegexesKeys]
regex.lastIndex = 0 // keeps regexMatch stateless
let regexMatch: RegExpExecArray | null
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 as RegexesKeys,
regexMatch,
})
}
}
})
return sorted(matches)
}
}
export default MatchRegex