Function parseAsAttributes

Parse data as attributes.

This is a first step of going from a relatively human-friendly simple array format into setting HTML attributes based on a CSS variable. The second step is to call setFromVariables

// Array of arrays is treated as a set of key-value pairs
const options = [ [`indicator-fill`, `gray`], [`backdrop-fill`, `whitesmoke`] ]
const attrs = parseAsAttributes(options);
Yields:
[
{ variable: `indicator-fill`, attribute: `fill`, id: `indicator`, defaultValue: `gray` }
{ variable: `backdrop-fill`, attribute: `fill`, id: `backdrop`, defaultValue: `whitesmoke` }
]

// Assign
setFromCssVariables(document.body, attrs);
  • Parameters

    • options: (string | string[])[]

    Returns (CssVariable & {
        id: string;
    })[]