Compare Semantic Versions in Larzscript
Parse major.minor.patch versions, compare them correctly (1.2.0 < 1.10.0, not a naive string compare), and check a version against a real range constraint.
semver.satisfies() understands >=/<=/>/</^/~ ranges and x-ranges, and max_satisfying() picks the highest matching version from a list - the same constraint logic a package manager needs.
larzscript pkg install semver
Code
import "semver" as semver
print(semver.compare("1.2.0", "1.10.0"))
print(semver.gt("2.0.0", "1.9.9"))
print(semver.satisfies("1.5.0", "^1.0.0"))
print(semver.max_satisfying(["1.0.0", "1.5.0", "2.0.0"], "^1.0.0"))Output
-1 true true 1.5.0
Related
larzsemverSemantic version parse, compare, and range satisfaction (>=, ^, ~, x-ranges)→Retry with Exponential Backoff in LarzscriptRetry a flaky call a few times, waiting longer between each attempt, instead of failing on the first hiccup or hammering a struggling service.→Memoize a Function in LarzscriptCache a function's results so calling it twice with the same input only does the real work once.→Implement a State Machine in LarzscriptDeclare states and transitions, fire events, and let the machine reject anything that isn't a legal move - a document workflow (draft -> review -> published) in a few lines.→