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

versioning

v1.1.2

Published

Semantic Versioning Number Compare

Downloads

2,096

Readme

版本号 (version number)


NPM version Build Status Coverage Status

语义化版本号比较模块。

语义化版本号通常定义如下:

Major_Version_Number.Minor_Version_Number[.Revision_Number[.Build_Number]]

主版本号            .子版本号            [.修正版本号     [.编译版本号  ]]

使用

var version = require("versioning");
version.compare("6.0", "6"); // 0
version.eq("6.0", "6"); // true

var v = new version("6.0");
v == 6 // true
v > 6  // false

API

静态方法:

version.compare(v1, v2)

比较两个语义化版本号的大小。

返回:

  • 如果两个版本号都具有的部分相等,返回 0;
  • 如果两个版本号都具有的部分中,v1 大于 v2 则返回 1;
  • 如果两个版本号都具有的部分中,v1 小于 v2 则返回 -1。

version.eq(v1, v2)

比较两个版本号是否相等。

返回:

  • 如果两个版本号都具有的部分相等,返回 true;
  • 否则,返回 false。

version.gt(v1, v2)

比较两个版本号都具有的部分中,v1 是否大于 v2。

返回:

  • 如果 v1 > v2,返回 true;
  • 否则返回 false。

version.gte(v1, v2)

比较两个版本号都具有的部分中,v1 是否大于或等于 v2。

返回:

  • 如果 v1 >= v2,返回 true;
  • 否则,返回 false。

version.lt(v1, v2)

比较两个版本号都具有的部分中,v1 是否小于 v2。

返回:

  • 如果 v1 < v2,返回 true;
  • 否则,返回 false。

version.lte(v1, v2)

比较两个版本号都具有的部分中,v1 是否小于或等于 v2。

返回:

  • 如果 v1 <= v2,返回 true;
  • 否则,返回 false。

实例化

除了上面的静态方法, versioning 还可以进行实例化,API 与上面一致。

特殊的,versioning 实例可以使用算术比较运算符,比较两个版本的大小。

注意:使用算术比较运算符,只能比较到子版本号,而且要求子版本号小于 10 的场景。

var versioning = require("versioning");

var ver = new versioning("6.0");

ver.eq(6); // true.
ver.gte("5.9"); // true.

ver == 6 // true.
ver > 5.9 // true.

注意

JavaScript 引擎的限制,versioning 实例与字符串相加时,只返回两级版本号。 要得到完整的原生版本号,需要使用显示转换方式。

var v = new versioning("1.2.3.4");

"" + v; // "1.2"

String(v); // "1.2.3.4"
v.toString(); // "1.2.3.4"