MCPcopy
hub / github.com/antfu-collective/taze / getVersionRangePrefix

Function getVersionRangePrefix

src/utils/versions.ts:4–28  ·  view source on GitHub ↗
(v: string)

Source from the content-addressed store, hash-verified

2import { gt, lte, minVersion, satisfies, validRange } from 'semver-es'
3
4export function getVersionRangePrefix(v: string) {
5 const leadings = ['>=', '<=', '>', '<', '~', '^']
6 const ver = v.trim()
7
8 if (ver === '*' || ver === '')
9 return '*'
10 if (ver[0] === '~' || ver[0] === '^')
11 return ver[0]
12 for (const leading of leadings) {
13 if (ver.startsWith(leading))
14 return leading
15 }
16 if (ver.includes('x')) {
17 const parts = ver.split('.')
18 if (parts[0] === 'x')
19 return '*'
20 if (parts[1] === 'x')
21 return '^'
22 if (parts[2] === 'x')
23 return '~'
24 }
25 if (+ver[0] < 10)
26 return ''
27 return null
28}
29
30export function changeVersionRange(version: string, mode: Exclude<RangeMode, 'latest' | 'newest' | 'stable' | 'next'>) {
31 if (!validRange(version))

Callers 2

versions.test.tsFile · 0.90
getPrefixedVersionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…