Fixed blackorwhite invalid argument crash
This commit is contained in:
parent
a5d7a35fdc
commit
fe9fdb9384
@ -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>
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.23.8",
|
||||
"version": "0.23.9",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user