Skip to content
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

Match alphanumeric params only #14

Merged
merged 1 commit into from
Dec 15, 2023
Merged

Match alphanumeric params only #14

merged 1 commit into from
Dec 15, 2023

Conversation

pleek91
Copy link
Contributor

@pleek91 pleek91 commented Dec 13, 2023

Description

Loosely conforms the types for route params to match params that end with a / , -, or _.

This is accomplished by replacing - and _ with / on each path prior to parsing out the params. Then / is used same as before. Each character we want to support requires a ReplaceAll<path, '-', '/'> type to wrap the path. This is recursive template literal type. So I think there probably is some cost to doing this.

For that reason there are some other special characters that I'm not accounting for here that are valid url characters are ., !, ~, *, ', (, and ). Which are not commonly used. I vote we only add this if necessary but I don't feel strongly.

Comment on lines +68 to +70
type UnifyParamEnds<
TPath extends string
> = ReplaceAll<ReplaceAll<TPath, '-', ParamEnd>, '_', ParamEnd>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than nesting ReplaceAll, could we use a union?

ReplaceAll<TPath, '-' | '_', ParamEnd>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time you have a union the type will produce a union. And we want to replace each character individually so the output type is a single template literal.

@pleek91 pleek91 merged commit 66ad903 into main Dec 15, 2023
3 checks passed
@pleek91 pleek91 deleted the alpha-numeric-params branch December 15, 2023 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants