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

Function parsePackageName

lib/internal/modules/package_map.js:203–223  ·  view source on GitHub ↗

* Parse a package specifier into name and subpath. * @param {string} specifier * @returns {{packageName: string, subpath: string}}

(specifier)

Source from the content-addressed store, hash-verified

201 * @returns {{packageName: string, subpath: string}}
202 */
203function parsePackageName(specifier) {
204 const isScoped = specifier[0] === '@';
205 let slashIndex = StringPrototypeIndexOf(specifier, '/');
206
207 if (isScoped) {
208 if (slashIndex === -1) {
209 // Invalid: @scope without package name, treat whole thing as name
210 return { packageName: specifier, subpath: '.' };
211 }
212 slashIndex = StringPrototypeIndexOf(specifier, '/', slashIndex + 1);
213 }
214
215 if (slashIndex === -1) {
216 return { packageName: specifier, subpath: '.' };
217 }
218
219 return {
220 packageName: StringPrototypeSlice(specifier, 0, slashIndex),
221 subpath: '.' + StringPrototypeSlice(specifier, slashIndex),
222 };
223}
224
225/**
226 * Load and parse the package map from a config path.

Callers 1

resolveMethod · 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…