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

@chain1/version-checker

v1.0.0

Published

Version comparison and update checking utilities

Readme

@chain1/version-checker

Version comparison and update checking utilities with semantic versioning support.

Installation

npm install @chain1/version-checker

Features

  • 🔢 Semantic Versioning: Full semver support (major.minor.patch)
  • 📊 Version Comparison: Compare any two version strings
  • Update Checking: Check for available updates
  • 🔒 Force Update Detection: Identify when force update is needed
  • 🛠️ Version Utilities: Parse, increment, validate versions
  • 📝 TypeScript: Full type definitions included

Usage

Compare Versions

import { compareVersions } from '@chain1/version-checker';

compareVersions('1.2.3', '1.2.4'); // -1 (first is older)
compareVersions('2.0.0', '1.9.9'); // 1 (first is newer)
compareVersions('1.0.0', '1.0.0'); // 0 (equal)

Check for Updates

import { checkForUpdate } from '@chain1/version-checker';

const result = checkForUpdate('1.0.0', {
  version: '1.2.0',
  minRequiredVersion: '1.1.0',
});

console.log(result.needsUpdate); // true
console.log(result.forceUpdate); // true (below min required)

Parse Version

import { parseVersion } from '@chain1/version-checker';

const parts = parseVersion('1.2.3'); // [1, 2, 3]

Validate Version

import { isValidVersion } from '@chain1/version-checker';

isValidVersion('1.2.3'); // true
isValidVersion('1.2'); // false
isValidVersion('v1.2.3'); // false

Get Version Parts

import { getMajorVersion, getMinorVersion, getPatchVersion } from '@chain1/version-checker';

getMajorVersion('1.2.3'); // 1
getMinorVersion('1.2.3'); // 2
getPatchVersion('1.2.3'); // 3

Increment Version

import { incrementVersion } from '@chain1/version-checker';

incrementVersion('1.2.3', 'major'); // '2.0.0'
incrementVersion('1.2.3', 'minor'); // '1.3.0'
incrementVersion('1.2.3', 'patch'); // '1.2.4'

Check Minimum Version

import { satisfiesMinVersion } from '@chain1/version-checker';

satisfiesMinVersion('1.2.0', '1.0.0'); // true
satisfiesMinVersion('0.9.0', '1.0.0'); // false

API Reference

Types

interface VersionInfo {
  version: string;
  minRequiredVersion?: string;
  isActive?: boolean;
  releaseNotes?: string;
}

interface UpdateCheckResult {
  needsUpdate: boolean;
  forceUpdate: boolean;
  currentVersion: string;
  latestVersion: string;
  minRequiredVersion?: string;
}

Functions

parseVersion(version: string): number[]

Parse version string to array of numbers.

compareVersions(version1: string, version2: string): number

Compare two versions. Returns:

  • 1 if version1 > version2
  • -1 if version1 < version2
  • 0 if equal

checkForUpdate(currentVersion: string, versionInfo: VersionInfo): UpdateCheckResult

Check if update is needed based on server version info.

isValidVersion(version: string): boolean

Validate version string format (X.Y.Z).

getMajorVersion(version: string): number

Get major version number.

getMinorVersion(version: string): number

Get minor version number.

getPatchVersion(version: string): number

Get patch version number.

incrementVersion(version: string, type: 'major' | 'minor' | 'patch'): string

Increment version by type.

satisfiesMinVersion(version: string, minVersion: string): boolean

Check if version meets minimum requirement.

Example: App Update Flow

import { checkForUpdate } from '@chain1/version-checker';

async function checkAppUpdate(currentVersion: string) {
  // Fetch version info from your server
  const versionInfo = await fetch('/api/version').then(r => r.json());

  const result = checkForUpdate(currentVersion, versionInfo);

  if (result.forceUpdate) {
    // Show force update dialog
    alert('Critical update required. Please update to continue.');
    // Redirect to app store
  } else if (result.needsUpdate) {
    // Show optional update dialog
    alert('New version available. Update now?');
  }
}

checkAppUpdate('1.0.0');

License

MIT

Links