bellroy/elm-storage/1.0.0

Formerly tricycle/elm-storage. Search finds this package by either name.

Storage.Value

type alias Value =
Value

A Storage Value

Build

empty : Value

Create an empty Value

string : String -> Value

Create a Value from a String

int : Int -> Value

Create a Value from an Int

float : Float -> Value

Create a Value from a Float

bool : Bool -> Value

Create a Value from a Bool

json : Value -> Value

Create a Value from a Json.Encode.Value

Helpers

compare : Value -> Value -> Order

Compare two Values

equals : Value -> Value -> Bool

Are two values the same?

JSON

encode : Value -> Value

Encode a Storage.Value as a Json.Encode.Value

decode : Decoder Value

Decode a Json.Encode.Value into a Json.Value

Convert

toString : Value -> Maybe String

Safely convert Value to a String

toString (string "foo")
--> Just "foo"


toString (bool True)
--> Nothing
toBool : Value -> Maybe Bool

Safely convert Value to a Bool

toBool (bool True)
--> Just True


toBool (string "foo")
--> Nothing
toFloat : Value -> Maybe Float

Safely convert Value to a Float

toFloat (float 1.6  )
--> Just 1.6


toFloat (int 1)
--> Nothing
toInt : Value -> Maybe Int

Safely convert Value to an Int

toInt (int 1  )
--> Just 1


toInt (float 1.0)
--> Nothing
toJson : Value -> Maybe Value

Safely convert Value to a Json.Encode.Value toJson (json Encode.null ) --> Just Encode.null

toJson (bool True)
--> Nothing
toStringUnsafe : Value -> String

Return a String representation of a Value.

toStringUnsafe empty
--> ""


toStringUnsafe (bool True)
--> "true"


toStringUnsafe (float 1.6)
--> "1.6"


toStringUnsafe (int 2)
--> "2"


toStringUnsafe (string "foo")
--> "foo"


toStringUnsafe (json (Encode.object [ ("foo", Encode.string "bar" ) ]))
--> "{\"foo\":\"bar\"}"