Fixed blackorwhite invalid argument crash
This commit is contained in:
parent
a5d7a35fdc
commit
fe9fdb9384
@ -8,7 +8,7 @@
|
|||||||
<script type="module">
|
<script type="module">
|
||||||
import {formatDate} from './dist/index.mjs';
|
import {formatDate} from './dist/index.mjs';
|
||||||
|
|
||||||
console.log(formatDate('D MMM, YYYY'));
|
console.log(formatDate('YYYY-01-01'));
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.23.8",
|
"version": "0.23.9",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* @return {"white" | "black"} Color with the most contrast
|
* @return {"white" | "black"} Color with the most contrast
|
||||||
*/
|
*/
|
||||||
export function blackOrWhite(background: string): 'white' | 'black' {
|
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';
|
if(!exploded) return 'black';
|
||||||
const [r, g, b] = exploded.map(hex => parseInt(hex, 16));
|
const [r, g, b] = exploded.map(hex => parseInt(hex, 16));
|
||||||
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
||||||
|
Loading…
Reference in New Issue
Block a user