MCPcopy
hub / github.com/webpack/webpack / parseRange

Function parseRange

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

Source from the content-addressed store, hash-verified

266 * @returns {SemVerRange}
267 */
268 const parseRange = (str) => {
269 // range ::= hyphen | simple ( ' ' ( ' ' ) * simple ) * | ''
270 // hyphen ::= partial ( ' ' ) * ' - ' ( ' ' ) * partial
271 const items = str.split(/\s+-\s+/);
272
273 if (items.length === 1) {
274 str = str.trim();
275
276 /** @type {SemVerRangeItem[][]} */
277 const items = [];
278 const r = /[-0-9A-Za-z]\s+/g;
279 var start = 0;
280 /** @type {RegExpExecArray | null} */
281 var match;
282 while ((match = r.exec(str))) {
283 const end = match.index + 1;
284 items.push(
285 /** @type {SemVerRangeItem[]} */
286 (parseSimple(str.slice(start, end).trim()))
287 );
288 start = end;
289 }
290 items.push(
291 /** @type {SemVerRangeItem[]} */
292 (parseSimple(str.slice(start).trim()))
293 );
294 return combine(items, 2);
295 }
296
297 const a = parsePartial(items[0]);
298 const b = parsePartial(items[1]);
299 // >=a <=b => and( >=a, or( <b, =b ) ) => >=a, <b, =b, or, and
300 // eslint-disable-next-line no-sparse-arrays
301 return [, toFixed(b), negate(b), 1, a, 2];
302 };
303
304 /**
305 * Returns the sem ver range.

Callers 3

applyMethod · 0.85
SemVer.unittest.jsFile · 0.85

Calls 9

parseSimpleFunction · 0.85
parsePartialFunction · 0.85
toFixedFunction · 0.85
negateFunction · 0.85
splitMethod · 0.80
execMethod · 0.80
sliceMethod · 0.80
combineFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected