recode

Data conversion between various formats

Import

_ <- fat.recode

type package is automatically imported with this import

Variables

These settings can be used to adjust the behavior of the processing functions:

  • csvSeparator, default is , (comma)
  • csvReplacement, default is empty (just removes commas from text)

Base64 functions

Name Signature Brief
toBase64 (data: Chunk): Text Encode binary chunk to base64 text
fromBase64 (b64: Text): Chunk Decode base64 text to original format

JSON functions

Name Signature Brief
toJSON (val: Any): Text Encode JSON from native types
fromJSON (json: Text): Any Decode JSON to native types

with toJSON the native types such as HugeInt, Method, and Chunk will translate into null, while Errors will be converted into strings

URL functions

Name Signature Brief
toURL (text: Text): Text Encode text to URL escaped text
fromURL (url: Text): Text Decode URL escaped text to original format
toFormData (data: Scope): Text Encode scope to URL encoded Form Data
fromFormData (data: Text): Scope Decode URL encoded Form Data to scope

CSV functions

Name Signature Brief
toCSV (header: List/Text, rows: List/Scope): Text Encode CSV from rows
fromCSV (csv: Text): List/Scope Decode CSV into rows

csvReplacement is used by toCSV as replacement in case a csvSeparator is found within a text being encoded

RLE functions

Name Signature Brief
toRLE (chunk: Chunk): Chunk Compress to RLE schema
fromRLE (chunk: Chunk): Chunk Decompress from RLE schema

Other functions

Name Signature Brief
inferType (val: Text): Any Convert text to void/boolean/number
minify (src: Text): Text Minifies FatScript source code

minify will replace any $break statements (debugger breakpoint) with ()

Usage

JSON

Since FatScript alternatively accepts JSON-like syntax, fromJSON actually uses FatScript internal parser, which is blazing fast, but may or not yield exactly what one is expecting from a JSON parser.

For example, once the bellow fragment is parsed, since null in FatScript is absence of value, there would be no entry declarations for "prop":

"prop": null

Therefore, reading with fromJSON and writing back with toJSON is not necessarily an idempotent operation.

if you need a null property to be returned within the object's structure, consider using a custom type that represents the desired structure, with an optional property, e.g. T(prop = null)

XML

The XML functions were removed from the recode library in version 3.0.0. This functionality can now be obtained with the XMLoaf project.

See also

results matching ""

    No results matching ""