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

Function detectModuleFormat

lib/internal/modules/esm/get_format.js:87–92  ·  view source on GitHub ↗

* Determine whether the given ambiguous source contains CommonJS or ES module syntax. * @param {string | Buffer | undefined} [source] * @param {URL} url * @returns {'module'|'commonjs'}

(source, url)

Source from the content-addressed store, hash-verified

85 * @returns {'module'|'commonjs'}
86 */
87function detectModuleFormat(source, url) {
88 const detectModule = getOptionValue('--experimental-detect-module');
89 if (!source) { return detectModule ? null : 'commonjs'; }
90 if (!detectModule) { return 'commonjs'; }
91 return containsModuleSyntax(`${source}`, fileURLToPath(url), url) ? 'module' : 'commonjs';
92}
93
94/**
95 * @param {URL} parsed

Callers 1

Calls 2

getOptionValueFunction · 0.85
fileURLToPathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…