node-semver icon indicating copy to clipboard operation
node-semver copied to clipboard

[QUESTION] includePrerelease usage

Open bz888 opened this issue 2 years ago • 9 comments

Hey, just wondering how do you use the prerelease tag in validRange e.g. const validated = valid('1.2.0-19', { includePrerelease: true})

With my understanding of includePrerelease this would result to null. However, currently it returns 1.2.0-19 Is there perhaps another more suited method I should be looking at?

Thank you in advance~

bz888 avatar Jul 15 '22 03:07 bz888

Why would that be invalid? It's a range of one.

ljharb avatar Jul 15 '22 17:07 ljharb

Is there a build-in method that checks for the -19 part ? If there is a -19 returns invalid

bz888 avatar Jul 16 '22 04:07 bz888

Sorry, I mistyped. I was meant to say includePrerelease: false

bz888 avatar Jul 17 '22 21:07 bz888

A range won’t implicitly include prereleases when that option is set to false, but that is an exact version. This behavior seems correct to me.

ljharb avatar Jul 18 '22 00:07 ljharb

Is there perhaps another way to identify an prerelease using semver ?

bz888 avatar Jul 18 '22 03:07 bz888

Are you looking for the prerelease function?

ljharb avatar Jul 18 '22 03:07 ljharb

Something similar I guess. But mainly looking for if i can accomplish these conditions with one function: 1.2.0-20 or ^1.2.0-20 fail (any version that supports pre release would fail) >=1.2.20 pass * pass 1.2.0 pass

or would I have to layer a bunch of semver functions together to accomplish this ?

bz888 avatar Jul 18 '22 05:07 bz888

prerelease(version) === null tells you exactly that.

ljharb avatar Jul 18 '22 05:07 ljharb

Oh ! thank you so much!

bz888 avatar Jul 19 '22 04:07 bz888

I think this question has been answered. If not, please reopen or open a new issue.

lukekarrys avatar Oct 27 '22 17:10 lukekarrys