semver.lua/README.md

108 lines
3.4 KiB
Markdown
Raw Normal View History

2015-09-27 18:08:45 +00:00
# semver.lua
2013-01-02 01:12:57 +00:00
2015-09-27 18:08:45 +00:00
[![Build Status](https://travis-ci.org/kikito/semver.lua.svg?branch=master)](https://travis-ci.org/kikito/semver.lua)
2012-01-13 23:08:47 +00:00
Semantic versioning for Lua.
See http://semver.org/ for details about semantic versioning.
2015-09-27 18:08:45 +00:00
# Documentation
2012-01-13 23:08:47 +00:00
2015-09-27 18:08:45 +00:00
``` lua
2012-01-14 02:38:04 +00:00
local v = require 'semver'
2012-01-13 23:08:47 +00:00
2012-01-15 13:15:43 +00:00
-- two ways of creating it: with separate parameters, or with one string
2012-01-14 02:38:04 +00:00
v1 = v(1,0,0)
v2_5_1 = v('2.5.1')
2012-01-13 23:08:47 +00:00
2012-01-15 13:15:43 +00:00
-- When using one string one can skip the parenthesis:
v2_5_1 = v'2.5.1' -- valid in Lua
2012-01-14 02:38:04 +00:00
-- major, minor and patch attributes
v2_5_1.major -- 2
v2_5_1.minor -- 5
v2_5_1.patch -- 1
2012-01-13 23:08:47 +00:00
2012-01-15 13:15:43 +00:00
-- prereleases:
a = v(1,0,0,'alpha')
2012-01-14 02:38:04 +00:00
a.prerelease -- 'alpha'
2012-01-15 13:15:43 +00:00
b = v('1.0.0-beta')
b.prerelease -- 'beta'
-- builds
c = v(1,0,0,nil,'build-1')
c.build -- 'build-1'
2012-01-14 02:34:43 +00:00
2012-01-15 13:15:43 +00:00
d = v('0.9.5+no.extensions.22')
d.build -- 'no.extensions.22'
2012-01-14 02:34:43 +00:00
2012-01-14 02:38:04 +00:00
-- comparison & sorting
2012-01-15 13:15:43 +00:00
v'1.2.3' == v(1,2,3) -- true
v'1.2.3' < v(4,5,6) -- true
v'1.2.3-alpha' < v'1.2.3' -- true
v'1.2.3' < v'1.2.3+build.1' -- false, builds are ignored when comparing versions in semver
2012-01-15 13:15:43 +00:00
-- (see the "notes" section for more informaion about version comparison)
2012-01-14 02:34:43 +00:00
2012-01-14 02:38:04 +00:00
-- "pessimistic upgrade" operator: ^
-- a ^ b returns true if it's safe to update from a to b
v'2.0.1' ^ v'2.5.1' -- true - it's safe to upgrade from 2.0.1 to 2.5.1
v'1.0.0' ^ v'2.0.0' -- false - 2.0.0 is not supposed to be backwards-compatible
v'2.5.1' ^ v'2.0.1' -- false - 2.5.1 is more modern than 2.0.1.
2012-01-14 02:34:43 +00:00
2012-01-15 13:15:43 +00:00
-- getting newer versions
2012-01-14 02:38:04 +00:00
v(1,0,0):nextPatch() -- v1.0.1
v(1,2,3):nextMinor() -- v1.3.0 . Notice the patch resets to 0
v(1,2,3):nextMajor() -- v2.0.0 . Minor and patch are reset to 0
2012-01-14 02:34:43 +00:00
2015-09-27 18:08:45 +00:00
```
2012-01-13 23:08:47 +00:00
2015-09-27 18:08:45 +00:00
# Installation
2012-01-13 23:08:47 +00:00
2015-09-27 18:08:45 +00:00
Just copy the semver.lua file wherever you want it (for example on a lib/ folder). Then write this in any Lua file where you want to use it. You must assign the require to a global or local variable (I use a local `v`):
2012-01-13 23:08:47 +00:00
2015-09-27 18:08:45 +00:00
``` lua
local v = require 'semver'
```
2012-01-13 23:08:47 +00:00
2015-09-27 18:08:45 +00:00
Using `v` allows for the nice string syntax: `v'1.2.3-alpha'`.
2012-01-13 23:08:47 +00:00
Please make sure that you read the license, too (for your convenience it's now included at the beginning of the semver.lua file).
2015-09-27 18:08:45 +00:00
# Notes about version comparison
2012-01-15 13:15:43 +00:00
2015-09-27 18:08:45 +00:00
Version comparison is done according to the semver 2.0.0 specs:
2012-01-15 13:15:43 +00:00
Major, minor, and patch versions are always compared numerically.
Pre-release precedence MUST be determined by comparing each dot-separated identifier as follows:
2012-01-15 13:15:43 +00:00
* Identifiers consisting of only digits are compared numerically
* Identifiers with letters or dashes are compared lexically in ASCII sort order.
* Numeric identifiers always have lower precedence than non-numeric identifiers
Builds are ignored when calculating precedence: version 1.2.3 and 1.2.3+build5 are considered equal.
2015-09-27 18:08:45 +00:00
# Specs
This project uses "busted":http://olivinelabs.com/busted/ for its specs. If you want to run the specs, you will have to install telescope first. Then just execute the following from the root inspect folder:
```
busted
```
2012-01-13 23:08:47 +00:00
2015-09-27 18:08:45 +00:00
# Changelog
2012-01-13 23:08:47 +00:00
2015-09-27 18:08:45 +00:00
## v1.1.1:
* Removed global variable which was declared by mistake
* Changed spec tool from telescope to busted
* Changed README format from textile to markdown
2015-10-24 08:28:48 +00:00
## v.1.2.0:
2015-10-24 08:28:48 +00:00
* Fix error: builds were being used for comparison, but according with semver 2.0.0 they should be ignored (so v'1.0.0+build1' is equal to v'1.0.0+build2')
* Fix several errors and inconsistencies in the way the comparisons where implemented.
* Added a lot more tests to cover more edge cases when comparing versions
2012-01-13 23:08:47 +00:00
2016-08-04 10:30:28 +00:00
## v.1.2.1
* Fix error on pessimistic update operator when applied to a 0.x.x version