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

Safe HaskellSafe
LanguageHaskell2010

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, traversals, common manipulations, and serialisation primitives.

Synopsis

Version

data Version Source #

An opaque type representing a successfully decoded or constructed semantic version. See the related functions and lenses for modification and update.

  • The Eq instance represents exhaustive equality with all components considered.
  • The Ord instance implements the precedence rules from the semantic version specification with metadata being ignored.
Instances
Eq Version Source # 
Instance details

Defined in Data.SemVer.Internal

Methods

(==) :: Version -> Version -> Bool #

(/=) :: Version -> Version -> Bool #

Ord Version Source # 
Instance details

Defined in Data.SemVer.Internal

Show Version Source # 
Instance details

Defined in Data.SemVer.Internal

NFData Version Source # 
Instance details

Defined in Data.SemVer.Internal

Methods

rnf :: Version -> () #

Hashable Version Source # 
Instance details

Defined in Data.SemVer.Internal

Methods

hashWithSalt :: Int -> Version -> Int #

hash :: Version -> Int #

Constructors

version Source #

Arguments

:: Int

Major version component.

-> Int

Minor version component.

-> Int

Patch version component.

-> [Identifier]

Release identifiers.

-> [Identifier]

Metadata identifiers.

-> Version 

Smart constructor fully specifying all available version components.

initial :: Version Source #

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

Note: Equivalent to 0.0.0

Lenses

major :: Functor f => (Int -> f Int) -> Version -> f Version Source #

Lens for the major version component.

minor :: Functor f => (Int -> f Int) -> Version -> f Version Source #

Lens for minor version component.

patch :: Functor f => (Int -> f Int) -> Version -> f Version Source #

Lens for the patch version component.

release :: Functor f => ([Identifier] -> f [Identifier]) -> Version -> f Version Source #

Lens for the list of release identifiers.

metadata :: Functor f => ([Identifier] -> f [Identifier]) -> Version -> f Version Source #

Lens for the list of metadata identifiers.

Incrementing

The following increment functions are used to ensure that the related version components are reset according to the specification.

See the individual function documentation for specifics regarding each version component.

incrementMajor :: Version -> Version Source #

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 -> Version Source #

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 -> Version Source #

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 -> Bool Source #

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 -> Bool Source #

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 -> String Source #

Convert a Version to it's readable String representation.

Note: This is optimised for cases where you require String output, and as such is faster than the semantically equivalent unpack . toLazyText.

toText :: Version -> Text Source #

Convert a Version to a strict Text representation.

Note: Equivalent to toStrict . toLazyText

toLazyText :: Version -> Text Source #

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 Version Source #

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

fromLazyText :: Text -> Either String Version Source #

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 Version Source #

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

Identifiers

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.

The functions numeric and textual can be used to construct an Identifier.

Constructors

numeric :: Int -> Identifier Source #

Safely construct a numeric identifier.

textual :: Text -> Maybe Identifier Source #

Construct an identifier from the given Text, returning Nothing if neither a numeric or valid textual input is supplied.

Prisms

_Numeric :: Applicative f => (Int -> f Int) -> Identifier -> f Identifier Source #

A prism into the numeric branch of an Identifier.

_Textual :: Applicative f => (Text -> f Text) -> Identifier -> f (Maybe Identifier) Source #

A prism into the textual branch of an Identifier.