{"version":3,"file":"normalise-dataset.mjs","sources":["../../../src/govuk/common/normalise-dataset.mjs"],"sourcesContent":["/* eslint-disable es-x/no-string-prototype-trim -- Polyfill imported */\n\nimport '../vendor/polyfills/Element/prototype/dataset.mjs'\nimport '../vendor/polyfills/String/prototype/trim.mjs'\n\n/**\n * Normalise string\n *\n * 'If it looks like a duck, and it quacks like a duck…' 🦆\n *\n * If the passed value looks like a boolean or a number, convert it to a boolean\n * or number.\n *\n * Designed to be used to convert config passed via data attributes (which are\n * always strings) into something sensible.\n *\n * @deprecated Will be made private in v5.0\n * @param {string} value - The value to normalise\n * @returns {string | boolean | number | undefined} Normalised data\n */\nexport function normaliseString (value) {\n if (typeof value !== 'string') {\n return value\n }\n\n var trimmedValue = value.trim()\n\n if (trimmedValue === 'true') {\n return true\n }\n\n if (trimmedValue === 'false') {\n return false\n }\n\n // Empty / whitespace-only strings are considered finite so we need to check\n // the length of the trimmed string as well\n if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) {\n return Number(trimmedValue)\n }\n\n return value\n}\n\n/**\n * Normalise dataset\n *\n * Loop over an object and normalise each value using normaliseData function\n *\n * @deprecated Will be made private in v5.0\n * @param {DOMStringMap} dataset - HTML element dataset\n * @returns {Object} Normalised dataset\n */\nexport function normaliseDataset (dataset) {\n /** @type {Object} */\n var out = {}\n\n for (var key in dataset) {\n out[key] = normaliseString(dataset[key])\n }\n\n return out\n}\n"],"names":[],"mappings":";;;AAAA;AACA,AAGA;;;;;;;;;;;;;;;;AAgBA,AAAO,SAAS,eAAe,EAAE,KAAK,EAAE;EACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;IAC7B,OAAO,KAAK;GACb;;EAED,IAAI,YAAY,GAAG,KAAK,CAAC,IAAI,GAAE;;EAE/B,IAAI,YAAY,KAAK,MAAM,EAAE;IAC3B,OAAO,IAAI;GACZ;;EAED,IAAI,YAAY,KAAK,OAAO,EAAE;IAC5B,OAAO,KAAK;GACb;;;;EAID,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE;IAC7D,OAAO,MAAM,CAAC,YAAY,CAAC;GAC5B;;EAED,OAAO,KAAK;CACb;;;;;;;;;;;AAWD,AAAO,SAAS,gBAAgB,EAAE,OAAO,EAAE;;EAEzC,IAAI,GAAG,GAAG,GAAE;;EAEZ,KAAK,IAAI,GAAG,IAAI,OAAO,EAAE;IACvB,GAAG,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,EAAC;GACzC;;EAED,OAAO,GAAG;CACX;;;;"}