🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

data-urls

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-urls

Parses data: URLs

5.0.0
latest
Version published
Weekly downloads
32M
-11.51%
Maintainers
6
Weekly downloads
 
Created

What is data-urls?

The data-urls npm package is used to parse and serialize data URLs as per the WHATWG specification. It allows you to work with data URLs in a structured way, extracting components like MIME type, base64 encoding, and the actual data.

What are data-urls's main functionalities?

Parsing Data URLs

This feature allows you to parse a data URL into its components. The `parse` function takes a data URL string and returns an object containing the MIME type, whether it's base64 encoded, and the actual data.

const { parse } = require('data-urls');
const dataUrl = 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==';
const parsed = parse(dataUrl);
console.log(parsed);

Serializing Data URLs

This feature allows you to serialize data into a data URL. The `serialize` function takes an object with MIME type and data, and returns a data URL string.

const { serialize } = require('data-urls');
const data = Buffer.from('Hello, World!');
const mimeType = 'text/plain';
const serialized = serialize({ mimeType, body: data });
console.log(serialized);

Other packages similar to data-urls

FAQs

Package last updated on 11 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