MCPcopy Create free account
hub / github.com/adobe/react-spectrum / unionSortKey

Function unionSortKey

packages/dev/s2-docs/scripts/generateMarkdownDocs.mjs:337–380  ·  view source on GitHub ↗
(part)

Source from the content-addressed store, hash-verified

335}
336
337function unionSortKey(part) {
338 const text = part.trim();
339 const primitiveOrder = new Map([
340 ['any', 0],
341 ['unknown', 1],
342 ['never', 2],
343 ['void', 3],
344 ['boolean', 4],
345 ['number', 5],
346 ['string', 6],
347 ['symbol', 7],
348 ['bigint', 8]
349 ]);
350
351 if (primitiveOrder.has(text)) {
352 return [0, primitiveOrder.get(text), ''];
353 }
354
355 if (/^-?\d+(?:\.\d+)?$/.test(text)) {
356 return [1, Number(text), ''];
357 }
358
359 const literal = stringLiteralValue(text);
360 if (literal != null) {
361 const booleanLiteralOrder = new Map([
362 ['true', 0],
363 ['false', 1]
364 ]);
365 if (booleanLiteralOrder.has(literal)) {
366 return [2, booleanLiteralOrder.get(literal), literal];
367 }
368 return [2, 2, literal.toLowerCase()];
369 }
370
371 if (text === 'null') {
372 return [8, 0, ''];
373 }
374
375 if (text === 'undefined') {
376 return [9, 0, ''];
377 }
378
379 return [3, 0, text.toLowerCase()];
380}
381
382function compareUnionParts(a, b) {
383 const aKey = unionSortKey(a);

Callers 1

compareUnionPartsFunction · 0.85

Calls 2

stringLiteralValueFunction · 0.85
hasMethod · 0.65

Tested by

no test coverage detected