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 🙏

© 2024 – Pkg Stats / Ryan Hefner

calver

v24.1.0

Published

Calendar based software versioning library as node.js module and with cli support.

Downloads

20,558

Readme

node-calver

Calendar based software versioning library as node.js module and with cli support. 📅

What is calendar based versioning?

It's a way of tagging software state based on in combination of a chosen calendar tags such as YYYY, MM, DD. The chosen tags convey the message of how frequently the software gets major updates, to the user. It doesn't tell anything about breaking changes (there is git-diff for that) but it tells when the next major release will come.

I recommend this article by Donald Stufft to read more about versioning softwares and this website by Mahmoud Hashemi to learn more about calendar versioning.

What does it look like?

The format consist of two parts. The calendar part and the minor changes counter. The calendar part describes software's release cycle. The minor part is just a counter over the main release. Take 2024-4.104 for example; the year and the month separated by a dash and the minor counter separated by a dot. So the general template for the format is YYYY-MM-DD.MINOR. One might choose:

  • YYYY for yearly release cycle
  • YYYY-MM for monthly release cycle
  • YYYY-WW for weekly release cycle
  • YYYY-MM-DD for daily release cycle

The releases sent before the next release time period, counts as minor changes and therefore it increments the minor part of the version.

Prerequisites

  • What is your release cycle? Decide how frequently you will release your software. Excluding minor changes such as security fixes or other kind of features and fixes.

Install

npm i -D calver
# or
pnpm add -D calver

Usage

The library can be used both as a node.js module and a cli app. Both usages documented below per feature.

Library defaults

There are some defaults to keep in mind while using node-calver.

  • Minor counter is 0 by default and it's hidden from the output if it's zero.
  • The values of calendar tags computed based on UTC time.
  • The year always exists in the output and can't be omitted. The other tags is up to a user.
  • When month, week or day isn't specified, they are considered as zero and this is important when comparing dates.

Cycles

Finds the next version based on release cycle.

import * as calver from 'calver'

calver.cycle('2024-4.204')
calver 2024-4.204

Depending on the date the code above executed, the output will be 2024-4.205, 2024-5 or 2024-[current month].

It's capable to understand the format you chose with one exception.

calver.cycle('2024.204')
calver 2024.204

Outputs 2024.205 or [current year].

The full year, month and day cycle:

calver.cycle('2024-4-16.204')
calver 2024-4-16.204

Outputs 2024-4-16.205 or [current date as YYYY-MM-DD].

And the exception is weeks. A cycle option needs to be passed for weekly release cycles:

calver.cycle('2024-32.204', { cycle: 'week' })
calver 2024-32.204 --cycle week # or -c week

Outputs 2024-32.205 or 2024-[current week of the year].

Minor releases

A minor method just increments the minor portion of the version and leaves the date portion as it is.

calver.minor('2024') // outputs 2024.1
calver 2024 --minor # outputs 2024.1
calver.minor('2024.204') // outputs 2024.205
calver 2024.204 --minor # outputs 2024.205
calver.minor('2024-4-16.204') // outputs 2024-4-16.205
calver 2024-4-16.204 --minor # outputs 2024-4-16.205

and so on.

Create an initial version

calver.initial({ cycle: 'month' })
calver initial --cycle month

Outputs [current year]-[current month].

Valid

calver.valid('2024-4.123')
// provide cycle for more strict check
calver.valid('2024-4.123', { cycle: 'month' })

Outputs a boolean.

calver valid 2024-4.123
# or specify --cycle flag for more strict check
calver valid --cycle month

Outputs the exact version string or exits with error.

Comparison

// newer than
calver.nt('2024-4-20', '2024-4-19') // true
calver.nt('2024-4-20', '2024') // true
calver.nt('2024', '2024-4-20') // false

// older than
calver.ot('2024-4-20', '2024-4-19') // false
calver.ot('2024-4-20', '2024') // false
calver.ot('2024', '2024-4-20') // true

// speciy cycle if you use weeks
calver.nt('2024-32', '2024-30', { cycle: 'week' }) // true

Returns a boolean

calver nt 2024-4-20 2024-4-19
calver ot 2024-4-20 2024-4-19
calver nt 2024-32 2024-30 --cycle week

Outputs the exact version string or exits with error.

Prefix, suffix and clean

Simple helper methods that might be useful in your versioning processes.

calver.prefix('2024-4.123') // outputs v2024-4.123
calver.prefix('2024-4.123', 'v') // outputs v2024-4.123

calver.suffix('2024-4.123', '-something') // outputs 2024-4.123-something

calver.clean(' =v2024-4.123-something ') // 2024-4.123

They work same as in the module api:

calver prefix 2024-4.123
calver prefix 2024-4.123 --prefix v
calver suffix 2024-4.123 --suffix something
calver clean " =v2024-4.123-something "

Contributing

If you're interested in contributing, read the CONTRIBUTING.md first, please.


Version management of this repository done by releaser 🚀


Thanks for watching 🐬

Support me on Patreon