GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ryuapp/js-semver: Parser and evaluator for npm's flavor of Semantic Versioning, compliant with node-semver

BranchesTags
Open more actions menu

Latest commit

 

History

175 Commits
175 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
benches
benches
 
 
fuzz
fuzz
 
 
scripts/coverage
scripts/coverage
 
 
src
src
 
 
tests
tests
 
 
website
website
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
AGENTS.md
AGENTS.md
 
 
Cargo.lock
Cargo.lock
 
 
Cargo.toml
Cargo.toml
 
 
LICENSE
LICENSE
 
 
NOTICE.md
NOTICE.md
 
 
README.md
README.md
 
 
mise.lock
mise.lock
 
 
mise.toml
mise.toml
 
 

Repository files navigation

js-semver

License crates github repo codecov

A parser and evaluator for npm's flavor of Semantic Versioning, compliant with node-semver.

It is written in pure Rust, offers high compatibility with node-semver and high performance, and has zero dependencies by default.

Example

use js_semver::{BuildMetadata, PreRelease, Range, Version};

fn main() {
    let range: Range = ">=4.1.0 <5.0.0".parse().unwrap();

    // Pre-release versions are not included in the range unless explicitly specified.
    let version = Version {
        major: 4,
        minor: 1,
        patch: 0,
        pre_release: PreRelease::new("rc.1").unwrap(),
        build: BuildMetadata::default(),
    };
    assert!(!range.satisfies(&version));

    // Stable version is included in the range.
    let version: Version = "4.1.0".parse().unwrap();
    assert!(range.satisfies(&version));
}

Features

serde

Enable serde to serialize and deserialize versions and ranges:

[dependencies]
js-semver = { version = "1", features = ["serde"] }
serde_json = "1"

For example, read a dependency range from package.json:

use js_semver::Range;

let package: serde_json::Value =
    serde_json::from_str(r#"{"dependencies":{"react":"^19.0.0"}}"#).unwrap();
let react: Range = serde_json::from_value(package["dependencies"]["react"].clone()).unwrap();
assert!(react.satisfies(&"19.1.0".parse().unwrap()));

Range is serialized in its normalized form. Invalid strings produce a deserialization error.

no-std

std feature is enabled by default. To use js-semver in a no_std environment, disable the default features:

[dependencies]
js-semver = { version = "1", default-features = false }

Comparison with other crates

node-semver

node-semver crate has numerous issues, including unnecessary dependencies like miette, incompatibilities with npm's node-semver (e.g., <=1.2 is parsed as <=1.2.0-0 in the crate's v2.2.0 release, so 1.2.9 does not satisfy it), and the fact that it is no longer actively maintained.

Benchmarks

Compared with the node-semver crate, js-semver is 3–13× faster. See the detailed benchmark results.

semver

semver crate is designed for Cargo. Therefore, it is not well-suited for the Node.js ecosystem, such as parsing versions in package.json.

License

MIT-0

This project's tests incorporate material from third parties, but they are not part of the library. For attribution and additional notice information, see NOTICE.md.

About

Parser and evaluator for npm's flavor of Semantic Versioning, compliant with node-semver

js-semver.ryu.app

Topics

node-semvernpmrust

Resources

Readme
MIT-0 license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity

Stars

3 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.