Skip to content

isBase64Image()

Returns true when str is a data URL that decodeDataUrl can parse and the MIME type starts with image/ (e.g. image/png, image/jpeg). Requires both a non-empty Base64 payload and an image MIME — arbitrary data:text/plain;base64,... is false.

Examples:

ts
isBase64Image('data:image/png;base64,iVBORw0KGgo='); // true
ts
isBase64Image('https://example.com/x.png'); // false
isBase64Image('data:text/plain;base64,SGk='); // false

Released under the MIT License.