feat: add module contracts and discovery
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { satisfies, valid, validRange } from "semver";
|
||||
import { z } from "zod";
|
||||
|
||||
export const semanticVersionSchema = z.string().refine((value) => valid(value) === value, {
|
||||
message: "Must be a strict semantic version.",
|
||||
});
|
||||
|
||||
export const semanticVersionRangeSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.refine((value) => validRange(value) !== null, {
|
||||
message: "Must be a valid semantic version range.",
|
||||
});
|
||||
|
||||
export function isVersionCompatible(version: string, range: string): boolean {
|
||||
return valid(version) === version && validRange(range) !== null && satisfies(version, range);
|
||||
}
|
||||
|
||||
export type SemanticVersion = z.infer<typeof semanticVersionSchema>;
|
||||
export type SemanticVersionRange = z.infer<typeof semanticVersionRangeSchema>;
|
||||
Reference in New Issue
Block a user