npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@betternpm/semver

v1.0.0

Published

Rewritten semver by @betternpm

Readme

image

📜 List of Contest

Install

NPM

npm install @betternpm/semver

PNPM

pnpm add @betternpm/semver

Yarn

yarn add @betternpm/semver

TLDR (Only Most Important!)

Functions

| Name | Description | | ------------------------------- | --------------------------------------------------------------------------------------- | | parseSemVer | Parse and validate into semver object | | compareSemver | Compare versions and return result 1 \| 0 \| -1 | | satisfies | Check that version pass range ex >=1.0.0 \|\| 0.5.0 | | increase | Increase semver major/minor/patch/prerelease/buildmetadata/premajor/preminor/premajor | | difference | Show most important differenceerence between versions | | minVersion | Show minimum version which pass range. | | simplifyRange | Simplify Range for inputed versions |

Classes

| Name | Description | | ----------------- | ----------------------------------------------- | | SemVer | Represents a class SemVer version with methods. |

Types

| Name | Description | | ----------------------- | --------------------------- | | TReleases | Represents a release types. |

Variables

| Name | Description | | ------------------------------- | ----------------------------------- | | RELEASE_TYPES | Represents a release type as Array. |

Table of Compatibility

Table of compatibility of functionalities with the official list of exports from the npm package semver with day of commit.

[!IMPORTANT]
There you not gonna find all @betternpm/semver package functions!

Status

| Emoji | Meaning | | ----- | ----------------------------------------------------- | | ✅ | Completed | | ⏸️ | Paused | | 🟧 | exist/you can use differenceerent function / no alias | | ❌ | Aborted | | 🛠️ | In Progress | | 💤 | Not Yet Started | | ℹ️ | Additional Comment |

Table

| Export | Progress Status | | ------------------- | ------------------------------------------------------------------------ | | parse | ✅🟧 parseSemVer | | valid | ✅🟧 parseSemVer | | clean | 🟧 SemVer.format | | inc | 🟧 increase | | difference | ✅ | | major | ❌🟧 parseSemVer | | minor | ❌🟧 parseSemVer | | patch | ❌🟧 parseSemVer | | prerelease | ❌🟧 parseSemVer | | compare | ✅ | | rcompare | ❌🟧 compareSemver) | | compareLoose | ❌🟧 compareSemver) | | compareBuild | ✅ | | sort | ❌ ℹ️ You can do it with sort algo using compareSemver | | rsort | ❌ | | gt | ❌🟧 compareSemver | | lt | ❌🟧 compareSemver | | eq | ❌🟧 compareSemver | | neq | ❌🟧 compareSemver | | gte | ❌🟧 compareSemver | | lte | ❌🟧 compareSemver | | cmp | ❌🟧 compareSemver | | coerce | ❌🟧 parseSemVer | | Comparator | ❌ | | Range | ❌ | | satisfies | ✅ | | toComparators | ❌ | | maxSatisfying | ❌ℹ️ You can do this with loop and satisfies | | minSatisfying | ❌ℹ️ You can do this with loop and satisfies | | minVersion | ✅ | | validRange | ❌🟧 parseSemVer with rangeMode at options | | outside | ❌🟧 satisfies | | gtr | ❌🟧 compareSemver | | ltr | ❌🟧 compareSemver | | intersects | ❌🟧 satisfies | | simplifyRange | ✅ | | subset | ❌ℹ️ (Didn't see need of this, maybe add in future) | | SemVer | ✅ | | re | ❌ℹ️ (Didn't see need of this) | | src | ❌ℹ️ (Didn't see need of this) | | tokens | ❌ℹ️ (Didn't see need of this) | | SEMVER_SPEC_VERSION | ❌ | | RELEASE_TYPES | ✅ | | compareIdentifiers | ❌🟧 compareSemver | | rcompareIdentifiers | ❌🟧 compareSemver |

Classes

SemVer

