semver-es
v0.1.1
Published
Modern ESM-first TypeScript rewrite of npm's semver.
Readme
semver-es
semver-es is an ESM-first TypeScript refactor of node-semver. It is designed to keep the upstream root API shape as consistent as possible, so existing semver usage can move to ESM imports with minimal changes. It is developed on top of the upstream node-semver implementation, which is licensed under ISC.
pnpm add semver-esUsage
import {
clean,
coerce,
Comparator,
gt,
lt,
minVersion,
Range,
satisfies,
SemVer,
valid,
} from 'semver-es'
valid('1.2.3') // '1.2.3'
valid('a.b.c') // null
clean(' =v1.2.3 ') // '1.2.3'
satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true
gt('2.0.0', '1.9.9') // true
lt('1.2.3', '9.8.7') // true
minVersion('>=1.0.0')?.version // '1.0.0'
valid(coerce('v2')) // '2.0.0'
valid(coerce('42.6.7.9.3-alpha')) // '42.6.7'
new SemVer('1.2.3').version // '1.2.3'
new Range('^1.2.0').range // '>=1.2.0 <2.0.0-0'
new Comparator('>=1.2.3').value // '>=1.2.3'Avoid Duplicate Bundles
If a dependency still imports semver, your bundle may include both semver and semver-es. Alias those imports to semver-es so everything resolves to a single implementation.
For example, with tsdown:
import { defineConfig } from 'tsdown'
export default defineConfig({
alias: {
'semver': 'semver-es',
'semver/functions/valid': 'semver-es/functions/valid',
'semver/functions/satisfies': 'semver-es/functions/satisfies',
'semver/ranges/valid': 'semver-es/ranges/valid',
},
})License
MIT License © jinghaihan
Based on node-semver, licensed under ISC.
