We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
isColor
1 parent b1a04fc commit 514f6caCopy full SHA for 514f6ca
src/lib/utils/typeUtils.ts
@@ -79,13 +79,15 @@ export function isTimestamp(value: unknown): boolean {
79
* Source: https://stackoverflow.com/questions/6386090/validating-css-color-names/33184805
80
*/
81
export function getColorCSS(color: string): string | null {
82
- const div = window.document.createElement('div')
+ colorTestDiv = colorTestDiv || window.document.createElement('div')
83
84
- div.style.color = color
+ colorTestDiv.style.color = ''
85
+ colorTestDiv.style.color = color
86
- const applied = div.style.color
87
+ const applied = colorTestDiv.style.color
88
return applied !== '' ? applied.replace(/\s+/g, '').toLowerCase() : null
89
}
90
+let colorTestDiv: HTMLDivElement | null = null
91
92
/**
93
* Test if a string contains a valid color name or code.
0 commit comments