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

Function extname

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

* Returns the file extension from a URL. Should give similar result to * `require('node:path').extname(require('node:url').fileURLToPath(url))` * when used with a `file:` URL. * @param {URL} url * @returns {string}

(url)

Source from the content-addressed store, hash-verified

115 * @returns {string}
116 */
117function extname(url) {
118 const { pathname } = url;
119 for (let i = pathname.length - 1; i > 0; i--) {
120 switch (StringPrototypeCharCodeAt(pathname, i)) {
121 case SLASH_CODE:
122 return '';
123
124 case DOT_CODE:
125 return StringPrototypeCharCodeAt(pathname, i - 1) === SLASH_CODE ? '' : StringPrototypeSlice(pathname, i);
126 }
127 }
128 return '';
129}
130
131/**
132 * Determine whether the given file URL is under a `node_modules` folder.

Callers 2

requireFnFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…