tryParse
Like parse, but returns null instead of throwing when input is not a supported, well-formed CSS color (or not a string). Never throws.
import { tryParse } from '@pbroom/color-kit';parse.ts:326function tryParse( input: string,): Color | null;Parameters
- input
string - CSS color string
Returns
Color | nullThe parsed Color, or null
Example
import { toHex, tryParse } from '@pbroom/color-kit';
const color = tryParse('#3b82f6');
color && toHex(color); // → '#3b82f6'
tryParse('#gggggg'); // → null