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

[FEATURE] decrement/truncate

Open isaacs opened this issue 12 years ago • 5 comments

Not pressing or urgent, but mostly for API symmetry, it'd be nice to have truncate/decrement functions.

  1. semver.truncate('1.2.3-foo', 'patch') == '1.2.3'
  2. semver.truncate('1.2.3', 'minor') == '1.2.0'
  3. semver.truncate('1.2.3', 'major') == '1.0.0'
  4. semver.dec('1.2.3-foo', 'patch') == '1.2.2'
  5. semver.dec('1.2.3', 'minor') == '1.1.0'
  6. 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

isaacs avatar Sep 05 '13 04:09 isaacs

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.

aschearer avatar Sep 19 '13 08:09 aschearer

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

sindresorhus avatar Oct 09 '14 23:10 sindresorhus

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.

anko avatar Sep 14 '15 19:09 anko

Any news on this?

ypicard avatar Nov 04 '21 22:11 ypicard