Functions
Encoding Functions
Functions for encoding and decoding data.
Base64 Encoding
Base64 encoding and decoding functions are used to encode or decode binary data, especially for storage and transfer over text-based media.
decode base64
The dec::base64 function decodes a Base64 encoded string back into the original string.
dec::base64("SGVsbG8gV29ybGQ=")
# Result: "Hello World"
encode base64
The enc::base64 function encodes a given string into Base64.
enc::base64("Hello World")
# Result: "SGVsbG8gV29ybGQ="
encode base64_gzip
The enc::base64_gzip function compresses a string using gzip and then encodes the result in Base64.
enc::base64_gzip("Hello World")
# Example Result: "H4sIAAAAAAAA/ytJLS4BAAx+f9gEAAAA"
encode file_base64
The enc::file_base64 function reads a file's contents and returns them as a Base64-encoded string.
enc::file_base64("${path.module_dir}/hello.txt")
# Example Result: "SGVsbG8gV29ybGQ="
encode file_base64_sha256
The enc::file_base64_sha256 function computes the SHA256 hash of a string and encodes it in Base64.
enc::file_base64_sha256("hello world")
# Result: "uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="
encode file_base64_sha512
The enc::file_base64_sha512 function computes the SHA512 hash of a string and encodes it in Base64.
enc::file_base64_sha512("hello world")
# Result: "MJ7MSJwS1utMxA9QyQLytNDtd+5RGnx6m808qG1M2G+YndNbxf9JlnDaNCVbRbDP2DDoH2Bdz33FVC6TrpzXbw=="
Data Format Encoding
Data format decoding and encoding functions assist with handling data in formats like CSV, JSON, and YAML.
decode csv
The dec::csv function decodes a CSV-formatted string into a list of maps.
dec::csv("a,b,c\n1,2,3\n4,5,6")
# Result:
# [
# {"a" = "1", "b" = "2", "c" = "3"},
# {"a" = "4", "b" = "5", "c" = "6"}
# ]
encode csv
The enc::csv function converts a list of records into a CSV encoded string.
enc::csv([["name", "age", "city"], ["Alice", "30", "New York"], ["Bob", "25", "Los Angeles"]])
# Example Result: "name,age,city\nAlice,30,New York\nBob,25,Los Angeles"
decode json
The dec::json function interprets a string as JSON and returns the decoded representation.
dec::json("{\"hello\": \"world\"}")
# Result: {"hello" = "world"}
encode json
The enc::json function encodes a value into a JSON string.
enc::json({"hello"="world"})
# Result: "{\"hello\":\"world\"}"
decode yaml
The dec::yaml function parses a YAML string and returns its value representation.
dec::yaml("hello: world")
# Result: {"hello" = "world"}
encode yaml
The enc::yaml function encodes a value into a YAML string.
enc::yaml({"a":"b", "c":"d"})
# Result:
# "a": "b"
# "c": "d"
URL Encoding
URL encoding provides functions for URL encoding.
encode url
The enc::url function applies URL encoding to a string.
enc::url("Hello World!")
# Result: "Hello+World%21"