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

Function simpleSubset

ranges/subset.js:76–223  ·  view source on GitHub ↗
(sub, dom, options)

Source from the content-addressed store, hash-verified

74const minimumVersion = [new Comparator('>=0.0.0')]
75
76const simpleSubset = (sub, dom, options) => {
77 if (sub === dom) {
78 return true
79 }
80
81 if (sub.length === 1 && sub[0].semver === ANY) {
82 if (dom.length === 1 && dom[0].semver === ANY) {
83 return true
84 } else if (options.includePrerelease) {
85 sub = minimumVersionWithPreRelease
86 } else {
87 sub = minimumVersion
88 }
89 }
90
91 if (dom.length === 1 && dom[0].semver === ANY) {
92 if (options.includePrerelease) {
93 return true
94 } else {
95 dom = minimumVersion
96 }
97 }
98
99 const eqSet = new Set()
100 let gt, lt
101 for (const c of sub) {
102 if (c.operator === '>' || c.operator === '>=') {
103 gt = higherGT(gt, c, options)
104 } else if (c.operator === '<' || c.operator === '<=') {
105 lt = lowerLT(lt, c, options)
106 } else {
107 eqSet.add(c.semver)
108 }
109 }
110
111 if (eqSet.size > 1) {
112 return null
113 }
114
115 let gtltComp
116 if (gt && lt) {
117 gtltComp = compare(gt.semver, lt.semver, options)
118 if (gtltComp > 0) {
119 return null
120 } else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) {
121 return null
122 }
123 }
124
125 // will iterate one or zero times
126 for (const eq of eqSet) {
127 if (gt && !satisfies(eq, String(gt), options)) {
128 return null
129 }
130
131 if (lt && !satisfies(eq, String(lt), options)) {
132 return null
133 }

Callers 1

subsetFunction · 0.85

Calls 5

higherGTFunction · 0.85
lowerLTFunction · 0.85
compareFunction · 0.85
satisfiesFunction · 0.85
testMethod · 0.45

Tested by

no test coverage detected