11cb0ef41Sopenharmony_ciconst SemVer = require('../classes/semver') 21cb0ef41Sopenharmony_ciconst Comparator = require('../classes/comparator') 31cb0ef41Sopenharmony_ciconst { ANY } = Comparator 41cb0ef41Sopenharmony_ciconst Range = require('../classes/range') 51cb0ef41Sopenharmony_ciconst satisfies = require('../functions/satisfies') 61cb0ef41Sopenharmony_ciconst gt = require('../functions/gt') 71cb0ef41Sopenharmony_ciconst lt = require('../functions/lt') 81cb0ef41Sopenharmony_ciconst lte = require('../functions/lte') 91cb0ef41Sopenharmony_ciconst gte = require('../functions/gte') 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst outside = (version, range, hilo, options) => { 121cb0ef41Sopenharmony_ci version = new SemVer(version, options) 131cb0ef41Sopenharmony_ci range = new Range(range, options) 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci let gtfn, ltefn, ltfn, comp, ecomp 161cb0ef41Sopenharmony_ci switch (hilo) { 171cb0ef41Sopenharmony_ci case '>': 181cb0ef41Sopenharmony_ci gtfn = gt 191cb0ef41Sopenharmony_ci ltefn = lte 201cb0ef41Sopenharmony_ci ltfn = lt 211cb0ef41Sopenharmony_ci comp = '>' 221cb0ef41Sopenharmony_ci ecomp = '>=' 231cb0ef41Sopenharmony_ci break 241cb0ef41Sopenharmony_ci case '<': 251cb0ef41Sopenharmony_ci gtfn = lt 261cb0ef41Sopenharmony_ci ltefn = gte 271cb0ef41Sopenharmony_ci ltfn = gt 281cb0ef41Sopenharmony_ci comp = '<' 291cb0ef41Sopenharmony_ci ecomp = '<=' 301cb0ef41Sopenharmony_ci break 311cb0ef41Sopenharmony_ci default: 321cb0ef41Sopenharmony_ci throw new TypeError('Must provide a hilo val of "<" or ">"') 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci // If it satisfies the range it is not outside 361cb0ef41Sopenharmony_ci if (satisfies(version, range, options)) { 371cb0ef41Sopenharmony_ci return false 381cb0ef41Sopenharmony_ci } 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci // From now on, variable terms are as if we're in "gtr" mode. 411cb0ef41Sopenharmony_ci // but note that everything is flipped for the "ltr" function. 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci for (let i = 0; i < range.set.length; ++i) { 441cb0ef41Sopenharmony_ci const comparators = range.set[i] 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci let high = null 471cb0ef41Sopenharmony_ci let low = null 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci comparators.forEach((comparator) => { 501cb0ef41Sopenharmony_ci if (comparator.semver === ANY) { 511cb0ef41Sopenharmony_ci comparator = new Comparator('>=0.0.0') 521cb0ef41Sopenharmony_ci } 531cb0ef41Sopenharmony_ci high = high || comparator 541cb0ef41Sopenharmony_ci low = low || comparator 551cb0ef41Sopenharmony_ci if (gtfn(comparator.semver, high.semver, options)) { 561cb0ef41Sopenharmony_ci high = comparator 571cb0ef41Sopenharmony_ci } else if (ltfn(comparator.semver, low.semver, options)) { 581cb0ef41Sopenharmony_ci low = comparator 591cb0ef41Sopenharmony_ci } 601cb0ef41Sopenharmony_ci }) 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci // If the edge version comparator has a operator then our version 631cb0ef41Sopenharmony_ci // isn't outside it 641cb0ef41Sopenharmony_ci if (high.operator === comp || high.operator === ecomp) { 651cb0ef41Sopenharmony_ci return false 661cb0ef41Sopenharmony_ci } 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci // If the lowest version comparator has an operator and our version 691cb0ef41Sopenharmony_ci // is less than it then it isn't higher than the range 701cb0ef41Sopenharmony_ci if ((!low.operator || low.operator === comp) && 711cb0ef41Sopenharmony_ci ltefn(version, low.semver)) { 721cb0ef41Sopenharmony_ci return false 731cb0ef41Sopenharmony_ci } else if (low.operator === ecomp && ltfn(version, low.semver)) { 741cb0ef41Sopenharmony_ci return false 751cb0ef41Sopenharmony_ci } 761cb0ef41Sopenharmony_ci } 771cb0ef41Sopenharmony_ci return true 781cb0ef41Sopenharmony_ci} 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_cimodule.exports = outside 81