Socket
Socket
Sign inDemoInstall

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

A simple Data URI scheme generator


Version published
Weekly downloads
234K
decreased by-2.13%
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

FAQs

Package last updated on 05 Feb 2014

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