Socket
Book a DemoInstallSign in
Socket

@workplus/compare-versions

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@workplus/compare-versions

A simple version comparison tool.

latest
npmnpm
Version
1.0.1
Version published
Maintainers
2
Created
Source

compare-versions

A simple version comparison tool.

The comparison principle is very simple, the version string is converted into a string of the same length, the default is 10, and then directly determine the size. But if the version of the type is inconsistent, such as 3.13.1 and 3.14, may get unexpected results, So, please make sure the version type you entered is the same.

'3.13.1' => '0000000003.0000000013.0000000001'

Judgment rules and return results are as follows:

  • if a > b, return 1
  • if a === b, return 0
  • if a < b, return -1
  • if (versions type is inconsistent) return null

Install

npm install -S @workplus/compare-versions

Usage

Import

// ES6
import compareVersions from '@workplus/compare-versions';

// Node
const compareVersions = require('@workplus/compare-versions');

Compare

/**
 * compareVersions(a, b, c)
 * 
 * @param {string} a version
 * @param {string} b another version
 * @param {number} c string length, default 10
 */

compareVersions('3.13.1', '3.13.0', 10); //  1
compareVersions('3.14.1', '3.14.1', 2); //  0
compareVersions('3.14.1', '4.14.1'); // -1
compareVersions('3.14.1', '4.14'); // null

License

MIT Hejx

Keywords

compare versions

FAQs

Package last updated on 17 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.