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

Function findLongestRegisteredExtension

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

* Find the longest (possibly multi-dot) extension registered in `Module._extensions`. * @param {string} filename The filename to find the longest registered extension for. * @returns {string}

(filename)

Source from the content-addressed store, hash-verified

621 * @returns {string}
622 */
623function findLongestRegisteredExtension(filename) {
624 const name = path.basename(filename);
625 let currentExtension;
626 let index;
627 let startIndex = 0;
628 while ((index = StringPrototypeIndexOf(name, '.', startIndex)) !== -1) {
629 startIndex = index + 1;
630 if (index === 0) { continue; } // Skip dotfiles like .gitignore
631 currentExtension = StringPrototypeSlice(name, index);
632 if (Module._extensions[currentExtension]) { return currentExtension; }
633 }
634 return '.js';
635}
636
637/**
638 * Tries to get the absolute file path of the parent module.

Callers 2

cjsPreparseModuleExportsFunction · 0.85
loader.jsFile · 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…