Skip to content

Commit ce202a3

Browse files
ABeviermxcl
authored andcommitted
add semver.isValid function
1 parent b6460d2 commit ce202a3

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/utils/semver.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ Deno.test("semver", async test => {
3434
assertEquals(semver.parse("1")?.toString(), "1.0.0")
3535
})
3636

37+
await test.step("isValidSemVer", () => {
38+
assert(semver.isValid("1.2.3.4.5"))
39+
assert(semver.isValid("1a"))
40+
assert(semver.isValid("20.4"))
41+
assert(semver.isValid("2023.05.10"))
42+
assertFalse(semver.isValid("a"))
43+
assertFalse(semver.isValid("!#!@#!@#"))
44+
})
45+
3746
await test.step("satisfies", () => {
3847
assertEquals(new semver.Range("=3.1.0").max([new SemVer("3.1.0")]), new SemVer("3.1.0"))
3948
})

src/utils/semver.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ export function parse(input: string) {
115115
}
116116
}
117117

118+
/// determines if the input is in fact a valid semantic version
119+
export function isValid(input: string) {
120+
return parse(input) !== undefined
121+
}
122+
118123
/// we don’t support as much as node-semver but we refuse to do so because it is badness
119124
export class Range {
120125
// contract [0, 1] where 0 != 1 and 0 < 1

0 commit comments

Comments
 (0)