@reventlessdev/rescript-hash-object
v1.2.0-alpha.11
Published
ReScript bindings for hash-object
Readme
@reventlessdev/rescript-hash-object
⚠️ Alpha. APIs and on-disk formats can change without notice between releases. Pin exact versions and expect breaking changes.
ReScript bindings for hash-obj.
Install
pnpm add @reventlessdev/rescript-hash-objectAdd it to your rescript.json dependencies:
{
"dependencies": ["@reventlessdev/rescript-hash-object"]
}API Documentation
hashDict
Generates a hash string from a dictionary object.
hashDict: (~dict: dict<string>, ~options: Options.t=?) => stringParameters:
dict: A dictionary with string values to hashoptions(optional): Configuration options for hash generation
Options
type Options.t = {
encoding?: encoding,
algorithm?: algorithm,
}encoding - Output encoding format:
Hex(default) - Hexadecimal stringBase64- Base64-encoded stringBuffer- Raw buffer outputLatin1- Latin1 string encoding
algorithm - Hash algorithm to use:
SHA256(default) - SHA-256 algorithmMD5- MD5 algorithmSHA1- SHA-1 algorithmSHA512- SHA-512 algorithm
Examples
Basic usage (default SHA256 with hex encoding)
open HashObj
let data = Dict.fromArray([("name", "Alice"), ("age", "30")])
let hash = hashDict(~dict=data)
// => "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918"Using different algorithms
open HashObj
let data = Dict.fromArray([("user", "bob"), ("id", "42")])
// MD5
let md5Hash = hashDict(~dict=data, ~options={algorithm: MD5})
// SHA1
let sha1Hash = hashDict(~dict=data, ~options={algorithm: SHA1})
// SHA512
let sha512Hash = hashDict(~dict=data, ~options={algorithm: SHA512})Using different encodings
open HashObj
let data = Dict.fromArray([("key", "value")])
// Hex encoding (default)
let hexHash = hashDict(~dict=data, ~options={encoding: Hex})
// Base64 encoding
let base64Hash = hashDict(~dict=data, ~options={encoding: Base64})
// Latin1 encoding
let latin1Hash = hashDict(~dict=data, ~options={encoding: Latin1})Combining algorithm and encoding
open HashObj
let data = Dict.fromArray([
("environment", "production"),
("version", "1.2.3"),
("region", "us-east-1"),
])
// SHA512 with Base64 encoding
let hash = hashDict(
~dict=data,
~options={
algorithm: SHA512,
encoding: Base64,
},
)Links
- 📚 Documentation — docs.reventless.dev
- 📦 Repository — ReventlessDev/reventless-core
- 📋 Changelog
