This is an alternative to PR#7. I was having trouble tweaking the existing logic to make it pass all the test cases (specifically to fix ~1.2 without breaking other cases).
So I tried writing the version stuff from scratch, more closely following the semver grammar from the NPM docs.
The rewritten version looks longer and scarier but I personally think it is easier to follow, particularly when you read it in conjunction with: https://docs.npmjs.com/misc/semver
This is an alternative to PR#7. I was having trouble tweaking the existing logic to make it pass all the test cases (specifically to fix
~1.2without breaking other cases).So I tried writing the version stuff from scratch, more closely following the semver grammar from the NPM docs.
The rewritten version looks longer and scarier but I personally think it is easier to follow, particularly when you read it in conjunction with: https://docs.npmjs.com/misc/semver
Up to you whether you prefer this version or not.