node-semver
node-semver copied to clipboard
[FEATURE] decrement/truncate
Not pressing or urgent, but mostly for API symmetry, it'd be nice to have truncate/decrement functions.
semver.truncate('1.2.3-foo', 'patch') == '1.2.3'semver.truncate('1.2.3', 'minor') == '1.2.0'semver.truncate('1.2.3', 'major') == '1.0.0'semver.dec('1.2.3-foo', 'patch') == '1.2.2'semver.dec('1.2.3', 'minor') == '1.1.0'semver.dec('1.2.3', 'major') == '0.0.0'
Re #46, but the use case presented there turned out to not require this functionality. It's still probably useful, though.
cc @ronkorving
Would be handy to have semver.dec. I would like to generate a change log from git based on the current version and the previous version. Not sure of a way to get the previous version short of decrementing the package's version.
I didn't have time to do a proper patch, but I did a quick module for truncation if anyone else needs it: https://github.com/sindresorhus/semver-truncate
What should semver.dec('2.0.0', 'patch') be? 1.99.99? 1.0.0? Something in between? The semver spec doesn't define how to decrement a semver or what it even means. I suspect this is why.
Any news on this?