-
-
Notifications
You must be signed in to change notification settings - Fork 216
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
Added nanoid() validation action #789
Added nanoid() validation action #789
Conversation
Thank you for this PR! I will try to review and merge it next week. |
I would recommend removing the 2 to 36 character limit from the regex and instead we could add the option to pass the length via the first argument of the function. If no argument is passed, it defaults to 21. What do you think? |
I did take precedence from the existing I do agree with you though, I like const NanoIDSchema = v.pipe(
v.string(),
v.nanoid(21, 'The Nano ID is badly formatted.')
); over const NanoIDSchema = v.pipe(
v.string(),
v.nanoid('The Nano ID is badly formatted.'),
v.length(21)
); I will make changes with your suggestions |
I think I would try to create the regex dynamically using the passed length. |
I made some changes so that it will accept length as the first argument of the function. ESLint was complaining about the dynamic regex https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/rules/detect-non-literal-regexp.md so I opted to do it another way. I am a little unsure how the generics should be set up now that |
I thought about what I wrote and I am no longer sure if we should bake the length into the action. Since the length is variable, it might be better to recommend using our length actions for more flexibility. This would also allow you to specify a length range. What do you think? |
This would make it more in line with the rest of the other existing validation actions. I think using I will probably reverse some changes of my previous commit, but I think I will still remove the 2 to 36 character limit, so it just checks for valid characters in the regex, leaving the option to check length entirely to the No length check const NanoIDSchema = v.pipe(
v.string(),
v.nanoid('The Nano ID is badly formatted.')
); With length check const NanoIDSchema = v.pipe(
v.string(),
v.nanoid('The Nano ID is badly formatted.'),
v.length(21)
); Does it sound good to you? |
Thank you for your changes. I will review everything soon and probably release it with our next minor release. |
Thank you so much! You did a great job with this PR! Are you interested in helping me add more common string validators for JWT (#692) as well as Bitcoin and Ethereum addresses? |
90d4c20
to
9f25d78
Compare
Thanks! Unable to help for now but I will look into it when I have more time. |
v0.40.0 is available 🚀 |
Added pipeline validation action for Nano ID.
v.nanoid()
should work similarly to the other validation actions for ID generators likev.cuid2()
,v.ulid()
andv.uuid()
.By default, Nano ID uses URL-friendly symbols (A-Za-z0-9_-) and returns an ID with 21 characters, but I modified it to a variable length of 2 to 36 characters instead (https://zelark.github.io/nano-id-cc/) while keeping the default alphabet/symbol set. This flexibility allows for people who want to use Nano ID with a reduced ID length and use
v.length()
to adjust.