-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Eric Pailleau edited this page Apr 20, 2025
·
11 revisions
samovar is an Erlang/OTP library for SEMVER standard handling, implementing:
- check of semver version against a semver range
- understand any semver ranges ( simple range or more complicated ranges using "and" and "or")
- smart handling of old Erlang/OTP release names
- extraction of elements of a semver version syntax
Since version 1.1 samovar understand both NPM and Elixir standard for version comparisons.
A cheat-sheet page is available to remind equivalences.
No function is available to compare two versions, as check/2 can be used for almost anything... See below examples.
1> samovar:check("1.2.3", ">2.0.0").
falseSo you can create you own functions or fun() :
% Creating a 'greater than' fun
1> GT = fun(V, R) -> samovar:check(V, ">"++R) end.
#Fun<erl_eval.41.81571850>
2> GT("1.2.3","2.0.0").
false
3> GT("1.2.3","1.0.0").
trueBelow an example to partition a list of versions between a sublist strictly higher than "2.0.0" and not.
1> R = "2.0.0".
"2.0.0"
2> GT = fun(V, R) -> samovar:check(V, ">"++R) end.
#Fun<erl_eval.41.81571850>
3> S = fun(X) -> GT(X, R) end.
#Fun<erl_eval.42.81571850>
4> lists:partition(S, ["1.1.0","1.2.3","2.0.1","3.1.2"]).
{["2.0.1","3.1.2"],["1.1.0","1.2.3"]}% Requirement for versions
1> R = "<2.0.0" .
"<2.0.0"
% Create a filter for versions matching requirement
2> FILTER = fun(X) -> samovar:check(X, R) end.
#Fun<erl_eval.42.81571850>
% Get candidate versions
3> CAN = lists:filter(FILTER, ["1.1.0","1.2.3","2.0.1","3.1.2"]).
["1.1.0","1.2.3"]
% Create fun to sort list with lists:sort/2
4> SORT = fun(A, B) -> samovar:check(A, ">="++B) end.
#Fun<erl_eval.41.81571850>
% Get best version matching rerquirement
5> BEST = hd(lists:sort(SORT, CAN)).
"1.2.3"