Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/data-urls

Package Overview
Dependencies
Maintainers
1
Versions
7
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

  • 3.0.4
  • ts4.5
  • ts4.6
  • ts4.7
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • ts5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27K
increased by13.56%
Maintainers
1
Weekly downloads
 
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 07 Nov 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc