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

Function tryExtensions

lib/internal/modules/cjs/loader.js:607–616  ·  view source on GitHub ↗

* Given a path, check if the file exists with any of the set extensions. * @param {string} basePath The path and filename without extension * @param {string[]} exts The extensions to try * @param {boolean} isMain Whether the module is the main module * @returns {string|false}

(basePath, exts, isMain)

Source from the content-addressed store, hash-verified

605 * @returns {string|false}
606 */
607function tryExtensions(basePath, exts, isMain) {
608 for (let i = 0; i < exts.length; i++) {
609 const filename = tryFile(basePath + exts[i], isMain);
610
611 if (filename) {
612 return filename;
613 }
614 }
615 return false;
616}
617
618/**
619 * Find the longest (possibly multi-dot) extension registered in `Module._extensions`.

Callers 2

tryPackageFunction · 0.85
loader.jsFile · 0.85

Calls 1

tryFileFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…