MCPcopy
hub / github.com/npm/node-semver / intersects

Method intersects

classes/comparator.js:79–133  ·  view source on GitHub ↗
(comp, options)

Source from the content-addressed store, hash-verified

77 }
78
79 intersects (comp, options) {
80 if (!(comp instanceof Comparator)) {
81 throw new TypeError('a Comparator is required')
82 }
83
84 if (this.operator === '') {
85 if (this.value === '') {
86 return true
87 }
88 return new Range(comp.value, options).test(this.value)
89 } else if (comp.operator === '') {
90 if (comp.value === '') {
91 return true
92 }
93 return new Range(this.value, options).test(comp.semver)
94 }
95
96 options = parseOptions(options)
97
98 // Special cases where nothing can possibly be lower
99 if (options.includePrerelease &&
100 (this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
101 return false
102 }
103 if (!options.includePrerelease &&
104 (this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
105 return false
106 }
107
108 // Same direction increasing (> or >=)
109 if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
110 return true
111 }
112 // Same direction decreasing (< or <=)
113 if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
114 return true
115 }
116 // same SemVer and both sides are inclusive (<= or >=)
117 if (
118 (this.semver.version === comp.semver.version) &&
119 this.operator.includes('=') && comp.operator.includes('=')) {
120 return true
121 }
122 // opposite directions less than
123 if (cmp(this.semver, '<', comp.semver, options) &&
124 this.operator.startsWith('>') && comp.operator.startsWith('<')) {
125 return true
126 }
127 // opposite directions greater than
128 if (cmp(this.semver, '>', comp.semver, options) &&
129 this.operator.startsWith('<') && comp.operator.startsWith('>')) {
130 return true
131 }
132 return false
133 }
134}
135
136module.exports = Comparator

Callers

nothing calls this directly

Calls 3

parseOptionsFunction · 0.85
cmpFunction · 0.85
testMethod · 0.45

Tested by

no test coverage detected