Safe Haskell | None |
---|
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.
- data Identifier
- data Version = Version {
- _versionMajor :: !Int
- _versionMinor :: !Int
- _versionPatch :: !Int
- _versionRelease :: [Identifier]
- _versionMeta :: [Identifier]
- defaultVersion :: Version
- versionMajor :: Functor f => (Int -> f Int) -> Version -> f Version
- versionMinor :: Functor f => (Int -> f Int) -> Version -> f Version
- versionPatch :: Functor f => (Int -> f Int) -> Version -> f Version
- versionRelease :: Functor f => ([Identifier] -> f [Identifier]) -> Version -> f Version
- versionMeta :: Functor f => ([Identifier] -> f [Identifier]) -> Version -> f Version
- incrementMajor :: Version -> Version
- incrementMinor :: Version -> Version
- incrementPatch :: Version -> Version
- isDevelopment :: Version -> Bool
- isPublic :: Version -> Bool
- toString :: Version -> String
- toText :: Version -> Text
- toLazyText :: Version -> Text
- toBuilder :: Version -> Builder
- fromText :: Text -> Either String Version
- fromLazyText :: Text -> Either String Version
- parser :: Parser Version
- data Delimiters = Delimiters {
- _delimMinor :: !Char
- _delimPatch :: !Char
- _delimRelease :: !Char
- _delimMeta :: !Char
- _delimIdent :: !Char
- defaultDelimiters :: Delimiters
- delimMinor :: Functor f => (Char -> f Char) -> Delimiters -> f Delimiters
- delimPatch :: Functor f => (Char -> f Char) -> Delimiters -> f Delimiters
- delimRelease :: Functor f => (Char -> f Char) -> Delimiters -> f Delimiters
- delimMeta :: Functor f => (Char -> f Char) -> Delimiters -> f Delimiters
- delimIdent :: Functor f => (Char -> f Char) -> Delimiters -> f Delimiters
- toDelimitedBuilder :: Delimiters -> Version -> Builder
- delimitedParser :: Delimiters -> Parser Version
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.
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.
Version | |
|
defaultVersion :: VersionSource
A default Version
which can be used to signify initial development.
Note: Equivalent to 0.0.0
Lenses
versionRelease :: Functor f => ([Identifier] -> f [Identifier]) -> Version -> f VersionSource
versionMeta :: Functor f => ([Identifier] -> f [Identifier]) -> Version -> f VersionSource
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
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
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.
Delimiters | |
|
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
delimMinor :: Functor f => (Char -> f Char) -> Delimiters -> f DelimitersSource
delimPatch :: Functor f => (Char -> f Char) -> Delimiters -> f DelimitersSource
delimRelease :: Functor f => (Char -> f Char) -> Delimiters -> f DelimitersSource
delimMeta :: Functor f => (Char -> f Char) -> Delimiters -> f DelimitersSource
delimIdent :: Functor f => (Char -> f Char) -> Delimiters -> f DelimitersSource
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.