Skip to content

Repository files navigation

@plotdb/semver

semantic version utility. a tiny (~1KB minified) browser-friendly alternative to npm's semver, covering the subset of range syntax used in plotdb projects.

Installation

npm install --save @plotdb/semver

Usage

require! <[@plotdb/semver]>

# fit(version, range) - test if a version satisfies a range
semver.fit "1.5.0", "^1.3.2"          # true
semver.fit "1.5.0", "~1.3.2"          # false
semver.fit "0.3.0", "^0.2.3"          # false (caret locks left-most non-zero component)

# compare(a, b) - -1 / 0 / 1, usable with Array.prototype.sort
semver.compare "1.10.0", "1.9.0"      # 1
semver.compare "1.2.3-beta", "1.2.3"  # -1 (release > prerelease)

# max-satisfying(versions, range) - latest version in list satisfying range, or null
semver.max-satisfying <[1.2.3 1.9.9 2.0.0]>, "^1.2.3"   # "1.9.9"

# valid(version) / valid-range(range) - syntax check
semver.valid "1.2.3"                  # true
semver.valid-range "^1.2.3"           # true
semver.valid-range "main"             # false

in browser (via script tag), the module is exposed as window.semver; kebab-case names become camelCase in plain js (maxSatisfying, validRange).

supported range syntax: exact (1.2.3), caret (^1.2.3), tilde (~1.2.3), > / >=. missing components are treated as 0 (^1.2 == ^1.2.0); wildcards (1.x, *) and compound ranges (>=1.2 <2, ||) are not supported.

prerelease versions (1.2.3-beta.1) follow npm semantics: they only satisfy a range that explicitly carries a prerelease with the same major.minor.patch.

License

MIT

About

semantic version parser and matcher

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages