UNPKG

1.06 kBSource Map (JSON)View Raw
1{"version":3,"file":"correctHex.js","sourceRoot":"../src/","sources":["utilities/color/correctHex.ts"],"names":[],"mappings":";;;AAAA,mCAA0D;AAE1D;;;;GAIG;AACH,SAAgB,UAAU,CAAC,GAAW;IACpC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,uBAAc,EAAE;QACvC,OAAO,QAAQ,CAAC,CAAC,sCAAsC;KACxD;IACD,IAAI,GAAG,CAAC,MAAM,IAAI,uBAAc,EAAE;QAChC,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,uBAAc,CAAC,CAAC;KACzC;IACD,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,uBAAc,CAAC,CAAC;AAC1C,CAAC;AARD,gCAQC","sourcesContent":["import { MIN_HEX_LENGTH, MAX_HEX_LENGTH } from './consts';\n\n/**\n * Corrects a hex color to have length 3 or 6. Defaults to white if too short.\n * Does NOT check anything besides the length (such as valid characters) and does NOT handle\n * hex values starting with # sign.\n */\nexport function correctHex(hex: string): string {\n if (!hex || hex.length < MIN_HEX_LENGTH) {\n return 'ffffff'; // not a valid color--default to white\n }\n if (hex.length >= MAX_HEX_LENGTH) {\n return hex.substring(0, MAX_HEX_LENGTH);\n }\n return hex.substring(0, MIN_HEX_LENGTH);\n}\n"]}
\No newline at end of file