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
41 lines
1.3 KiB
Plaintext
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
|