36373400f8
Validate blurhash hashes before passing them to react-blurhash's <Blurhash> component, which throws when the encoded length doesn't match the component count header. Malformed hashes from third-party events (e.g. length 92 instead of 94) now gracefully fall back to a skeleton placeholder instead of crashing the page.
8 lines
271 B
TypeScript
8 lines
271 B
TypeScript
import { isBlurhashValid } from 'blurhash';
|
|
|
|
/** Returns `true` when `hash` is a structurally valid blurhash string. */
|
|
export function isValidBlurhash(hash: string | undefined | null): hash is string {
|
|
if (!hash) return false;
|
|
return isBlurhashValid(hash).result;
|
|
}
|