Class creating SemVer object which has own methods.

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

Functions

parseSemVer

Parses a semantic version string or range (options).

import { parseSemVer } from "@betternpm/semver";

const version = parseSemVer("1.2.3-prerelease.0+20241025");
console.log(version.major); // 1
console.log(version.minor); // 2
console.log(version.patch); // 3
console.log(version.prerelease); // ["prerelease",0]
console.log(version.buildmetadata); // [20241025]
console.log(version.version()); // "1.2.3-prerelease.0+20241025"

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

compareSemver

Compare A to B in full scope.

import { compareSemver } from "@betternpm/semver";

console.log(compareSemver("1.3.0", "1.2.3")); // 1 - because A is bigger than B
console.log(compareSemver("1.3.0", "1.3.0")); // 0 - because A is same as B
console.log(compareSemver("1.2.3", "1.3.0")); // -1 - because A is smaller than B

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

compareMinorMajorPatch

Compare A to B but ONLY in Major/Minor/Patch scope.

import { compareMinorMajorPatch } from "@betternpm/semver";

console.log(compareMinorMajorPatch("1.3.0", "1.2.3")); // 1 - because A is bigger than B
console.log(compareMinorMajorPatch("1.3.0-alpha", "1.3.0")); // 0 - because A is same as B (We care only about MMP)
console.log(compareMinorMajorPatch("1.2.3", "1.3.0")); // -1 - because A is smaller than B

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

comparePrerelease

Compare A to B but ONLY in prerelease scope.

import { comparePrerelease } from "@betternpm/semver";
// am > alpha.1 > alpha.0 > alpha
console.log(comparePrerelease("1.3.0-alpha.1", "1.2.3-alpha.0")); // 1 - because A is bigger than B
console.log(comparePrerelease("1.3.0-alpha", "1.2.0-alpha")); // 0 - because A is same as B (We care only about MMP)
console.log(comparePrerelease("1.3.0-alpha", "1.2.0")); // -1 - because A is smaller than B (no prereleases > prereleases)

console.log(comparePrerelease("1.3.0-alpha", "1.2.0-am")); // -1 - In this case just comparing them to first differenceerence v1[i] > v2[i].
console.log(comparePrerelease("1.3.0-alpha", "1.2.0-alphaa")); // -1 - Same as above but ends at last element in v1 or v2 (longer one).

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

compareBuild

Compare A to B but ONLY in buildmetadata.

import { compareBuild } from "@betternpm/semver";

console.log(compareBuild("1.3.0+124", "1.2.3+123")); // 1 - because A is bigger than B
console.log(compareBuild("1.3.0+123", "1.2.0+123")); // 0 - because A is same as B (We care only about MMP)
console.log(compareBuild("1.3.0+1.2.2", "1.2.0+123")); // -1 - because A is smaller than B (no prereleases > prerelease)
console.log(compareBuild("1.3.0", "1.2.0+123")); // -1 - because A is smaller than B (no prereleases > prerelease)
console.log(compareBuild("1.3.0+a", "1.2.0+b")); // -1 In this case just comparing them to first differenceerence v1[i] > v2[i].
console.log(compareBuild("1.3.0+a", "1.2.0+aa")); // -1 - Same as above but comparing to last element in v1 or v2 (longer one).

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

satisfies

Checks that version pass range ex >=1.0.0 || 0.5.0

import { satisfies } from "@betternpm/semver";

console.log(satisfies("1.2.3", ">=1.0.0 || 0.5.0")); // true - Must be equal or higher than 1.0.0 or equal 0.5.0
console.log(satisfies("0.5.0", ">=1.0.0 || 0.5.0")); // true - Must be equal or higher than 1.0.0 or equal 0.5.0
console.log(satisfies("0.4.0", ">=1.0.0 || 0.5.0")); // false - Must be equal or higher than 1.0.0 or equal 0.5.0
console.log(satisfies("0.1.3", ">2.0.0")); // false - Must be higher than 2.0.0

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

