Skip to content

decodeDataUrl()

Parses a data: URL of the form data:<mime>;base64,<payload> into its MIME type and raw Base64 body (without the data:...;base64, prefix). Non-matching strings yield undefined fields in the result object.

Examples:

ts
const { mimeType, data } = decodeDataUrl('data:image/png;base64,iVBORw0KGgo=');
// mimeType === 'image/png', data === 'iVBORw0KGgo='
ts
decodeDataUrl('not-a-data-url'); // { mimeType: undefined, data: undefined }

Released under the MIT License.