You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

datauri

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datauri

[Module](http://npm.im/datauri) and [Client](http://npm.im/datauri-cli) to generate [Data URI scheme][datauri].

1.0.1
Source
npmnpm
Version published
Weekly downloads
280K
6.77%
Maintainers
1
Weekly downloads
 
Created

What is datauri?

The datauri npm package is used to convert file paths or file buffers to Data URI scheme. This is particularly useful for embedding file data directly into HTML or CSS files.

What are datauri's main functionalities?

Convert File Path to Data URI

This feature allows you to convert a file path to a Data URI. The `format` method takes the file extension and the file path as arguments and returns an object containing the Data URI.

const Datauri = require('datauri');
const dUri = new Datauri();
const result = dUri.format('.png', 'path/to/file.png');
console.log(result.content);

Convert Buffer to Data URI

This feature allows you to convert a buffer to a Data URI. The `format` method takes the file extension and the buffer as arguments and returns an object containing the Data URI.

const Datauri = require('datauri');
const dUri = new Datauri();
const buffer = Buffer.from('some data');
const result = dUri.format('.txt', buffer);
console.log(result.content);

Convert File Path to Data URI (Async)

This feature allows you to convert a file path to a Data URI using an asynchronous method. The `promise` method takes the file path as an argument and returns a promise that resolves to the Data URI.

const Datauri = require('datauri');
const dUri = new Datauri();
const result = await dUri.promise('path/to/file.png');
console.log(result);

Other packages similar to datauri

Keywords

datauri

FAQs

Package last updated on 10 Feb 2016

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