Created
September 1, 2025 19:59
-
-
Save aMarCruz/95175cfa57caf8bfcb5f3727a189c257 to your computer and use it in GitHub Desktop.
Test that `semver.satisfies` performs a conversion from `#` to `#.x.x` and not a coercion to `#.0.0`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import semver from 'semver' | |
| const SEMVER1 = '1.2.0' | |
| const SEMVER2 = '1.2.8' | |
| const tests = [ | |
| '1', // === '1.x.x' | |
| '1.2', | |
| '1.2.0', | |
| '1.2.x', | |
| '=1', | |
| '=1.2', | |
| '=1.2.0', | |
| '=1.2.x', | |
| '~1', // === '1.x.x' ? | |
| '~1.2', | |
| '~1.2.0', // === '1.2.x' | |
| '^1', | |
| '^1.2', | |
| '^1.2.0', | |
| '<1', | |
| '<1.2', | |
| '<1.2.0', | |
| '<=1', | |
| '<=1.2', | |
| '<=1.2.0', | |
| '>1', | |
| '>1.2', | |
| '>1.2.0', | |
| '>=1', | |
| '>=1.2', | |
| '>=1.2.0', | |
| ] as const | |
| const showit = (x: string) => { | |
| const test: [string, string][] = tests.map((c) => [x, c]) | |
| for (const [version, condition] of test) { | |
| const spc = ''.padEnd(9 - condition.length) | |
| const result = semver.satisfies(version, condition) | |
| console.log(`semver.satisfies('${version}', '${condition}')${spc}// ${result}`) | |
| } | |
| } | |
| console.log(showit(SEMVER1)) | |
| console.log('so...') | |
| console.log(showit(SEMVER2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment