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

allow to specify a uuid version to validate method #526

Closed
ben8p opened this issue Oct 7, 2020 · 3 comments
Closed

allow to specify a uuid version to validate method #526

ben8p opened this issue Oct 7, 2020 · 3 comments

Comments

@ben8p
Copy link

ben8p commented Oct 7, 2020

Is your feature request related to a problem? Please describe.

Cross referencing thenativeweb/uuidv4#221

There is currently no way to know if a given string is a valid uuid of a specific version. We can only know if it is a valid uuid (regardless of the version)

Describe the solution you'd like

add a 2nd argument to validate where we can specify the version of the uuid to check against.

Describe alternatives you've considered

add methods such as validateV4, validateV5, ....

Additional context

See the uuidv4 issue linked on top of the feature request

@ctavan
Copy link
Member

ctavan commented Oct 7, 2020

You can use uuid.version(), which calls validate under the hood and returns the version as a number. It throws the same error as uuid.validate() an error when call with a malformed uuid.

Does that work for you?

@ctavan
Copy link
Member

ctavan commented Oct 7, 2020

If you don't want to catch the error you can also do something like:

function validateV4(str) {
  return uuid.validate(str) && uuid.version(str) === 4;
}

@ben8p
Copy link
Author

ben8p commented Oct 7, 2020

Sounds great!
Indeed using.version is a satisfying approach.

Thanks
Closing for now.

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

No branches or pull requests

2 participants