Title: | 'Semantic Versioning V2.0.0' Parser |
---|---|
Description: | Tools and functions for parsing, rendering and operating on semantic version strings. Semantic versioning is a simple set of rules and requirements that dictate how version numbers are assigned and incremented as outlined at <http://semver.org>. |
Authors: | John Harrison [aut, cre] (R package semver), Marko Živanović [aut, cph] (semver cpp library, https://github.com/zmarko/semver) |
Maintainer: | John Harrison <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2024-11-03 03:35:15 UTC |
Source: | https://github.com/johndharrison/semver |
Increment the version field. "Major", "minor" and "patch" fields are set as integers. Fields of lower precedence are reset to default value (0L)
increment_version(x, field, value, ...) ## S3 method for class 'svptr' increment_version(x, field = c("major", "minor", "patch"), value, ...) ## S3 method for class 'svlist' increment_version(x, field, value, ...)
increment_version(x, field, value, ...) ## S3 method for class 'svptr' increment_version(x, field = c("major", "minor", "patch"), value, ...) ## S3 method for class 'svlist' increment_version(x, field, value, ...)
x |
An object of class "svlist" or "svptr". |
field |
For the "svptr" class a character string detailing the field to set (major, minor etc...). For the "svlist" class a character vector detailing the field to set for each list member. |
value |
The value to increment the field by. For fields "major", "minor" and "patch" this is an integer. For the "svptr" class value is a scalar. For the "svlist" class value is an integer vector detailing the value to increment by for each list member. |
... |
Additional arguments passed on to methods. |
returns an object of class svptr or svlist
semver <- parse_version(c("1.2.3", "1.2.4-alpha+bld1")) increment_version(semver[[2]], "major", 1L) increment_version(semver[[2]], "major", -1L) increment_version(semver, c("minor", "patch"), c(3L, 9L)) increment_version(semver, c("minor", "patch"), c(-1L, -3L)) increment_version(semver, c("minor"), 1L)
semver <- parse_version(c("1.2.3", "1.2.4-alpha+bld1")) increment_version(semver[[2]], "major", 1L) increment_version(semver[[2]], "major", -1L) increment_version(semver, c("minor", "patch"), c(3L, 9L)) increment_version(semver, c("minor", "patch"), c(-1L, -3L)) increment_version(semver, c("minor"), 1L)
Parse a character vector to semantic versions
parse_version(version)
parse_version(version)
version |
A character vector |
A list of "svptr" objects. The list itself is of class "svlist"
semver <- parse_version(c("1.2.3", "1.2.4", "1.0.0", "1.2.4-beta", "2.1.3-alpha", "1.9.4")) max(semver) ver124a <- semver[semver > "1.2.4-alpha"] sort(ver124a) # compare versions semver[[1]] < semver[[2]] # compare against a version semver > semver[1] # compare against a character string semver > "1.7.2" # sort versions sort(semver) order(semver) rank(semver) # get summary statistics min(semver) max(semver) range(semver) # coerce versions as.character(semver) as.data.frame(semver)
semver <- parse_version(c("1.2.3", "1.2.4", "1.0.0", "1.2.4-beta", "2.1.3-alpha", "1.9.4")) max(semver) ver124a <- semver[semver > "1.2.4-alpha"] sort(ver124a) # compare versions semver[[1]] < semver[[2]] # compare against a version semver > semver[1] # compare against a character string semver > "1.7.2" # sort versions sort(semver) order(semver) rank(semver) # get summary statistics min(semver) max(semver) range(semver) # coerce versions as.character(semver) as.data.frame(semver)
Render a semantic version list or a semantic version pointer as an R list giving the major, minor and patch version as an integer and the prerelease and build version as a charcter
render_version(x, ...) ## S3 method for class 'svptr' render_version(x, ...) ## S3 method for class 'svlist' render_version(x, ...)
render_version(x, ...) ## S3 method for class 'svptr' render_version(x, ...) ## S3 method for class 'svlist' render_version(x, ...)
x |
An object of class "svlist" or "svptr". |
... |
Additional arguments passed on to methods. |
A list of semantic versions represented as integers (major, minor, patch) and characters (prerelease, build)
semver <- parse_version(c("1.2.3", "1.2.4", "1.0.0", "1.2.4-beta+2", "2.1.3-alpha", "1.9.4")) render_version(semver[[4]]) render_version(semver)
semver <- parse_version(c("1.2.3", "1.2.4", "1.0.0", "1.2.4-beta+2", "2.1.3-alpha", "1.9.4")) render_version(semver[[4]]) render_version(semver)
Reset the version field. "Major", "minor" and "patch" fields are set as integers, "prerelease" and "build" are set with character strings. Fields of lower precedence are reset to default value (0L or "")
reset_version(x, field, value, ...) ## S3 method for class 'svptr' reset_version(x, field = c("major", "minor", "patch", "prerelease", "build"), value, ...) ## S3 method for class 'svlist' reset_version(x, field, value, ...)
reset_version(x, field, value, ...) ## S3 method for class 'svptr' reset_version(x, field = c("major", "minor", "patch", "prerelease", "build"), value, ...) ## S3 method for class 'svlist' reset_version(x, field, value, ...)
x |
An object of class "svlist" or "svptr". |
field |
For the "svptr" class a character string detailing the field to set (major, minor etc...). For the "svlist" class a character vector detailing the field to set for each list member. |
value |
The value to set the field to. For fields "major", "minor" and "patch" this is an integer. For fields "prerelease" and "build" this is a character. For the "svptr" class value is a scalar. For the "svlist" class value is a list detailing the value to set for each list member. |
... |
Additional arguments passed on to methods. |
returns an object of class svptr or svlist
semver <- parse_version(c("1.2.3", "1.2.4-alpha+bld1")) reset_version(semver[[2]], "major", 1L) semver[[1]] <- reset_version(semver[[1]], "major", 2L) reset_version(semver, c("minor", "prerelease"), list(3L, "beta")) reset_version(semver, c("prerelease"), list("hello", "world"))
semver <- parse_version(c("1.2.3", "1.2.4-alpha+bld1")) reset_version(semver[[2]], "major", 1L) semver[[1]] <- reset_version(semver[[1]], "major", 2L) reset_version(semver, c("minor", "prerelease"), list(3L, "beta")) reset_version(semver, c("prerelease"), list("hello", "world"))
semver
has two functions:
parse_version
,
render_version
,
parse_version
takes as input a character vector with
elements following the specification at http://semver.org/.
Comparisons can be done on the "svlist" and "svptr" classes returned
by parse_version
. Ops
and
summary
methods are implemented for both classes.
Set the version field. "Major", "minor" and "patch" fields are set as integers, "prerelease" and "build" are set with character strings.
set_version(x, field, value, ...) ## S3 method for class 'svptr' set_version(x, field = c("major", "minor", "patch", "prerelease", "build"), value, ...) ## S3 method for class 'svlist' set_version(x, field, value, ...)
set_version(x, field, value, ...) ## S3 method for class 'svptr' set_version(x, field = c("major", "minor", "patch", "prerelease", "build"), value, ...) ## S3 method for class 'svlist' set_version(x, field, value, ...)
x |
An object of class "svlist" or "svptr". |
field |
For the "svptr" class a character string detailing the field to set (major, minor etc...). For the "svlist" class a character vector detailing the field to set for each list member. |
value |
The value to set the field to. For fields "major", "minor" and "patch" this is an integer. For fields "prerelease" and "build" this is a character. For the "svptr" class value is a scalar. For the "svlist" class value is a list detailing the value to set for each list member. |
... |
Additional arguments passed on to methods. |
returns an object of class svptr or svlist
semver <- parse_version(c("1.2.3", "1.2.4-alpha+bld1")) semver[[1]] <- set_version(semver[[1]], "major", 2L) set_version(semver, c("prerelease", "build"), list("hello")) set_version(semver, c("prerelease"), list("hello", "world"))
semver <- parse_version(c("1.2.3", "1.2.4-alpha+bld1")) semver[[1]] <- set_version(semver[[1]], "major", 2L) set_version(semver, c("prerelease", "build"), list("hello")) set_version(semver, c("prerelease"), list("hello", "world"))