Socket
Socket
Sign inDemoInstall

@w6s/compare-versions

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @w6s/compare-versions

A simple version comparison tool.


Version published
Weekly downloads
3
Maintainers
1
Install size
12.6 kB
Created
Weekly downloads
 

Readme

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 @w6s/compare-versions

Usage

Import
// ES6
import compareVersions from '@w6s/compare-versions';

// Node
const compareVersions = require('@w6s/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

Author

  • youth7
  • Hejx

License

MIT

Keywords

FAQs

Last updated on 14 Nov 2019

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc