flarebyte/bubblegum-entity/1.1.1

Bubblegum.Entity.Validation

List of validations with implicit transformations that can be applied to an outcome

For most validations:

  • None will propagate as None.
  • Warning will propagate as Warning.
  • A failure to validate the outcome will produce a Warning.

Simple conversion

asSingle : Outcome (List String) -> Outcome String

Convert a list with only one string to a single string.

Valid [ "alpha" ] |> asSingle -- Valid "alpha"
Outcome ( List String, List String )
-> Outcome ( String, String )

Convert a tuple of singleton list to a tuple of String

Valid ( [ "min" ], [ "max" ] ) |> asTuple -- Valid ("min", "max")
asBool : Outcome String -> Outcome Bool

Convert a String to a Float otherwise raise a warning

Valid "true" |> asBool -- Valid True
asFloat : Outcome String -> Outcome Float

Convert a String to a Float otherwise raise a warning

Valid "12.3" |> asFloat -- Valid 12.3
asInt : Outcome String -> Outcome Int

Convert a String to an Int otherwise raise a warning

Valid "12" |> asInt -- Valid 12
asIntTuple : Outcome ( String, String ) -> Outcome ( Int, Int )

Convert a tuple of String to a tuple of Int otherwise raise a warning

Valid ( "3", "5" ) |> asIntTuple -- Valid (3, 5)
asFloatTuple : Outcome ( String, String ) -> Outcome ( Float, Float )

Convert a tuple of String to a tuple of Float otherwise raise a warning

Valid ( "3.5", "5.5" ) |> asFloatTuple -- Valid (3.5, 5.5)
asUnique : Outcome (List String) -> Outcome (List String)

Enforce that the list to be unique

Valid [ "alpha", "beta", "alpha" ] |> asUnique -- Valid ["alpha", "beta"]

Range validation

asIntRange : Outcome ( Int, Int ) -> Outcome ( Int, Int )

Check that first value is strictly less than the second otherwise raise a warning

Valid ( 3, 5 ) |> asIntRange -- Valid (3, 5)
asFloatRange : Outcome ( Float, Float ) -> Outcome ( Float, Float )

Check that first value is strictly less than the second otherwise raise a warning

Valid ( 3.5, 5.5 ) |> asFloatRange -- Valid (3.5, 5.5)
withinIntRange : ( Int, Int ) -> Outcome ( Int, Int ) -> Outcome ( Int, Int )

Check a tuple of Int is within the range of a given range otherwise raise a warning

Valid ( 3, 5 ) |> withinIntRange ( 2, 7 ) -- Valid (3, 5)
( Float, Float )
-> Outcome ( Float, Float )
-> Outcome ( Float, Float )

Check a tuple of Float is within the range of a given range otherwise raise a warning

Valid ( 3.5, 5.2 ) |> withinFloatRange ( 2.1, 7.2 ) -- Valid (3.5, 5.2)

List validation

listEqual : Int -> Outcome (List String) -> Outcome (List String)

Ensure that the list equal a given size otherwise raise a warning

Valid [ "alpha", "beta" ] |> listEqual 2 -- Valid ["alpha", "beta"]
listLessThan : Int -> Outcome (List String) -> Outcome (List String)

Ensure that the list equal or less than a given size otherwise raise a warning

Valid [ "alpha", "beta" ] |> listLessThan 2 -- Valid ["alpha", "beta"]
listMoreThan : Int -> Outcome (List String) -> Outcome (List String)

Ensure that the list equal or more than a given size otherwise raise a warning

Valid [ "alpha", "beta" ] |> listMoreThan 2 -- Valid ["alpha", "beta"]
listStrictlyLessThan : Int -> Outcome (List String) -> Outcome (List String)

Ensure that the list is strictly less than a given size otherwise raise a warning

Valid [ "alpha", "beta" ] |> listStrictlyLessThan 3 -- Valid ["alpha", "beta"]
listStrictlyMoreThan : Int -> Outcome (List String) -> Outcome (List String)

Ensure that the list is strictly more than a given size otherwise raise a warning

Valid [ "alpha", "beta" ] |> listStrictlyMoreThan 1 -- Valid ["alpha", "beta"]

String validation

matchAbsoluteUrl : Outcome String -> Outcome String

Check whether a string matches an absolute URL otherwise raise a warning

Valid "http://bbc.co.uk" |> matchAbsoluteUrl -- Valid "http://bbc.co.uk"
matchCompactUri : Outcome String -> Outcome String

Check whether a string matches an absolute URL otherwise raise a warning.

The prefix should not exceed 15 characters.


Valid "uri:a/b001/c" |> matchCompactUri -- Valid "uri:a/b001/c"
matchEnum : List String -> Outcome String -> Outcome String

Check that a string belong to an enumeration otherwise raise a warning

Valid [ "alpha" ] |> matchEnum [ "beta", "alpha" ] -- Valid ["alpha"]

Check that a string is a normalized string

Valid "some string" |> matchNormalizedString -- Valid "some string"
matchRegex : String -> Outcome String -> Outcome String

Check whether a string matches a regular expression otherwise raise a warning

Valid "abc" |> matchRegex "[a-z]+" -- Valid "abc"
stringContains : String -> Outcome String -> Outcome String

Check that a string contains a term otherwise raise a warning

Valid [ "blue red green" ] |> stringContains "red" -- Valid ["blue red green"]
stringStartsWith : String -> Outcome String -> Outcome String

Check that a string starts with a prefix otherwise raise a warning

Valid [ "ui:label" ] |> stringStartsWith "ui:" -- Valid ["ui:label"]
stringEndsWith : String -> Outcome String -> Outcome String

Check that a string ends with a suffix otherwise raise a warning

Valid [ "image.jpg" ] |> stringEndsWith ".jpg" -- Valid ["image.jpg"]
withinListStringCharsRange : ( Int, Int ) -> Outcome (List String) -> Outcome (List String)

Check that all the strings' number of characters are within a range otherwise raise a warning

Valid [ "abc", "abcd" ] |> withinListStringCharsRange ( 2, 7 ) -- Valid "abcd"
withinStringCharsRange : ( Int, Int ) -> Outcome String -> Outcome String

Check that a string number of characters is within a range otherwise raise a warning

Valid "abcd" |> withinStringCharsRange ( 2, 7 ) -- Valid "abcd"

Number validation

floatLessThan : Float -> Outcome Float -> Outcome Float

Check that an int is equal or less than a given value otherwise raise a warning

Valid 12.4 |> floatLessThan 12.4 -- Valid 12.4
floatMoreThan : Float -> Outcome Float -> Outcome Float

Check that an int is equal or more than a given value otherwise raise a warning

Valid 12.4 |> floatMoreThan 5.0 -- Valid 12.4
floatStrictlyLessThan : Float -> Outcome Float -> Outcome Float

Check that an int is strictly less than a given value otherwise raise a warning

Valid 12.4 |> floatStrictlyLessThan 20 -- Valid 12.4
floatStrictlyMoreThan : Float -> Outcome Float -> Outcome Float

Check that an int is strictly more than a given value otherwise raise a warning

Valid 12.4 |> floatStrictlyMoreThan 5.3 -- Valid 12.4
intLessThan : Int -> Outcome Int -> Outcome Int

Check that an int is equal or less than a given value otherwise raise a warning

Valid 12 |> intLessThan 12 -- Valid 12
intMoreThan : Int -> Outcome Int -> Outcome Int

Check that an int is equal or more than a given value otherwise raise a warning

Valid 12 |> intMoreThan 12 -- Valid 12
intStrictlyLessThan : Int -> Outcome Int -> Outcome Int

Check that an int is strictly less than a given value otherwise raise a warning

Valid 12 |> intStrictlyLessThan 20 -- Valid 12
intStrictlyMoreThan : Int -> Outcome Int -> Outcome Int

Check that an int is equal or more than a given value otherwise raise a warning

Valid 12 |> intStrictlyMoreThan 5 -- Valid 12