semver-luau/README.md

69 lines
5.8 KiB
Markdown
Raw Normal View History

2024-11-10 15:14:18 +00:00
# semver-luau
<a href="https://discord.gg/ATVVsNNv3u"><img alt="Discord" src="https://img.shields.io/discord/385151591524597761?style=plastic&logo=discord&color=%235865F2" /></a>
<a href="https://pesde.daimond113.com/packages/0x5eal/semver"><img alt="Pesde" src="https://img.shields.io/badge/pesde-0x5eal/semver-F19D1E?&style=plastic&logo=data:image/svg%2bxml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00OS42MDI1IDBMOTIuOTAzOCAyNVY3NUw0OS42MDI1IDEwMEw2LjMwMTI3IDc1VjI1TDQ5LjYwMjUgMFpNMTQuMzAxMyAyOS42MTg4TDQ5LjYwMjUgOS4yMzc2TDg0LjkwMzggMjkuNjE4OFY3MC4zODEyTDQ5LjYwMjUgOTAuNzYyNEwzMy42MTQ4IDgxLjUzMTlWNjcuMzg0OEMzNC41MTY3IDY4LjUwNzEgMzUuNjM4OCA2OS40MjE1IDM2Ljk4MSA3MC4xMjc5QzM4Ljk3MDEgNzEuMTQ4IDQxLjAzNTcgNzEuNjU4IDQzLjE3NzkgNzEuNjU4QzQ2LjQ0MiA3MS42NTggNDkuMTQ1MiA3MC44OTI5IDUxLjI4NzMgNjkuMzYyOUM1My40ODA1IDY3Ljc4MTggNTUuMTEyNiA2NS43NjcyIDU2LjE4MzYgNjMuMzE5QzU3LjA5MTUgNjEuMzM4MiA1Ny42MzIgNTkuMjc0IDU3LjgwNTQgNTcuMTI2M0M1OS44NzIzIDU3Ljc0NTcgNjIuMjE1NyA1OC4wNTU0IDY0LjgzNTYgNTguMDU1NEM2Ny42OTE4IDU4LjA1NTQgNzAuMzY5NSA1Ny42NDczIDcyL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xMiA2MC45MjE5IDUwLjI5MjggNTguNjAxMiA1MC4yOTI4IDU1LjU5MjFDNTAuMjkyOCA1NC4wNjc5IDUwLjA3NjkgNTIuNzI3IDQ5LjY0NTEgNTEuNTY5MloiIGZpbGw9IiNGRkZGRkYiPjwvcGF0aD4KPC9zdmc+" /></a>
<a href="https://lune-org.github.io/docs"><img alt="Lune" src="https://github.com/0x5eal/semver-luau/blob/main/.lune/assets/powered-by-lune.svg" /></a>
2024-11-10 15:14:18 +00:00
2024-11-10 15:14:18 +00:00
A Luau library to parse and compare [Semantic Versioning] compatible version numbers.
Semantic Versioning (Semver) is a versioning scheme for software that uses a three-part version number format, `MAJOR.MINOR.PATCH`.
Additionally, Semver defines rules on when to increment each of these parts:
- `MAJOR` version increments indicate incompatible API changes.
- `MINOR` version increments indicate the addition of functionality in a backward-compatible manner.
- `PATCH` version increments indicate backward-compatible bug fixes.
Semver also allows for optional pre-release and build metadata tags.
For a detailed set of guidelines that Semver version numbers follow, visit the previously linked website containing the full
Semver specification.
## Usage
To improve error / nil handling ergnomics, this library makes use of [util.luau]'s [`Option`] and [`Result`] implementations.
Any fallible methods return a [`Result`] and potentially null values are represented as [`Option`]s.
Invalid versions should return a [`Result`] with the respective error. If not, this is considered a bug, and please consider
filing an issue [here](https://github.com/0x5eal/semver-luau/issues).
```luau
local semver = require("semver")
-- Parse version strings
local v1 = semver.parse("1.2.3"):unwrap() --[[
major = 1,
minor = 2,
patch = 3,
buildMetadata = Option::None,
prerelease = Option::None
]]
local v2 = semver.parse("5.12.0+build.1731248766"):unwrap() --[[
major = 5,
minor = 12,
patch = 0,
buildMetadata = Option::Some("build.1731248766"),
prerelease = Option::None
]]
-- Compare versions
print(v1 < v2) -- true
print(v1 > v2) -- false
print(v1 == v2) -- false
```
## MSLV (Minimum Supported Luau Version)
This library requires at least requires at least Luau [0.629](https://github.com/luau-lang/luau/releases/tag/0.629),
which corresponds to Lune [0.8.7](https://github.com/lune-org/lune/releases/tag/v0.8.7) (for leading `|` support).
## License
This project is licensed under the [MIT] license.
[Semantic Versioning]: https://semver.org
[util.luau]: https://github.com/lukadev-0/util.luau
[`Result`]: https://lukadev-0.github.io/util.luau/docs/error-handling
[`Option`]: https://lukadev-0.github.io/util.luau/docs/optional-values
[MIT]: https://compeydev.mit-license.org