• Returns a CSS variable string from a plain object with key-value pairs.

    Remarks

    This function uses Object.entries() and Array.map() to generate a string with CSS variable declarations. The object keys are expected to be strings, while the values can be of any type. If the input object is not a plain object, an error is returned.

    Example

    const obj = { primaryColor: '#f00', secondaryColor: '#0f0', fontSize: '16px' };
    mapToCssVars(obj)
    // => { ok: true, value: '--primaryColor: #f00; --secondaryColor: #0f0; --fontSize: 16px;' }

    Example

    mapToCssVars('a')
    // => { ok: false, error: Error('[objects.mapToCssVars] Expected a plain javascript object') }

    Type Parameters

    • T extends Record<PropertyKey, any>

      The type of the input object.

    Parameters

    • obj: T

      The object to convert to a CSS variable string.

    Returns Result<string, Error>

    A Result object with either the CSS variable string, or an Error object is the given object is not a plain javascript object.

Generated using TypeDoc v0.24.7