MCPcopy
hub / github.com/webpack/webpack / parseSimple

Function parseSimple

lib/util/semver.js:187–239  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

185 * @returns {SemVerRange}
186 */
187 const parseSimple = (str) => {
188 // simple ::= primitive | partial | tilde | caret
189 // primitive ::= ( '<' | '>' | '>=' | '<=' | '=' | '!' ) ( ' ' ) * partial
190 // tilde ::= '~' ( ' ' ) * partial
191 // caret ::= '^' ( ' ' ) * partial
192 const match = /^(\^|~|<=|<|>=|>|=|v|!)/.exec(str);
193 const start = match ? match[0] : "";
194 const remainder = parsePartial(
195 start.length ? str.slice(start.length).trim() : str.trim()
196 );
197
198 switch (start) {
199 case "^":
200 if (remainder.length > 1 && remainder[1] === 0) {
201 if (remainder.length > 2 && remainder[2] === 0) {
202 return [3, ...remainder.slice(1)];
203 }
204 return [2, ...remainder.slice(1)];
205 }
206 return [1, ...remainder.slice(1)];
207 case "~":
208 if (remainder.length === 2 && remainder[0] === 0) {
209 return [1, ...remainder.slice(1)];
210 }
211 return [2, ...remainder.slice(1)];
212 case ">=":
213 return remainder;
214 case "=":
215 case "v":
216 case "":
217 return toFixed(remainder);
218 case "<":
219 return negate(remainder);
220 case ">": {
221 // and( >=, not( = ) ) => >=, =, not, and
222 const fixed = toFixed(remainder);
223 // eslint-disable-next-line no-sparse-arrays
224 return [, fixed, 0, remainder, 2];
225 }
226 case "<=":
227 // or( <, = ) => <, =, or
228 // eslint-disable-next-line no-sparse-arrays
229 return [, toFixed(remainder), negate(remainder), 1];
230 case "!": {
231 // not =
232 const fixed = toFixed(remainder);
233 // eslint-disable-next-line no-sparse-arrays
234 return [, fixed, 0];
235 }
236 default:
237 throw new Error("Unexpected start value");
238 }
239 };
240
241 /**
242 * Returns result.

Callers 1

parseRangeFunction · 0.85

Calls 5

parsePartialFunction · 0.85
toFixedFunction · 0.85
negateFunction · 0.85
execMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected