Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
WARNING: This module should be considered private! If you find yourself wanting to import something from this module, please open an issue to get that thing exported from Salve.
- data Version = Version {
- versionMajor :: Word
- versionMinor :: Word
- versionPatch :: Word
- versionPreReleases :: [PreRelease]
- versionBuilds :: [Build]
- data PreRelease
- newtype Build = Build String
- data Constraint
- parseVersion :: String -> Maybe Version
- parsePreRelease :: String -> Maybe PreRelease
- parseBuild :: String -> Maybe Build
- parseConstraint :: String -> Maybe Constraint
- unsafeParseVersion :: String -> Version
- unsafeParsePreRelease :: String -> PreRelease
- unsafeParseBuild :: String -> Build
- unsafeParseConstraint :: String -> Constraint
- renderVersion :: Version -> String
- renderPreRelease :: PreRelease -> String
- renderBuild :: Build -> String
- renderConstraint :: Constraint -> String
- isUnstable :: Version -> Bool
- isStable :: Version -> Bool
- bumpMajor :: Version -> Version
- bumpMinor :: Version -> Version
- bumpPatch :: Version -> Version
- satisfies :: Version -> Constraint -> Bool
- majorLens :: Functor f => (Word -> f Word) -> Version -> f Version
- minorLens :: Functor f => (Word -> f Word) -> Version -> f Version
- patchLens :: Functor f => (Word -> f Word) -> Version -> f Version
- preReleasesLens :: Functor f => ([PreRelease] -> f [PreRelease]) -> Version -> f Version
- buildsLens :: Functor f => ([Build] -> f [Build]) -> Version -> f Version
- data Operator
- constraintLT :: Version -> Constraint
- constraintLE :: Version -> Constraint
- constraintEQ :: Version -> Constraint
- constraintGE :: Version -> Constraint
- constraintGT :: Version -> Constraint
- constraintAnd :: Constraint -> Constraint -> Constraint
- constraintOr :: Constraint -> Constraint -> Constraint
- versionP :: Parser Version
- preReleasesP :: Parser [PreRelease]
- preReleaseP :: Parser PreRelease
- preReleaseNumberP :: Parser PreRelease
- preReleaseStringP :: Parser PreRelease
- buildsP :: Parser [Build]
- buildP :: Parser Build
- numberP :: Parser Word
- zeroP :: Parser Word
- nonZeroP :: Parser Word
- constraintsP :: Parser Constraint
- constraintP :: Parser Constraint
- hyphenatedP :: Parser Constraint
- simplesP :: Parser Constraint
- simpleP :: Parser Constraint
- caretP :: Parser Constraint
- caretUpper :: Version -> Version
- tildeP :: Parser Constraint
- tildeUpper :: Version -> Version
- primitiveP :: Parser Constraint
- operatorP :: Parser Operator
- leP :: Parser Operator
- geP :: Parser Operator
- ltP :: Parser Operator
- gtP :: Parser Operator
- eqP :: Parser Operator
- hyphenP :: Parser String
- orP :: Parser String
- spacesP :: Parser String
- spaceP :: Parser Char
- parse :: Parser a -> String -> Maybe a
- newtype Parser a = Parser {}
- charP :: Char -> Parser Char
- choiceP :: Parser a -> Parser a -> Parser a
- failP :: Parser a
- getP :: Parser Char
- manyP :: Parser a -> Parser [a]
- oneOfP :: [Parser a] -> Parser a
- optionP :: a -> Parser a -> Parser a
- satisfyP :: (Char -> Bool) -> Parser Char
- sepByP :: Parser b -> Parser a -> Parser [a]
- sepBy1P :: Parser b -> Parser a -> Parser [a]
- someP :: Parser a -> Parser [a]
- stringP :: String -> Parser String
- renderPreReleases :: [PreRelease] -> String
- renderBuilds :: [Build] -> String
- both :: (a -> b) -> (a, a) -> (b, b)
- comparing :: Ord b => (a -> b) -> a -> a -> Ordering
- isAsciiAlpha :: Char -> Bool
- isAsciiAlphaLower :: Char -> Bool
- isAsciiAlphaUpper :: Char -> Bool
- isAsciiDigit :: Char -> Bool
- isAsciiDigitNonZero :: Char -> Bool
- isIdentifier :: Char -> Bool
- join :: Char -> [String] -> String
- safeHead :: [a] -> Maybe a
Documentation
>>>
import Lens.Micro.Extras
Public
A semantic version number. Versions have five parts:
majorLens
: The major version number.minorLens
: The minor version number.patchLens
: The patch version number.preReleasesLens
: A list of pre-release identifiers.buildsLens
: A list of build metadata.
Use parseVersion
to create versions.
Version | |
|
Eq Version Source # | |
Ord Version Source # | In general,
Numbers are compared numerically, not alphabetically.
If all the numbers are the same, the pre-releases are compared.
A version with a pre-release is always less than a version without one as long as the other parts are the same.
Builds are not considered when comparing versions.
|
Show Version Source # | |
data PreRelease Source #
Pre-release information attached to a version. These can either be numeric or textual. They must not be empty.
- Numeric: Can be any non-negative integer. Cannot have leading zeros.
- Textual: Can be any string of ASCII digits, letters, or hyphens. Cannot be all digits, as that would be numeric.
In general, pre-releases must match the regular expression
/^[-0-9A-Za-z]+$/
.
Use parsePreRelease
to create pre-releases.
Eq PreRelease Source # | |
Ord PreRelease Source # | Numeric pre-releases are always less than textual pre-releases.
Numeric pre-releases are compared numerically.
Textual pre-releases are compared alphabetically.
|
Show PreRelease Source # | |
Build metadata attached to a version. These are similar to
PreRelease
s with some key differences:
- There is no such thing as numeric builds. Even though builds can look like numbers, all builds are textual.
- As a result, builds that look numeric are allowed to have leading zeros.
- Builds cannot be compared. That is, they do not have an
Ord
instance.
Use parseBuild
to create builds.
data Constraint Source #
Constrains allowable version numbers.
Use parseConstraint
to create constraints and satisfies
to see if a
version number satisfies a constraint.
parseVersion :: String -> Maybe Version Source #
Attempts to parse a version. This parser follows SemVer's BNF.
>>>
parseVersion "1.2.3-p.4+b.5"
Just (Version {versionMajor = 1, versionMinor = 2, versionPatch = 3, versionPreReleases = [PreReleaseTextual "p",PreReleaseNumeric 4], versionBuilds = [Build "b",Build "5"]})
Returns Nothing
if the parse fails.
>>>
parseVersion "wrong"
Nothing
Whitespace is not allowed and will cause the parser to fail.
>>>
parseVersion " 1.2.3 "
Nothing
parsePreRelease :: String -> Maybe PreRelease Source #
Attempts to parse a pre-release.
>>>
parsePreRelease "pre"
Just (PreReleaseTextual "pre")>>>
parsePreRelease "1"
Just (PreReleaseNumeric 1)
Returns Nothing
if the parse fails.
>>>
parsePreRelease "wrong!"
Nothing
Numeric pre-releases cannot contain leading zeros.
>>>
parsePreRelease "01"
Nothing
parseBuild :: String -> Maybe Build Source #
Attempts to parse a build.
>>>
parseBuild "build"
Just (Build "build")>>>
parseBuild "1"
Just (Build "1")
Returns Nothing
if the parse fails.
>>>
parseBuild "wrong!"
Nothing
Unlike pre-releases, numeric builds can have leading zeros.
>>>
parseBuild "01"
Just (Build "01")
parseConstraint :: String -> Maybe Constraint Source #
Attempts to parse a constraint. This parser follows npm's
BNF,
except that neither the so-called "x-ranges" nor partial version numbers are
not supported. So you cannot use 1.2.x
or >1.2
as version constraints.
>>>
parseConstraint ">1.2.3"
Just (ConstraintCompare OperatorGT (Version {versionMajor = 1, versionMinor = 2, versionPatch = 3, versionPreReleases = [], versionBuilds = []}))
Returns Nothing
if the parse fails.
>>>
parseConstraint "wrong"
Nothing
unsafeParseVersion :: String -> Version Source #
Parses a version.
>>>
unsafeParseVersion "1.2.3-p.4+b.5"
Version {versionMajor = 1, versionMinor = 2, versionPatch = 3, versionPreReleases = [PreReleaseTextual "p",PreReleaseNumeric 4], versionBuilds = [Build "b",Build "5"]}
Raises an exception if the parse fails.
>>>
unsafeParseVersion "wrong"
*** Exception: invalid version: "wrong" ...
See parseVersion
for a safe version of this function.
unsafeParsePreRelease :: String -> PreRelease Source #
Parses a pre-release.
>>>
unsafeParsePreRelease "pre"
PreReleaseTextual "pre"
Raises an exception if the parse fails.
>>>
unsafeParsePreRelease "wrong!"
*** Exception: invalid pre-release: "wrong!" ...
See parsePreRelease
for a safe version of this function.
unsafeParseBuild :: String -> Build Source #
Parses a build.
>>>
unsafeParseBuild "build"
Build "build"
Raises an exception if the parse fails.
>>>
unsafeParseBuild "wrong!"
Build "*** Exception: invalid build: "wrong!" ...
See parseBuild
for a safe version of this function.
unsafeParseConstraint :: String -> Constraint Source #
Parses a constraint.
>>>
unsafeParseConstraint ">1.2.3"
ConstraintCompare OperatorGT (Version {versionMajor = 1, versionMinor = 2, versionPatch = 3, versionPreReleases = [], versionBuilds = []})
Raises an exception if the parse fails.
>>>
unsafeParseConstraint "wrong"
*** Exception: invalid constraint: "wrong" ...
See parseConstraint
for a safe version of this function.
renderVersion :: Version -> String Source #
Renders a version.
>>>
renderVersion <$> parseVersion "1.2.3-p.4+b.5"
Just "1.2.3-p.4+b.5"
renderPreRelease :: PreRelease -> String Source #
Renders a pre-release.
>>>
renderPreRelease <$> parsePreRelease "pre"
Just "pre">>>
renderPreRelease <$> parsePreRelease "1"
Just "1"
renderBuild :: Build -> String Source #
Renders a build.
>>>
renderBuild <$> parseBuild "build"
Just "build">>>
renderBuild <$> parseBuild "1"
Just "1"
renderConstraint :: Constraint -> String Source #
Renders a constraint.
>>>
renderConstraint <$> parseConstraint ">1.2.3"
Just ">1.2.3"
Parsing and rendering a constraint doesn't always return what you started with.
>>>
renderConstraint <$> parseConstraint "=1.2.3"
Just "1.2.3"
isUnstable :: Version -> Bool Source #
bumpMajor :: Version -> Version Source #
Increments the major version number.
>>>
bumpMajor <$> parseVersion "0.0.0"
Just (Version {versionMajor = 1, versionMinor = 0, versionPatch = 0, versionPreReleases = [], versionBuilds = []})
The minor and patch numbers are reset to zero.
>>>
bumpMajor <$> parseVersion "1.2.3"
Just (Version {versionMajor = 2, versionMinor = 0, versionPatch = 0, versionPreReleases = [], versionBuilds = []})
The pre-releases and builds are removed.
>>>
bumpMajor <$> parseVersion "0.0.0-pre+build"
Just (Version {versionMajor = 1, versionMinor = 0, versionPatch = 0, versionPreReleases = [], versionBuilds = []})
Consider using majorLens
if you want to arbitrarily change the major
number, or if you don't want the other parts of the version to change.
bumpMinor :: Version -> Version Source #
Increments the minor version number.
>>>
bumpMinor <$> parseVersion "0.0.0"
Just (Version {versionMajor = 0, versionMinor = 1, versionPatch = 0, versionPreReleases = [], versionBuilds = []})
The patch number is reset to zero.
>>>
bumpMinor <$> parseVersion "1.2.3"
Just (Version {versionMajor = 1, versionMinor = 3, versionPatch = 0, versionPreReleases = [], versionBuilds = []})
The pre-releases and builds are removed.
>>>
bumpMinor <$> parseVersion "0.0.0-pre+build"
Just (Version {versionMajor = 0, versionMinor = 1, versionPatch = 0, versionPreReleases = [], versionBuilds = []})
Consider using minorLens
if you want to arbitrarily change the minor
number, or if you don't want the other parts of the version to change.
bumpPatch :: Version -> Version Source #
Increments the patch number.
>>>
bumpPatch <$> parseVersion "0.0.0"
Just (Version {versionMajor = 0, versionMinor = 0, versionPatch = 1, versionPreReleases = [], versionBuilds = []})
The major and minor numbers are not changed.
>>>
bumpPatch <$> parseVersion "1.2.3"
Just (Version {versionMajor = 1, versionMinor = 2, versionPatch = 4, versionPreReleases = [], versionBuilds = []})
The pre-releases and builds are removed.
>>>
bumpPatch <$> parseVersion "0.0.0-pre+build"
Just (Version {versionMajor = 0, versionMinor = 0, versionPatch = 1, versionPreReleases = [], versionBuilds = []})
Consider using patchLens
if you want to arbitrarily change the patch
number, or if you don't want the other parts of the version to change.
majorLens :: Functor f => (Word -> f Word) -> Version -> f Version Source #
Focuses on the major version number.
>>>
view majorLens <$> parseVersion "1.2.3-pre.4+build.5"
Just 1
minorLens :: Functor f => (Word -> f Word) -> Version -> f Version Source #
Focuses on the minor version number.
>>>
view minorLens <$> parseVersion "1.2.3-pre.4+build.5"
Just 2
patchLens :: Functor f => (Word -> f Word) -> Version -> f Version Source #
Focuses on the patch version number.
>>>
view patchLens <$> parseVersion "1.2.3-pre.4+build.5"
Just 3
preReleasesLens :: Functor f => ([PreRelease] -> f [PreRelease]) -> Version -> f Version Source #
Focuses on the pre-release identifiers.
>>>
view preReleasesLens <$> parseVersion "1.2.3-pre.4+build.5"
Just [PreReleaseTextual "pre",PreReleaseNumeric 4]
buildsLens :: Functor f => ([Build] -> f [Build]) -> Version -> f Version Source #
Focuses on the build metadata.
>>>
view buildsLens <$> parseVersion "1.2.3-pre.4+build.5"
Just [Build "build",Build "5"]
Private
Types
constraintLT :: Version -> Constraint Source #
constraintLE :: Version -> Constraint Source #
constraintEQ :: Version -> Constraint Source #
constraintGE :: Version -> Constraint Source #
constraintGT :: Version -> Constraint Source #
constraintAnd :: Constraint -> Constraint -> Constraint Source #
constraintOr :: Constraint -> Constraint -> Constraint Source #
Parsing
preReleasesP :: Parser [PreRelease] Source #
caretUpper :: Version -> Version Source #
tildeUpper :: Version -> Version Source #
Helpers
Rendering
renderPreReleases :: [PreRelease] -> String Source #
renderBuilds :: [Build] -> String Source #
Helpers
isAsciiAlpha :: Char -> Bool Source #
isAsciiAlphaLower :: Char -> Bool Source #
isAsciiAlphaUpper :: Char -> Bool Source #
isAsciiDigit :: Char -> Bool Source #
isAsciiDigitNonZero :: Char -> Bool Source #
isIdentifier :: Char -> Bool Source #