https://github.com/tomchen/semver-ts
https://github.com/tomchen/semver-ts
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tomchen/semver-ts
- Owner: tomchen
- License: isc
- Created: 2025-03-10T20:07:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-10T21:13:36.000Z (over 1 year ago)
- Last Synced: 2025-03-10T21:24:26.394Z (over 1 year ago)
- Language: TypeScript
- Homepage: http://semver.tomchen.org/
- Size: 67.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
SemVer TS
SemVer (Semantic Versioning) JavaScript library's
TypeScript
Tree-Shakable
Tiny Size
Turbo Speed[1]
Version
A fork and drop-in replacement of npm's official [semver](https://www.npmjs.com/package/semver) library, it has all 26 functions of the original library (except `satisfies`)[2], with the same implementation and the same API, passes all the original's tests[3], but:
- It is more lightweight and perfectly treeshakable with ES modules[4]
- It removed SemVer class and uses a purely functional approach[5]
- It is written in TypeScript, has correct types[6] and is well-commented and -documented[7].
## Usage
Installation:
```
npm install semver-ts
```
In your ES module (recommanded instead of CommonJS) JavaScript/TypeScript code:
```js
import { compare } from "semver-ts"
compare("1.0.0", "1.0.3")
```
Or directly in HTML (not tree-shakable, obviously):
```html
semver.compare("1.0.0", "1.0.3")
```
Documentation: [https://semver.tomchen.org/](https://semver.tomchen.org/)
## Size comparison
ES module treeshaked and minified (with terser) bundle size comparison:
Code
Minified
Gzipped
import { compare } from "semver-ts"
compare("1.0.0", "1.0.3")
2.00 KB
914 bytes
import compare from "semver/functions/compare"
compare("1.0.0", "1.0.3")
8.95 KB
2.80 KB
import { compare } from "semver"
compare("1.0.0", "1.0.3")
25.9 KB
7.55 KB
## Notes
[1] Turbo Speed: OK, the current version faithfully uses the original implementation so it's not really that fast, but it should be slightly faster than the original due to the fact that it removes the class-based structure and uses a purely functional approach
[2] All 'semver/functions/*', except for 'semver/functions/satisfies' which is intended to be included in the future. List of functions: `clean`, `cmp`, `coerce`, `compare`, `compareBuild`, `compareCore`, `compareIdentifiers`, `compareLoose`, `diff`, `eq`, `gt`, `gte`, `inc`, `incThrow`, `lt`, `lte`, `major`, `minor`, `neq`, `parse`, `patch`, `prerelease`, `rcompare`, `rsort`, `sort`, `valid`
[3] Faithfully uses the same implementation code, same function signatures (even the same weird overload of `inc()`) (only replacing SemVer class by an object containing parsed semver information), and passed all the tests in the original library (semver v7.7.1 (2025-02-03))
[4] Not tree-shakable with CommonJS exports. The support for `const a = require("semver/a")` CommonJS treeshakability could be done but will increase the size of the ESM bundle. So, just use the modern ES modules
[5] Currently, class is not tree-shakable with any bundler, and with either ES modules or CommonJS exports. Therefore, despite the [effort](https://github.com/npm/node-semver/issues/291) to make the original semver tree-shakable, user's bundling output may still contain a lot of unused code, mainly from the SemVer class
[6] Some functions in @types/semver, such as `inc()`, do not seem to have correct types
[7] You can hover over a function to see very detailed information including examples in VS Code thanks to the comments. The documentation webpages are automatically generated from the comments with TypeDoc.