recode
Data conversion between various formats
Import
_ <- fat.recode
type package is automatically imported with this import
Constants
- numeric, regex definition used by
inferType
Variables
These settings can be adjusted to configure the behavior of the processing functions:
- csvSeparator, default is
,
(comma) - csvReplacement, default is empty (just removes commas from text)
- xmlWarnings, default is
true
- set tofalse
to suppress XML warnings
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 | (_: Any): Text | Encode JSON from native types |
fromJSON | (json: Text): Any | Decode JSON to native types |
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 URL encoded Form Data from scope |
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 bytoCSV
as replacement in case acsvSeparator
is found within a text being encoded
XML functions (rudimentary)
XML attributes and self-closing tags are not supported.
Name | Signature | Brief |
---|---|---|
toXML | (node: Any): Text | Encode XML from native types |
fromXML | (text: Text): Any | Decode XML into native types |
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 boolean/number if applicable |
minify | (src: Text): Text | Minifies JSON and FatScript sources |
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.
XML
Building XML from native types:
data = {
bookstore: [
{ book: { title: 'Book 1', author: 'Author 1' } }
]
}
xmlString = recode.toXML(data)
# xmlString will be the xml representation of the data
toXML
generates xml string from FatScript data structures
Parsing XML back into native types:
xmlData =
'<bookstore><book><title>Book 1</title><author>Author 1</author></book></bookstore>'
parsedData = recode.fromXML(xmlData)
# parsedData will be a Scope containing the parsed xml data
lists are automatically inferred when multiple sibling items are present, which might lead to inconsistent data structures in cases where an element is expected to be a list but occasionally contains only a single item, or even none