File tree Expand file tree Collapse file tree 2 files changed +19
-12
lines changed
Expand file tree Collapse file tree 2 files changed +19
-12
lines changed Original file line number Diff line number Diff line change 11<script setup lang="ts">
22import { SEVERITY_TEXT_COLORS , getHighestSeverity } from ' #shared/utils/severity'
33import { getOutdatedTooltip , getVersionClass } from ' ~/utils/npm/outdated-dependencies'
4+ import { parseNpmAlias } from ' ~/utils/npm/alias'
45
56const { t } = useI18n ()
67
@@ -91,18 +92,6 @@ function getDepVersionClass(dep: string) {
9192
9293const numberFormatter = useNumberFormatter ()
9394
94- /**
95- * Parses npm alias syntax: "npm:real-pkg@^1.0.0"
96- * Returns { name, range } for the real package, or null if not an alias.
97- */
98- function parseNpmAlias(version : string ): { name: string ; range: string } | null {
99- if (! version .startsWith (' npm:' )) return null
100- const spec = version .slice (4 ) // strip 'npm:'
101- // Handle scoped packages like @scope/pkg@1.0.0 — find @ after position 0
102- const atIdx = spec .startsWith (' @' ) ? spec .indexOf (' @' , 1 ) : spec .indexOf (' @' )
103- if (atIdx === - 1 ) return { name: spec , range: ' ' }
104- return { name: spec .slice (0 , atIdx ), range: spec .slice (atIdx + 1 ) }
105- }
10695 </script >
10796
10897<template >
Original file line number Diff line number Diff line change 1+ /**
2+ * Parses npm alias syntax: "npm:real-pkg@^1.0.0"
3+ * Returns { name, range } for the real package, or null if not an alias.
4+ *
5+ * @example
6+ * parseNpmAlias('npm:real-pkg@^1.0.0') // { name: 'real-pkg', range: '^1.0.0' }
7+ * parseNpmAlias('npm:@scope/pkg@^1.0.0') // { name: '@scope /pkg', range: '^1.0.0' }
8+ * parseNpmAlias('npm:real-pkg') // { name: 'real-pkg', range: '' }
9+ * parseNpmAlias('^1.0.0') // null
10+ */
11+ export function parseNpmAlias ( version : string ) : { name : string ; range : string } | null {
12+ if ( ! version . startsWith ( 'npm:' ) ) return null
13+ const spec = version . slice ( 4 ) // strip 'npm:'
14+ // Handle scoped packages like @scope /pkg@1.0.0 — find @ after position 0
15+ const atIdx = spec . startsWith ( '@' ) ? spec . indexOf ( '@' , 1 ) : spec . indexOf ( '@' )
16+ if ( atIdx === - 1 ) return { name : spec , range : '' }
17+ return { name : spec . slice ( 0 , atIdx ) , range : spec . slice ( atIdx + 1 ) }
18+ }
You can’t perform that action at this time.
0 commit comments