semver icon indicating copy to clipboard operation
semver copied to clipboard

Distinguish between zero values and missing values

Open mcandre opened this issue 3 years ago • 1 comments

I have a need to distinguish between "2" and "2.0" post-parsing, without having to re-parse these strings.

For example, I am writing an automated system to identify when software component versions are no longer supported. The data about support timelines can vary about specificity, so that some products exit support as of a major-wide series 2.x ("2"), whereas other products develop at a much faster rate and can exit support as of particular minor versions ("2.0").

Unfortunately, it appears that semver simply defaults unspecified minor version values, etc. etc. as zero, without providing a clear way to distinguish between an explicit zero input, versus an implicit default of missing information to zero.

I think I may hack around this gap by counting the periods in the original version string prior to parsing with semver. But I would love for a standard feature such as HasMinor(), HasPatch(), HasBuild(), to clarify in a reliable way.

mcandre avatar Jun 03 '22 00:06 mcandre

It's been a little bit since you posted this so may already have a setup that works for this.

When it comes to versions, a missing section is a 0. When an x is used it's a range and that means a constraint. Versions are covered by the semver spec while constraints used for things like ranges are made up by implementers. Some of use try to follow the same patterns.

The way to do all of that with this library is to parse your version as a version (e.g., 2.0.0), create a constraint (e.g., =2.0.0 or 2.x), and then test the version against the constraint.

mattfarina avatar Aug 15 '22 15:08 mattfarina