@jossmac/lil-libs
    Preparing search index...

    Function toDataAttributes

    • Maps object properties to data-* attributes for DOM elements.

      CamelCase keys become kebab-case. Omits null and undefined values, and omits false and "" by default. Preserves 0. Trims a leading is from boolean-style keys by default (only when followed by an uppercase letter).

      • T extends object
      • props: T

        Object whose keys become data-* attribute names (camelCase → kebab-case).

      • options: { omitFalsyValues?: boolean; trimBooleanKeys?: boolean } = {}

        Controls omission of falsy values and trimming of is* prefixes from boolean-style keys.

        • OptionalomitFalsyValues?: boolean

          Omit props with values of false and "". Nullish values are always omitted, and values of 0 are valid in this situation.

          true
          
        • OptionaltrimBooleanKeys?: boolean

          Removes the is* prefix from keys, if present.

          true
          

      A record of data-* keys to values ready for spreading onto a DOM element.

      toDataAttributes({
      isSelected: true,
      panelIndex: 2,
      count: 0,
      empty: "",
      });
      // {
      // "data-selected": true,
      // "data-panel-index": 2,
      // "data-count": 0,
      // }

      toDataAttributes({ isHidden: false, label: "Save" }, { omitFalsyValues: false });
      // { "data-hidden": false, "data-label": "Save" }