-
Notifications
You must be signed in to change notification settings - Fork 341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: masks #4332
feat: masks #4332
Conversation
@@ -0,0 +1,228 @@ | |||
interface TokenBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parser is actually good. The only problem here is in tree: Token[]
type. I should've been use TokenBase[] here, because Token
is declared after tree: Token[]
.
This also might be optimized if we parse normalized at the beginning. But it is too complex to understand.
|
||
type PossibleResult = RegexToken[] | ||
|
||
export const normalizeTokens = (tokens: Token[], dynamic = false) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalization is okay... Can be improved for better readability.
return true | ||
} | ||
|
||
const formatByRegexTokens = (possibleResults: PossibleResult[], value: string, reverse = false) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is a mess and most likely at unoptimized.
const suggestedChar = possibleSuggestions[0]?.expect ?? '' | ||
let canBeSuggested = possibleSuggestions.every((token) => token.expect === suggestedChar) && value[valueOffset]?.length > 0 | ||
|
||
const onlyStaticLeft = possibleResults.length === 1 && possibleResults[0].slice(tokensOffset).every((token) => token.static) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It must be refactored.
* raw * feat(masks): remove junk * feat(masks): add docs * feat(masks): improve suggestion when option group * feat(masks): add static tokens if only one possible solution is left * docs(masks): improve phone extended demo * feat(masks): correct suggestion when only one possible solution is left
* raw * feat(masks): remove junk * feat(masks): add docs * feat(masks): improve suggestion when option group * feat(masks): add static tokens if only one possible solution is left * docs(masks): improve phone extended demo * feat(masks): correct suggestion when only one possible solution is left
This PR originally created to replace cleavejs.
We can have it in beta state before 1.10.0