@snyk/ruby-semver
Advanced tools
Comparing version 1.0.0 to 1.1.0
const api = {}; | ||
Object.assign(api, require('./lib/comparison')); | ||
Object.assign(api, require('./lib/ranges')); | ||
Object.assign(api, require('./lib/functions')); | ||
module.exports = api; | ||
module.exports = Object.assign(api, | ||
require('./lib/comparison'), | ||
require('./lib/ranges'), | ||
require('./lib/functions')); |
@@ -18,2 +18,15 @@ const { GemVersion, GemRequirement } = require('./generated'); | ||
function _expandTildes(gemRequirement) { | ||
const requirements = []; | ||
gemRequirement.$requirements().forEach(([op, version]) => { | ||
if (op.indexOf('~') !== -1) { | ||
requirements.push(`>= ${version}`); | ||
requirements.push(`< ${version.$bump()}`); | ||
} else { | ||
requirements.push(`${op} ${version}`); | ||
} | ||
}); | ||
return GemRequirement.$create(requirements); | ||
} | ||
function validRange(range) { | ||
@@ -24,3 +37,7 @@ if (range === null || range === undefined) { return null; } | ||
try { | ||
return _createRequirement(range).$to_s(); | ||
let requirement = _createRequirement(range); | ||
if (range.indexOf('~') !== -1) { | ||
requirement = _expandTildes(requirement); | ||
} | ||
return requirement.$to_s(); | ||
} catch (err) { | ||
@@ -27,0 +44,0 @@ return null; |
@@ -19,3 +19,3 @@ { | ||
}, | ||
"version": "1.0.0" | ||
"version": "1.1.0" | ||
} |
@@ -9,3 +9,6 @@ import test from 'ava'; | ||
t.is(validRange('1.1'), '= 1.1'); | ||
t.is(validRange('~> 1.1.0'), '~> 1.1.0'); | ||
t.is(validRange('~> 1.1'), '< 2, >= 1.1'); | ||
t.is(validRange('~> 1.1.0'), '< 1.2, >= 1.1.0'); | ||
t.is(validRange('~> 1.1.1.0'), '< 1.1.2, >= 1.1.1.0'); | ||
t.is(validRange('~> 1.1.1.beta.1'), '< 1.2, >= 1.1.1.beta.1'); | ||
t.is(validRange('> 2.1, < 2.4'), '< 2.4, > 2.1'); | ||
@@ -12,0 +15,0 @@ |
715134
16302