increase

Increase semver `major/minor/patch/prerelease/buildmetadata/premajor/preminor/premajor

[!IMPORTANT]
At prerelease and buildmetadata always increase last found number.

import { increase } from "@betternpm/semver";

console.log(increase("1.2.3", "major", "string")); // 2.0.0
console.log(increase("1.2.3", "minor", "string")); // 1.3.0
console.log(increase("1.2.3", "patch", "string")); // 1.2.4

console.log(increase("1.2.3", "prerelease", "string")); //1.2.3-0
console.log(increase("1.2.3-0", "prerelease", "string")); //1.2.3-1
console.log(increase("1.2.3", "prerelease", "string", { value: "alpha" })); // 1.2.3-alpha
console.log(increase("1.2.3-alpha", "prerelease", "string")); // 1.2.3-alpha.0

console.log(increase("1.2.3", "buildmetadata", "string")); //1.2.3+0
console.log(increase("1.2.3+0", "buildmetadata", "string")); //1.2.3+1
console.log(increase("1.2.3", "buildmetadata", "string", { value: "build" })); // 1.2.3+build
console.log(increase("1.2.3+build", "buildmetadata", "string")); // 1.2.3+build.0

console.log(increase("1.2.3", "premajor", "string")); // 2.0.0-0
console.log(increase("1.2.3", "preminor", "string")); // 1.3.0-0
console.log(increase("1.2.3", "premajor", "string")); // 1.2.4-0
// etc...

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

difference

Show most important differenceerence between versions

import { difference } from "@betternpm/semver";

console.log(difference("1.0.0", "2.5.0")); // "major"
console.log(difference("1.1.0", "1.2.0")); // "minor"
console.log(difference("1.1.1", "1.1.2")); // "patch"
console.log(difference("0.0.0", "0.0.0")); // undefined

console.log(difference("1.0.0", "2.0.0-prerelease")); // "premajor"
console.log(difference("1.0.0", "1.1.0-prerelease")); // "preminor"
console.log(difference("1.0.0", "1.0.1-prerelease")); // "prepatch"
console.log(difference("1.0.0-alpha", "1.0.0-beta")); // "prerelease"

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

minVersion

Show minimum version which pass range.

import { minVersion } from "@betternpm/semver";

console.log(minVersion(">=1.0.0 || 0.5.0")); //  0.5.0
console.log(minVersion(">=1.0.0")); // 1.0.0
console.log(minVersion("<=1.0.0")); // 0.0.0
console.log(minVersion(">2.0.0")); // 2.0.1

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

simplifyRange

Simplify Range for inputed versions

import { simplifyRange } from "@betternpm/semver";

console.log(simplifyRange(["0.0.0", "1.0.0", "0.5.0", "2.0.1"], ">=1.0.0 || 0.5.0")); // >=0.5.0
console.log(simplifyRange(["0.0.0", "1.0.0", "0.5.0", "2.0.1"], ">=1.0.0")); // >=1.0.0
console.log(simplifyRange(["0.0.0", "1.0.0", "0.5.0", "2.0.1"], "<=1.0.0")); // <=1.0.0
console.log(simplifyRange(["2.0.1"], ">2.0.0")); // *

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

Types

TReleases

type with every possible release (from variable RELEASE_TYPES)

Links: [📄File] [🐒TESTS]

Scroll to List of Contest

Variables

PATTERNS

| Name | Description | | --------------------- | ------------------------------------ | | PATTERN_STRICT_SEMVER | RegEx Pattern used for strict semver | | PATTERN_LOOSE_SEMVER | RegEx Pattern used for loose semver | | PATTERN_RANGE_MODE | RegEx Pattern used for range semver |

Links: [📄File]

Scroll to List of Contest

RELEASE_TYPES

Array with every possible

Links: [📄File] [🐒TESTS]

Scroll to List of Contest