Fixed blackorwhite invalid argument crash
All checks were successful
Build / Build NPM Project (push) Successful in 38s
Build / Tag Version (push) Successful in 8s
Build / Publish Documentation (push) Successful in 40s

This commit is contained in:
Zakary Timson 2025-02-03 14:20:18 -05:00
parent a5d7a35fdc
commit fe9fdb9384
3 changed files with 3 additions and 3 deletions

View File

@ -8,7 +8,7 @@
<script type="module">
import {formatDate} from './dist/index.mjs';
console.log(formatDate('D MMM, YYYY'));
console.log(formatDate('YYYY-01-01'));
</script>
</body>
</html>

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.23.8",
"version": "0.23.9",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@ -4,7 +4,7 @@
* @return {"white" | "black"} Color with the most contrast
*/
export function blackOrWhite(background: string): 'white' | 'black' {
const exploded = background.match(background.length >= 6 ? /\w\w/g : /\w/g);
const exploded = background?.match(background.length >= 6 ? /\w\w/g : /\w/g);
if(!exploded) return 'black';
const [r, g, b] = exploded.map(hex => parseInt(hex, 16));
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;