From 63858958c8dc56c48c8c38fa7005a766ac21c9fa Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Fri, 22 Nov 2024 05:30:16 +0000 Subject: [PATCH] feat: `Semver.new` for construction Includes a `Semver.new` method, which constructs a `SemverImpl` from a `Version`, by setting its metatable. --- lib/init.luau | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/init.luau b/lib/init.luau index 3c55f02..6cc1576 100644 --- a/lib/init.luau +++ b/lib/init.luau @@ -170,6 +170,19 @@ local PRERELEASE_LEX_ORDER: { [PreleaseType]: number } = table.freeze({ rc = 3, }) +--[=[ + @within Semver + @function new + + Creates a new Semver instance from a [Version] + + @param ver Version -- The version to create a Semver instance from + @return SemverImpl -- The new Semver instance +]=] +function Semver.new(ver: Version): SemverImpl + return setmetatable(ver, Semver) +end + --[=[ @within Semver @function parse @@ -344,7 +357,7 @@ function Semver.parse(ver: string): SemverResult end end - return Result.Ok(setmetatable(parsed :: Version, Semver)) + return Result.Ok(Semver.new(parsed)) end local function prereleaseEq(leftPrerelease: PrereleaseVersion?, rightPrerelease: PrereleaseVersion?): boolean