1.4.1 • Published 2 years ago

major-version-check v1.4.1

Weekly downloads
-
License
CC0-1.0
Repository
github
Last release
2 years ago

versionweekly_downloadsdownloadsissueslicense

major-version-check

Version tools

A small module to check the information about versions, such as comparing, parsing version data, and checking if the two version is a major change.


Changelog (v1.4.1)

Fixed conflict in docs. \ • Added new function to readme.md. \ • Added new function to tests. \ • Updated tsconfig.json. \ • Added new scripts to package.json. \ • Some more linting. \ • Added the version check for old node versions.

To-do

• Make parseVersion() function return version numbers as a int instead of a string.


Installation

npm i major-version-check

Usage

This library is ONLY compatible with node version 14 and above

First you must import the library using the following code:

const versionTools = require('major-version-check');
// or `import * as versionTools from 'major-version-check';` for Typescript users

\ Then all you have to do is call the function with some values:

const versionTools = require('major-version-check');
// or `import * as versionTools from 'major-version-check';` for Typescript users

// Will return true
console.log(versionTools.majorVer('1.0.0', '2.0.0'));

// Will return false
console.log(versionTools.majorVer('1.0.0', '1.0.1'));

// Will return info about the version
console.log(JSON.stringify(versionTools.parseVersion('1.0.0-beta')));

// Will return true
console.log(`Output:\n${versionTools.compare(versionTools.parseVersion('1.0.1'), versionTools.parseVersion('1.0.0'), { type: 'greaterThan' })}`);

// Will return false
console.log(`Output:\n${versionTools.compare(versionTools.parseVersion('1.0.1'), versionTools.parseVersion('1.0.0'), { type: 'lessThan' })}`);

Thats it! Now you have it running!

Parameters

Parameter info for majorVer()

ParametersTypeUsageDescription
oldVersionstring (required)majorVer(oldVersion, ...);The old version to compare
newVersionstring (required)majorVer(..., newVersion);The new version to compare
options.debugbooleanmajorVer(..., ..., { debug: boolean });Weather to log debug messages

Parameter info for parseVersion()

ParametersTypeUsageDescription
versionstring (required)parseVersion(version, ...);The version to parse
options.debugbooleanparseVersion(..., { debug: boolean });Weather to log debug messages

Parameter info for compare()

ParametersTypeUsageDescription
versionobject (required)compare(version, ...);The version to compare
comparatorstring (required)compare(..., comparator, ...);The second version to compare
options.debugbooleancompare(..., ..., { debug: boolean });Weather to log debug messages

npm.io