Corex.Dataset (Corex v0.2.0)

View Source

Encode multi-value datasets for Corex component data-* attributes.

Prefer encode_json/1 when passing lists or maps into the DOM (select, combobox, listbox, tags, tree-view, color picker presets, and similar).

Summary

Functions

Maps a boolean to "true" / "false" for dataset attributes.

JSON-encodes value for a dataset attribute, or nil when the value is nil (attribute omitted).

Maps a boolean to its string, and anything else to nil so the attribute is omitted. For dataset fields whose value reaches the library unvalidated.

Puts to_string(value) under key when value is not nil.

Functions

bool_str(bool)

@spec bool_str(boolean()) :: String.t()

Maps a boolean to "true" / "false" for dataset attributes.

encode_json(value)

@spec encode_json(term()) :: String.t() | nil

JSON-encodes value for a dataset attribute, or nil when the value is nil (attribute omitted).

optional_bool_str(value)

@spec optional_bool_str(term()) :: String.t() | nil

Maps a boolean to its string, and anything else to nil so the attribute is omitted. For dataset fields whose value reaches the library unvalidated.

put_string(map, key, value)

@spec put_string(map(), String.t(), term()) :: map()

Puts to_string(value) under key when value is not nil.