Validating versions and version ranges

#47 · closed · 3 comments

View on GitHub ↗

r3ps4J

Hi! I want to check if a semver version or version range string is valid. With [node-semver](https://github.com/npm/node-semver) I'm using `valid(v)` (for versions) and `validRange(range)` (for ranges) to do this. See the following Typescript code: ```ts if (!semver.valid(actualVersion)) { return false; } if (!semver.validRange(requiredVersion)) { return false; } ``` Can this be done with your library as well in C++? For versions I think I can make use of the from_string methods and check the return or error, based on the following from the readme file: ```cpp // Non-member from string. semver::version v5 = semver::from_string(s); // constexpr and may throw. std::optional<version> v6 = semver::from_string_noexcept(s); // constexpr and no throw. // From string. semver::version v7; v7.from_string(s); // constexpr and may throw. bool success = v7.from_string_noexcept(s); // constexpr and no throw. ``` But I'm not sure if something similar is possible for version ranges. What would be the best way to recreate my typescript code in C++ using your library? I'm a bit new to C++, so let me know if you need more info!

Comments

Naratzul

Hi! Unfortunately, the old implementation does not support API for range validation. However, you can explore our recently released new implementation, which now includes this functionality. The `semver::parse` function has been updated to return an `std::errc` for both versions and ranges. For more details, please refer to this [example](https://github.com/Neargye/semver/blob/master/example/range_example.cpp).

chudonghao

When will the release version be released?

Neargye

v1.0.0-rc released