semver-0.1.1: Representation, manipulation, and de/serialisation of Semantic Versions.

Safe HaskellNone

Data.SemVer

Contents

Description

An implementation of the Semantic Versioning specification located at http://semver.org.

A canonical Version type and functions representing behaviour as outlined in the specification are defined alongside additional lenses, common manipulations, and serialisation primitives.

Synopsis

Version

data Identifier Source

A type representing an individual identifier from the release or metadata components of a Version.

  • The Ord instance implements precedence according to the semantic version specification, with numeric identifiers being of lower precedence than textual identifiers, otherwise lexicographic ordering is used.

Constructors

INum !Int 
IText !Text 

data Version Source

A type representing a successfully decoded or constructed semantic version.

  • The Eq instance represents exhaustive equality with all components considered.
  • The Ord instance implements the precedence rules from the semantic version specification with metadata (_versionMeta) being ignored.

Constructors

Version 

Fields

_versionMajor :: !Int

The major version component.

_versionMinor :: !Int

The minor version component.

_versionPatch :: !Int

The patch level component.

_versionRelease :: [Identifier]

A (potentially empty) list of release identifiers.

_versionMeta :: [Identifier]

A (potentially empty) list of metadata.

defaultVersion :: VersionSource

A default Version which can be used to signify initial development.

Note: Equivalent to 0.0.0

Lenses

Incrementing

incrementMajor :: Version -> VersionSource

Increment the major component of a Version by 1, resetting the minor and patch components.

  • Major version X (X.y.z | X > 0) MUST be incremented if any backwards incompatible changes are introduced to the public API.
  • It MAY include minor and patch level changes.
  • Patch and minor version MUST be reset to 0 when major version is incremented.

incrementMinor :: Version -> VersionSource

Increment the minor component of a Version by 1, resetting the patch component.

  • Minor version Y (x.Y.z | x > 0) MUST be incremented if new, backwards compatible functionality is introduced to the public API.
  • It MUST be incremented if any public API functionality is marked as deprecated.
  • It MAY be incremented if substantial new functionality or improvements are introduced within the private code.
  • It MAY include patch level changes.
  • Patch version MUST be reset to 0 when minor version is incremented.

incrementPatch :: Version -> VersionSource

Increment the patch component of a Version by 1.

  • Patch version Z (x.y.Z | x > 0) MUST be incremented if only backwards compatible bug fixes are introduced.
  • A bug fix is defined as an internal change that fixes incorrect behavior.

Predicates

isDevelopment :: Version -> BoolSource

Check if the Version is considered unstable.

  • Major version zero (0.y.z) is for initial development.
  • Anything may change at any time.
  • The public API should not be considered stable.

isPublic :: Version -> BoolSource

Check if the Version is considered stable.

Version 1.0.0 defines the public API. The way in which the version number is incremented after this release is dependent on this public API and how it changes.

Encoding

toString :: Version -> StringSource

Convert a Version to it's readable String representation.

Note: This is optimised for cases where you wish to use a String and as such is faster than the semantically equivalent unpack . toLazyText.

toText :: Version -> TextSource

Convert a Version to a strict Text representation.

Note: Equivalent to toStrict . toLazyText

toLazyText :: Version -> TextSource

Convert a Version to a Text representation.

Note: This uses a lower Builder buffer size optimised for commonly found version formats. If you have particuarly long version numbers using toBuilder and toLazyTextWith to control the buffer size is recommended.

Decoding

fromText :: Text -> Either String VersionSource

Parse a Version from Text, returning an attoparsec error message in the Left case on failure.

fromLazyText :: Text -> Either String VersionSource

Parse a Version from Text, returning an attoparsec error message in the Left case on failure.

Note: The underlying attoparsec Parser is based on Text and this is equivalent to fromText . toStrict

parser :: Parser VersionSource

A greedy attoparsec Parser which requires the entire Text input to match.

Delimiters

data Delimiters Source

A set of delimiters used to encode/decode a Version and specifyc alternative serialisation strategies.

Example: using alpha characters to encode the version as a valid DNS CNAME, such as:

 let Right v = fromText 1.2.3+40
 let alpha   = Delimiters 'm' 'p' 'r' 'd' 'i'

Data.Text.Lazy.Builder.toLazyText (app01-  toDelimitedBuilder alpha v  .dmz.internal)

Would result in the following Text:

 app01-1m2p3d40.dmz.internal

Using the same Delimiters set with delimitedParser would ensure correct decoding behaviour.

defaultDelimiters :: DelimitersSource

The default set of delimiters used in the semantic version specification.

Example: Given exhaustive version components would result in the following hypothetical version:

 1.2.3-alpha.1+sha.exp.12ab3d9

Lenses

Encoding

toDelimitedBuilder :: Delimiters -> Version -> BuilderSource

Convert a Version to a Builder using the specified Delimiters set.

Decoding

delimitedParser :: Delimiters -> Parser VersionSource

A greedy attoparsec Parser using the specified Delimiters set which requires the entire Text input to match.