@hapi/somever
Advanced tools
Comparing version 2.1.1 to 3.0.0
156
lib/index.js
@@ -47,2 +47,82 @@ 'use strict'; | ||
exports.compare = function (a, b, options = {}) { | ||
let aFirst = -1; | ||
let bFirst = 1; | ||
a = exports.version(a, options); | ||
b = exports.version(b, options); | ||
// Mark incompatible prereleases | ||
if (options.range && | ||
a.prerelease.length && | ||
(a.major !== b.major || a.minor !== b.minor || a.patch !== b.patch || !b.prerelease.length)) { | ||
aFirst = -2; | ||
bFirst = 2; | ||
} | ||
// Compare versions | ||
for (let i = 0; i < 3; ++i) { | ||
const av = a.dots[i]; | ||
const bv = b.dots[i]; | ||
if (av === bv || | ||
av === internals.any || // Wildcard is equal to everything | ||
bv === internals.any) { | ||
continue; | ||
} | ||
return av - bv < 0 ? aFirst : bFirst; | ||
} | ||
// Compare prerelease | ||
if (!a.prerelease.length && | ||
!b.prerelease.length) { | ||
return 0; | ||
} | ||
if (!!a.prerelease.length !== !!b.prerelease.length) { | ||
return (a.prerelease.length ? aFirst : bFirst); // prerelease < none | ||
} | ||
for (let i = 0; ; ++i) { | ||
const ai = a.prerelease[i]; | ||
const bi = b.prerelease[i]; | ||
if (ai === undefined && | ||
bi === undefined) { | ||
return 0; | ||
} | ||
if (ai === bi) { | ||
continue; | ||
} | ||
if (ai === undefined) { | ||
return aFirst; | ||
} | ||
if (bi === undefined) { | ||
return bFirst; | ||
} | ||
const an = Number.isFinite(ai); | ||
const bn = Number.isFinite(bi); | ||
if (an !== bn) { | ||
return an ? aFirst : bFirst; | ||
} | ||
return (a < b ? aFirst : bFirst); | ||
} | ||
}; | ||
internals.Version = class { | ||
@@ -152,77 +232,3 @@ | ||
let aFirst = -1; | ||
let bFirst = 1; | ||
a = exports.version(a, options); | ||
b = exports.version(b, options); | ||
// Mark incompatible prereleases | ||
if (options.range && | ||
a.prerelease.length && | ||
(a.major !== b.major || a.minor !== b.minor || a.patch !== b.patch || !b.prerelease.length)) { | ||
aFirst = -2; | ||
bFirst = 2; | ||
} | ||
// Compare versions | ||
for (let i = 0; i < 3; ++i) { | ||
const av = a.dots[i]; | ||
const bv = b.dots[i]; | ||
if (av === bv || | ||
av === internals.any || // Wildcard is equal to everything | ||
bv === internals.any) { | ||
continue; | ||
} | ||
return av - bv < 0 ? aFirst : bFirst; | ||
} | ||
// Compare prerelease | ||
if (!a.prerelease.length && | ||
!b.prerelease.length) { | ||
return 0; | ||
} | ||
if (!!a.prerelease.length !== !!b.prerelease.length) { | ||
return (a.prerelease.length ? aFirst : bFirst); // prerelease < none | ||
} | ||
for (let i = 0; ; ++i) { | ||
const ai = a.prerelease[i]; | ||
const bi = b.prerelease[i]; | ||
if (ai === undefined && | ||
bi === undefined) { | ||
return 0; | ||
} | ||
if (ai === bi) { | ||
continue; | ||
} | ||
if (ai === undefined) { | ||
return aFirst; | ||
} | ||
if (bi === undefined) { | ||
return bFirst; | ||
} | ||
const an = Number.isFinite(ai); | ||
const bn = Number.isFinite(bi); | ||
if (an !== bn) { | ||
return an ? aFirst : bFirst; | ||
} | ||
return (a < b ? aFirst : bFirst); | ||
} | ||
return exports.compare(a, b, options); | ||
} | ||
@@ -229,0 +235,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
Copyright (c) 2018-2019, Sideway Inc, and project contributors | ||
Copyright (c) 2018-2020, Sideway Inc, and project contributors | ||
All rights reserved. | ||
@@ -3,0 +3,0 @@ |
{ | ||
"name": "@hapi/somever", | ||
"description": "Semantic versioning rules parser", | ||
"version": "2.1.1", | ||
"version": "3.0.0", | ||
"repository": "git://github.com/hapijs/somever", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib" | ||
], | ||
"keywords": [ | ||
@@ -13,8 +16,8 @@ "semantic", | ||
"dependencies": { | ||
"@hapi/bounce": "1.x.x", | ||
"@hapi/hoek": "8.x.x" | ||
"@hapi/bounce": "2.x.x", | ||
"@hapi/hoek": "9.x.x" | ||
}, | ||
"devDependencies": { | ||
"@hapi/code": "6.x.x", | ||
"@hapi/lab": "20.x.x" | ||
"@hapi/code": "8.x.x", | ||
"@hapi/lab": "22.x.x" | ||
}, | ||
@@ -21,0 +24,0 @@ "scripts": { |
<a href="http://hapijs.com"><img src="https://raw.githubusercontent.com/hapijs/assets/master/images/family.png" width="180px" align="right" /></a> | ||
# somever | ||
# @hapi/somever | ||
@@ -10,3 +10,2 @@ Semantic versioning rules parser, compatible with version ranges used in package.json files and the | ||
[![Build Status](https://secure.travis-ci.org/hapijs/somever.svg?branch=master)](https://travis-ci.org/hapijs/somever) | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
0
16496
4
379
11
+ Added@hapi/boom@9.1.4(transitive)
+ Added@hapi/bounce@2.0.0(transitive)
+ Added@hapi/hoek@9.3.0(transitive)
- Removed@hapi/boom@7.4.11(transitive)
- Removed@hapi/bounce@1.3.2(transitive)
- Removed@hapi/hoek@8.5.1(transitive)
Updated@hapi/bounce@2.x.x
Updated@hapi/hoek@9.x.x