{"version":3,"sources":["../src/index.ts"],"names":["useDeepCompareMemo","stringify","dashify"],"mappings":";;;;;;;;;;;AAwBO,SAAS,kBAA+C,KAAA,EAAiC;AAC9F,EAAA,OAAOA,iCAAA;AAAA,IACL,SAAS,gBAAA,GAAmB;AAC1B,MAAA,OAAO,MAAA,CAAO,KAAK,KAAK,CAAA,CAAE,OAAO,SAAS,gBAAA,CAAiB,MAA8B,GAAA,EAAK;AAC5F,QAAA,MAAM,KAAA,GAAQC,0BAAA,CAAU,KAAA,CAAM,GAAG,CAAC,CAAA;AAElC,QAAA,IAAI,CAAC,OAAO,OAAO,IAAA;AACnB,QAAA,IAAI,CAAC,GAAA,CAAI,UAAA,CAAW,OAAO,CAAA,QAAS,OAAA,GAAU,GAAA;AAE9C,QAAA,IAAA,CAAKC,wBAAA,CAAQ,GAAG,CAAC,CAAA,GAAI,KAAA;AACrB,QAAA,OAAO,IAAA;AAAA,MACT,CAAA,EAAG,EAAE,CAAA;AAAA,IACP,CAAA;AAAA,IACA,CAAC,KAAK;AAAA,GACR;AACF","file":"index.cjs","sourcesContent":["import { useDeepCompareMemo } from 'use-deep-compare';\nimport { stringify } from '@bento/to-attribute-value';\nimport { UnknownObject } from '@bento/types';\nimport dashify from 'dashify';\n\n/**\n * Transforms the keys of a given type to be prefixed with 'data-' and ensures the values are strings.\n *\n * @template Type - The original type whose keys will be transformed.\n * @typedef {Object} DataPrefix\n * @property {string} [data-${string & Property}] - The transformed keys prefixed with 'data-' and their corresponding string values.\n */\ntype DataPrefix<Type> = {\n  [Property in keyof Type as `data-${string & Property}`]: string;\n};\n\n/**\n * A custom hook that generates data attributes from the given props object.\n * It uses deep comparison memoization to optimize performance.\n *\n * @param {object} props - The input object containing key-value pairs to be converted into data attributes.\n * @returns {object} - An object with keys formatted as data attributes and their corresponding stringified values.\n * @public\n */\nexport function useDataAttributes<Props extends UnknownObject>(props: Props): DataPrefix<Props> {\n  return useDeepCompareMemo(\n    function createAttributes() {\n      return Object.keys(props).reduce(function reduceAttributes(data: Record<string, string>, key) {\n        const value = stringify(props[key]);\n\n        if (!value) return data;\n        if (!key.startsWith('data-')) key = 'data-' + key;\n\n        data[dashify(key)] = value;\n        return data;\n      }, {}) as DataPrefix<Props>;\n    },\n    [props]\n  );\n}\n"]}