js_semver/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]
2#![cfg_attr(test, allow(clippy::restriction))]
3//! # js-semver
4//!
5//! <p>
6//! <a href="https://github.com/ryuapp/js-semver/blob/main/LICENSE">
7//! <img alt="License" src="https://img.shields.io/github/license/ryuapp/js-semver?labelColor=171717&color=39b54a&label=License">
8//! </a>
9//! <a href="https://crates.io/crates/js-semver">
10//! <img alt="crates" src="https://img.shields.io/crates/v/js-semver?labelColor=171717&color=39b54a">
11//! </a>
12//! <a href="https://github.com/ryuapp/js-semver">
13//! <img alt="github repo" src="https://img.shields.io/badge/GitHub-ryuapp/js--semver-171717?labelColor=171717&color=39b54a">
14//! </a>
15//! <a href="https://codecov.io/gh/ryuapp/js-semver">
16//! <img alt="codecov" src="https://codecov.io/gh/ryuapp/js-semver/graph/badge.svg?token=P7NMEB4IP7">
17//! </a>
18//! </p>
19//!
20//! A parser and evaluator for npm's flavor of Semantic Versioning.
21//!
22//! This crate is designed for the JavaScript ecosystem and follows [node-semver](https://github.com/npm/node-semver) (the one npm uses) parsing and range semantics.
23//! It maintains high compatibility and performance, and has zero dependencies by default.
24//!
25//!
26//! # Examples
27//!
28//! ```rust
29//! use js_semver::{BuildMetadata, PreRelease, Range, Version};
30//!
31//! fn main() {
32//! let range: Range = ">=4.1.0 <5.0.0".parse().unwrap();
33//!
34//! // Pre-release versions are not included in the range unless explicitly specified.
35//! let version = Version {
36//! major: 4,
37//! minor: 1,
38//! patch: 0,
39//! pre_release: PreRelease::new("rc.1").unwrap(),
40//! build: BuildMetadata::default(),
41//! };
42//! assert!(!range.satisfies(&version));
43//!
44//! // Stable version is included in the range.
45//! let version: Version = "4.1.0".parse().unwrap();
46//! assert!(range.satisfies(&version));
47//! }
48//! ```
49
50#[cfg(not(feature = "std"))]
51extern crate alloc;
52
53// --------------------------------------------------------------------------
54// Constants
55// --------------------------------------------------------------------------
56
57/// Maximum accepted length for any version or range string.
58pub(crate) const MAX_LENGTH: usize = 256;
59
60mod error;
61mod identifier;
62mod number;
63mod range;
64#[cfg(feature = "serde")]
65mod serde;
66mod version;
67
68pub use error::SemverError;
69pub use identifier::{BuildMetadata, PreRelease};
70pub use range::Range;
71pub use version::Version;