🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@types/data-urls

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/data-urls

TypeScript definitions for data-urls

ts5.2
ts5.3
ts5.4
ts5.5
ts5.6
ts5.7
ts5.8
ts5.9
ts6.0
latest
Source
npmnpm
Version
3.0.5
Version published
Maintainers
1
Created
Source

Installation

npm install --save @types/data-urls

Summary

This package contains type definitions for data-urls (https://github.com/jsdom/data-urls#readme).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/data-urls.

index.d.ts

import MIMEType = require("whatwg-mimetype");
import { URLRecord } from "whatwg-url";

/**
 * Parses `data:` URLs.
 *
 * @param stringInput The `data:` URL to parse.
 * @returns The parsed data URL, or `null` if the result cannot be parsed as a `data:` URL.
 *
 * @example
 * import parseDataURL = require("data-urls");
 *
 * const textExample = parseDataURL("data:,Hello%2C%20World!");
 * console.log(textExample.mimeType.toString()); // "text/plain;charset=US-ASCII"
 * console.log(textExample.body);                // Uint8Array(13) [ 72, 101, 108, 108, 111, 44, … ]
 *
 * const htmlExample = parseDataURL("data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E");
 * console.log(htmlExample.mimeType.toString()); // "text/html"
 * console.log(htmlExample.body);                // Uint8Array(22) [ 60, 104, 49, 62, 72, 101, … ]
 *
 * const pngExample = parseDataURL("data:image/png;base64,iVBORw0KGgoAAA" +
 *                                 "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" +
 *                                 "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" +
 *                                 "5ErkJggg==");
 * console.log(pngExample.mimeType.toString()); // "image/png"
 * console.log(pngExample.body);                // Uint8Array(85) [ 137, 80, 78, 71, 13, 10, … ]
 */
declare function parseDataURL(stringInput: string): parseDataURL.DataURL | null;

declare namespace parseDataURL {
    interface DataURL {
        mimeType: MIMEType;
        body: Uint8Array;
    }

    /**
     * If you are using the [whatwg-url](https://github.com/jsdom/whatwg-url) package, you may already have a
     * "URL record" object on hand, as produced by that package's `parseURL` export. In that case, you can use
     * this function to save a bit of work.
     *
     * @example
     * import { parseURL } from "whatwg-url";
     * const dataURLFromURLRecord = require("data-urls").fromURLRecord;
     *
     * const urlRecord = parseURL("data:,Hello%2C%20World!");
     * const dataURL = dataURLFromURLRecord(urlRecord);
     */
    function fromURLRecord(urlRecord: URLRecord): DataURL | null;
}

export = parseDataURL;

Additional Details

Credits

These definitions were written by Jaime Filho, and BendingBender.

FAQs

Package last updated on 26 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts