MCPcopy Create free account
hub / github.com/TanStack/devtools / parseVersion

Function parseVersion

packages/devtools/src/tabs/semver-utils.ts:16–45  ·  view source on GitHub ↗
(version: string)

Source from the content-addressed store, hash-verified

14 * Parse a semver string into components
15 */
16export function parseVersion(version: string): ParsedVersion | null {
17 if (!version) return null
18
19 // Remove leading 'v', '^', '~', and any prerelease/build metadata
20 const cleanVersion = version
21 .replace(/^[v^~]/, '')
22 .split('-')[0]
23 ?.split('+')[0]
24
25 if (!cleanVersion) return null
26
27 const parts = cleanVersion.split('.')
28
29 if (parts.length < 2) return null
30
31 const major = parseInt(parts[0] ?? '0', 10)
32 const minor = parseInt(parts[1] ?? '0', 10)
33 const patch = parseInt(parts[2] ?? '0', 10)
34
35 if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
36 return null
37 }
38
39 return {
40 major,
41 minor,
42 patch,
43 raw: version,
44 }
45}
46
47/**
48 * Compare two versions

Callers 3

satisfiesMinVersionFunction · 0.85
satisfiesMaxVersionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected