Hi there 👋
I am currently using semver.coerce to coerce semver-like strings into a string which only contains a major, minor, and patch version.
The documentation doesn't mention anything about the other things which semver.parse may produce (build number, prerelease, etc.).
...is it safe for me to depend on this behaviour? Is there a better way to do this?
In addition, I need to coerce a lot of strings missing a patch version:
>require('semver').coerce('10.20-45')
SemVer {
options: {},
loose: false,
raw: '10.20.0',
major: 10,
minor: 20,
patch: 0,
prerelease: [],
build: [],
version: '10.20.0'
}
The reason I am asking is because of somewhat surprising results. While I don't want the current behaviour of semver to change, I think if this is too surprising maybe it should. What do you think? 🤔
Welcome to Node.js v16.20.0.
Type ".help" for more information.
> const semver = require('semver')
undefined
> const semverStringWithPrerelease = '10.20.30-40';
undefined
> semver.valid(semverStringWithPrerelease);
'10.20.30-40'
> semver.parse(semverStringWithPrerelease);
SemVer {
options: { loose: false, includePrerelease: false },
loose: false,
raw: '10.20.30-40',
major: 10,
minor: 20,
patch: 30,
prerelease: [ 40 ],
build: [],
version: '10.20.30-40'
}
> semver.coerce(semverStringWithPrerelease);
SemVer {
options: {},
loose: false,
raw: '10.20.30',
major: 10,
minor: 20,
patch: 30,
prerelease: [],
build: [],
version: '10.20.30'
}
> semver.compare(semverStringWithPrerelease, semverStringWithPrerelease)
0
> semver.compare(semver.coerce(semverStringWithPrerelease), semverStringWithPrerelease)
1
Hi there 👋
I am currently using
semver.coerceto coerce semver-like strings into a string which only contains a major, minor, and patch version.The documentation doesn't mention anything about the other things which
semver.parsemay produce (build number, prerelease, etc.)....is it safe for me to depend on this behaviour? Is there a better way to do this?
In addition, I need to coerce a lot of strings missing a patch version:
The reason I am asking is because of somewhat surprising results. While I don't want the current behaviour of
semverto change, I think if this is too surprising maybe it should. What do you think? 🤔