arnau/elm-objecthash/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Objecthash.Hash

Functions to hash values.

Types

type alias ByteList =
List Int

A list of bytes.

Convert from and to lists of bytes.

bytes : Value -> ByteList

Hash an Objecthash Value.

bytes VNull == [27,22,177,223,83,139,161,45,195,249,126,219,184,92,170,112,80,212,108,20,129,52,41,15,235,168,15,130,54,200,61,185]
toHex : ByteList -> String

Transform a list of bytes into its hexadecimal string representation.

(toHex [27,22,177,223,83,139,161,45,195,249,126,219,184,92,170,112,80,212,108,20,129,52,41,15,235,168,15,130,54,200,61,185]) == "1b16b1df538ba12dc3f97edbb85caa7050d46c148134290feba80f8236c83db9"

Primitives

unicode : String -> ByteList

Hashes a unicode string.

toHex (unicode "foo") == "a6a6e5e783c363cd95693ec189c2682315d956869397738679b56305f2095038"
redacted : String -> ByteList

Hashes a redacted stringified list of bytes.

toHex (redacted "**REDACTED**480499ec4efe0e177793c217c8227d4096d2352beee2d6816ba8f4e8a421a138") == "480499ec4efe0e177793c217c8227d4096d2352beee2d6816ba8f4e8a421a138"
null : ByteList

Hashes a null value.

toHex null == "1b16b1df538ba12dc3f97edbb85caa7050d46c148134290feba80f8236c83db9"
int : Int -> ByteList

Hashes an integer.

toHex (int 6) == "396ee89382efc154e95d7875976cce373a797fe93687ca8a27589116644c4bcd"
float : Float -> ByteList

Hashes a float number. Note this function normalises values following the same algorithm implemented in the original Objecthash implementation.

toHex (float 6.1) == "43f5ebd1617989a69b819ed3a246c9e59468d6db90c29abdd3c8c1f17ffc365a"
bool : Bool -> ByteList

Hashes a boolean.

toHex (bool True) == "7dc96f776c8423e57a2785489a3f9c43fb6e756876d6ad9a9cac4aa4e72ec193"

Collection primitives

list : List ByteList -> ByteList

Hashes a list of ByteList.

[unicode "foo", int 6]
    |> list
    |> toHex
== "28dbb78890fb7b0462c62de04bcf165c69bd65b9f992f2edd89ae7369afa7005"
set : List ByteList -> ByteList

Hashes a set of ByteList. Note that this function receives a List but treats it as a Set (i.e. removes duplicates).

[unicode "foo", int 6]
    |> set
    |> toHex
== "cf38664185ed5377fee384d0a37bdb36681a16d72480f21336e38a493a8851b9"
dict : Dict String ByteList -> ByteList

Hahes a dictionary of ByteList.

Dict.fromList [("foo", int 1)]
    |> dict
    |> toHex
== "bf4c58f5e308e31e2cd64bdbf7a01b9b595a13602438be5e912c7d94f6d8177a"