MCPcopy Index your code
hub / github.com/nodejs/node / patternKeyCompare

Function patternKeyCompare

lib/internal/modules/esm/resolve.js:673–685  ·  view source on GitHub ↗

* Compares two strings that may contain a wildcard character ('*') and returns a value indicating their order. * @param {string} a - The first string to compare. * @param {string} b - The second string to compare. * @returns {number} - A negative number if `a` should come before `b`, a positive n

(a, b)

Source from the content-addressed store, hash-verified

671 * or 0 if they are equal.
672 */
673function patternKeyCompare(a, b) {
674 const aPatternIndex = StringPrototypeIndexOf(a, '*');
675 const bPatternIndex = StringPrototypeIndexOf(b, '*');
676 const baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
677 const baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
678 if (baseLenA > baseLenB) { return -1; }
679 if (baseLenB > baseLenA) { return 1; }
680 if (aPatternIndex === -1) { return 1; }
681 if (bPatternIndex === -1) { return -1; }
682 if (a.length > b.length) { return -1; }
683 if (b.length > a.length) { return 1; }
684 return 0;
685}
686
687/**
688 * Resolves the given import name for a package.

Callers 2

packageExportsResolveFunction · 0.85
packageImportsResolveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…