MCPcopy Create free account
hub / github.com/Effect-TS/effect / getPackageExportMatch

Function getPackageExportMatch

packages/tools/jsdocs/src/Jsdocs.ts:658–693  ·  view source on GitHub ↗
(exports: unknown, subpath: string)

Source from the content-addressed store, hash-verified

656}
657
658function getPackageExportMatch(exports: unknown, subpath: string): PackageExportMatch | undefined {
659 if (!isRecord(exports)) {
660 return subpath === "." ? { key: ".", value: exports, star: null, specificity: 1, prefixLength: 1 } : undefined
661 }
662 if (Object.hasOwn(exports, subpath)) {
663 return {
664 key: subpath,
665 value: exports[subpath],
666 star: null,
667 specificity: Number.MAX_SAFE_INTEGER,
668 prefixLength: subpath.length
669 }
670 }
671 const matches: Array<PackageExportMatch> = []
672 for (const [key, value] of Object.entries(exports)) {
673 const starIndex = key.indexOf("*")
674 if (!key.startsWith(".") || starIndex === -1) {
675 continue
676 }
677 const prefix = key.slice(0, starIndex)
678 const suffix = key.slice(starIndex + 1)
679 if (!subpath.startsWith(prefix) || !subpath.endsWith(suffix)) {
680 continue
681 }
682 matches.push({
683 key,
684 value,
685 star: subpath.slice(prefix.length, subpath.length - suffix.length),
686 specificity: prefix.length + suffix.length,
687 prefixLength: prefix.length
688 })
689 }
690 return matches.sort((a, b) =>
691 b.specificity - a.specificity || b.prefixLength - a.prefixLength || b.key.length - a.key.length
692 )[0]
693}
694
695function packageExportTargetMatches(value: unknown, star: string | null, expectedTarget: string): boolean {
696 if (typeof value === "string") {

Callers 1

isPackageSubpathExportedFunction · 0.85

Calls 2

pushMethod · 0.80
isRecordFunction · 0.70

Tested by

no test coverage detected