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

Add method to test if tag is a pre-release tag #133

Closed
SamyPesse opened this issue Aug 14, 2015 · 4 comments
Closed

Add method to test if tag is a pre-release tag #133

SamyPesse opened this issue Aug 14, 2015 · 4 comments

Comments

@SamyPesse
Copy link

It'd be great to have a method like semver.isPrerelease(v):

> semver.isPrerelease("1.0.0")
false

> semver.isPrerelease("1.0.0-alpha.1")
true
@SamyPesse
Copy link
Author

And maybe have a method to extract the type of prerelease:

> semver.prerelease("1.0.0-alpha.1") // or semver.pre ?
"alpha"

> semver.prerelease("1.0.0-beta.45")
"beta"

@isaacs
Copy link
Contributor

isaacs commented Aug 14, 2015

Shouldn't it return the full "alpha.1" or "beta.45"?

Another option would be to return the full parsed prerelease field if it's there, or else null. Maybe something like this?

> require('semver').parse('1.2.3-alpha.23.bravo.43').prerelease
[ 'alpha', 23, 'bravo', 43 ]
> require('semver').parse('1.2.3').prerelease
[]
> function prerelease (ver) { var p = require('semver').parse(ver); return p && p.prerelease.length && p.prerelease || null }
undefined
> prerelease('1.2.3-alpha.4.bravo.65')
[ 'alpha', 4, 'bravo', 65 ]
> prerelease('1.2.3')
null

@SamyPesse
Copy link
Author

Something like this would be perfect 👍

You're right, it should return the full parsed prerelease, since there is no strict convention on the prerelease's format: some people are using alpha.x and some others are using numerical values like 1.0.0-0.3.7; and others are using the pre-release part as a patch (ex: https://github.com/nwjs/npm-installer#install-a-specific-version-of-nwjs).

I was trying to find the most conventional way to filter versions by "pre-release's category" (stable, beta, alpha, ..) for Nuts. I'll probably consider that pre-release like 1.0.0-0.3.7 are alpha.

ekmartin added a commit to ekmartin/node-semver that referenced this issue Dec 7, 2015
ekmartin added a commit to ekmartin/node-semver that referenced this issue Dec 7, 2015
ekmartin added a commit to ekmartin/node-semver that referenced this issue Dec 8, 2015
@luckydrq
Copy link

I have the same demand. Any update on this?

@isaacs isaacs closed this as completed in 3cc5a94 Jun 28, 2016
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

3 participants