MCPcopy
hub / github.com/markmap/markmap / addDefaultVersions

Function addDefaultVersions

packages/markmap-lib/src/plugins/util.ts:4–23  ·  view source on GitHub ↗
(
  paths: string[],
  name: string,
  version: string,
)

Source from the content-addressed store, hash-verified

2 * Find NPM paths and resolve them to full URLs with the same package version as in this library.
3 */
4export function addDefaultVersions(
5 paths: string[],
6 name: string,
7 version: string,
8) {
9 return paths.map((path) => {
10 if (typeof path === 'string' && !path.includes('://')) {
11 if (!path.startsWith('npm:')) {
12 path = `npm:${path}`;
13 }
14 const prefixLength = 4 + name.length;
15 if (path.startsWith(`npm:${name}/`)) {
16 path = `${path.slice(0, prefixLength)}@${version}${path.slice(
17 prefixLength,
18 )}`;
19 }
20 }
21 return path;
22 });
23}

Callers 1

transformFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected