feat: Semver.new for construction

Includes a `Semver.new` method, which constructs a `SemverImpl` from a
`Version`, by setting its metatable.
This commit is contained in:
Erica Marigold 2024-11-22 05:30:16 +00:00
parent 2f0fa8e5c4
commit 63858958c8
Signed by: DevComp
GPG key ID: 429EF1C337871656

View file

@ -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<SemverImpl>
end
end
return Result.Ok(setmetatable(parsed :: Version, Semver))
return Result.Ok(Semver.new(parsed))
end
local function prereleaseEq(leftPrerelease: PrereleaseVersion?, rightPrerelease: PrereleaseVersion?): boolean