Files
SnowLuma/.pnpm-store/v11/files/5a/c7016d0fe293f00b6c54296bdd4eff6c15001cafd67b5da1a11bcf350816e86c775c9fdcc28539a5dccabb9dbb15bb52fbe1e793c97de0c358b30f8c7340f0
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

35 lines
915 B
Plaintext

import { MIN_YEAR_SPACE, REFERENCE_YEAR } from '../../data/const'
import { MatchEstimated, MatchExtended } from '../../types'
export default ({
regexName,
regexMatch,
token,
}: MatchExtended | MatchEstimated) => {
const charClassBases = {
alphaLower: 26,
alphaUpper: 26,
alpha: 52,
alphanumeric: 62,
digits: 10,
symbols: 33,
}
if (regexName in charClassBases) {
return (
charClassBases[regexName as keyof typeof charClassBases] ** token.length
)
}
// TODO add more regex types for example special dates like 09.11
switch (regexName) {
case 'recentYear':
// conservative estimate of year space: num years from REFERENCE_YEAR.
// if year is close to REFERENCE_YEAR, estimate a year space of MIN_YEAR_SPACE.
return Math.max(
Math.abs(parseInt(regexMatch[0], 10) - REFERENCE_YEAR),
MIN_YEAR_SPACE,
)
}
return 0
}