# strong-data-uri

> Parser and builder for `data:` URIs

Latest version **1.0.6** (published 2018-05-31) · Artistic-2.0 license · 0 weekly downloads

## Install

```sh
npm install strong-data-uri
pnpm add strong-data-uri
yarn add strong-data-uri
bun add strong-data-uri
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-05-31 |
| First published | 2013-09-12 |
| Weekly downloads | 0 |
| License | Artistic-2.0 |
| TypeScript types | separate (@types/strong-data-uri) |
| Module format | CommonJS |
| Node | >=0.8.0 |
| Dependencies | 1 |
| Unpacked size | 24.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Miroslav Bajtos |
| Maintainers | 0candy, amir-61, b-admike, bajtos, davidcheung, hacksparrow, jannyhou2016, kjdelisle, kraman, qpresley, rfeng, ritch, rmg, superkhau, thegman, tonyf-ibm |

## Links

- npm: https://www.npmjs.com/package/strong-data-uri
- Repository: https://github.com/strongloop/strong-data-uri
- Homepage: https://github.com/strongloop/strong-data-uri#readme
- Issues: https://github.com/strongloop/strong-data-uri/issues
- npm.io page: https://npm.io/package/strong-data-uri

## Dependencies (1)

- [truncate](https://npm.io/package/truncate.md) ^2.0.1

## Recent versions

- 1.0.6 (latest) — 2018-05-31
- 1.0.5 — 2018-02-26
- 1.0.4 — 2016-05-04
- 1.0.3 — 2015-09-21
- 1.0.2 — 2015-09-09
- 1.0.1 — 2015-06-09
- 1.0.0 — 2015-05-06
- 0.2.0 — 2015-04-22
- 0.1.1 — 2014-01-21
- 0.1.0 — 2013-09-12

## README

# strong-data-uri

[![Build Status](https://travis-ci.org/strongloop/strong-data-uri.png?branch=master)](https://travis-ci.org/strongloop/strong-data-uri)
[![NPM version](https://badge.fury.io/js/strong-data-uri.png)](http://badge.fury.io/js/strong-data-uri)

## Overview
strong-data-uri implements a parser for retrieving data encoded
in `data:` URIs specified by [RFC2397](http://www.ietf.org/rfc/rfc2397.txt),
as well as an encoder for those URIs.

## API

 - [decode](#decodeuri)
 - [encode](#encodedata-mediatype)

### decode(uri)

Call `dataUri.decode(uri)` to parse the payload of a data URI. The `uri`
argument expects a string.

```js
var dataUri = require('strong-data-uri');
var uri = 'data:text/plain;charset=iso-8859-1;base64,aGVsbG8gd29ybGQ=';

var buffer = dataUri.decode(uri);
console.log(buffer);
// <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
console.log(buffer.toString('ascii'));
// Hello world

console.log(buffer.mimetype);  // text/plain
console.log(buffer.mediatype); // text/plain;charset=iso-8859-1
console.log(buffer.charset);   // iso-8859-1
```

### encode(data, [mediatype])

Use `dataUri.encode(data, mediatype)` to build a new data URI. The `data`
argument can be a `Buffer` or a `String`. Strings are converted to buffers
using `utf-8` encoding.

If `mediatype` is not specified, then `application/octet-stream` is used
as a default if the data is a Buffer, and `text/plain;charset=UTF-8` if
the data is a String.

```js
var dataUri = require('strong-data-uri');

uri = dataUri.encode('foo');
console.log(uri);
// data:text/plain;charset=UTF-8;base64,Zm9v

uri = dataUri.encode(new Buffer('<foo/>', 'utf8'), 'text/xml');
console.log(uri);
// data:text/xml;base64,PGZvby8+
```

## Command-line access

To keep this project small and light, no command-line tool is provided.  If you
need one, please consider [data-colon](https://github.com/hildjj/data-colon).

---
_Source: https://npm.io/package/strong-data-uri · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
