Détail du package

strong-data-uri

strongloop41kArtistic-2.01.0.6

Parser and builder for data: URIs

readme

strong-data-uri

Build Status NPM version

Overview

strong-data-uri implements a parser for retrieving data encoded in data: URIs specified by RFC2397, as well as an encoder for those URIs.

API

decode(uri)

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

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.

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.

changelog

2018-05-31, Version 1.0.6

  • Travis: add Node.js 10, remove legacy versions (Miroslav Bajtoš)

  • fix: reject data uris containing CR or LF (Mark Vayngrib)

2018-02-26, Version 1.0.5

  • Travis: add Node.js versions 4, 6 and 8 (Miroslav Bajtoš)

  • Update truncate from 1.x to 2.x (Miroslav Bajtoš)

  • Update URLs in CONTRIBUTING.md (#21) (Ryan Graham)

2016-05-03, Version 1.0.4

  • update/insert copyrights (Ryan Graham)

  • relicense as Artistic-2.0 only (Ryan Graham)

  • Refer to licenses with a link (Sam Roberts)

2015-09-21, Version 1.0.3

  • Consistent license expressions (Sam Roberts)

  • Correct SPDX identifier (Sebastiaan Deckers)

2015-09-09, Version 1.0.2

  • package: fix license field (Miroslav Bajtoš)

  • package.json: correct license info (Bert Belder)

2015-06-09, Version 1.0.1

  • Fix package.json: license, description (Miroslav Bajtoš)

2015-05-06, Version 1.0.0

  • Fix readme for #15 (Joe Hildebrand)

  • Change default mediatype for strings (Joe Hildebrand)

  • README: minor improvements (Miroslav Bajtoš)

  • Add mediatype, mimetype, and charset (Joe Hildebrand)

  • Add pointer to data-colon project (Joe Hildebrand)

2015-04-22, Version 0.2.0

  • Travis: install newer npm for Node 0.8 (Miroslav Bajtoš)

  • Travis: drop Node 0.11, add 0.12 and io.js (Miroslav Bajtoš)

  • Add encode (Joe Hildebrand)

  • Fix bad CLA URL in CONTRIBUTING.md (Ryan Graham)

  • Update contribution guidelines (Ryan Graham)

  • doc: add CONTRIBUTING.md and LICENSE.md (Ben Noordhuis)

  • Apply Dual MIT/StrongLoop license (Sam Roberts)

  • Ignore coverage artifacts (Ryan Graham)

  • Specify versions of devDependencies (Ryan Graham)

  • Replace blanket with istanbul (Ryan Graham)

2014-01-21, Version 0.1.1

  • First release!