Socket
Socket
Sign inDemoInstall

data-uri-to-buffer

Package Overview
Dependencies
0
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.2.0

7

History.md
1.2.0 / 2017-07-18
==================
* Essentially identical to v1.0.0. Reverting changes from v1.1.0 because they are breaking changes and should be part of a major version bump
* Revert "More correct media type handling"
* Revert "add typings for Typescript"
1.1.0 / 2017-07-17

@@ -3,0 +10,0 @@ ==================

23

index.js

@@ -32,21 +32,11 @@ 'use strict';

var type = meta[0] || 'text/plain';
var typeFull = type;
var base64 = false;
var charset = '';
for (var i = 1; i < meta.length; i++) {
var charset = 'US-ASCII';
for (var i = 0; i < meta.length; i++) {
if ('base64' == meta[i]) {
base64 = true;
} else {
typeFull += ';' + meta[i];
if (0 == meta[i].indexOf('charset=')) {
charset = meta[i].substring(8);
}
} else if (0 == meta[i].indexOf('charset=')) {
charset = meta[i].substring(8);
}
}
// defaults to US-ASCII only if type is not provided
if (!meta[0] && !charset.length) {
typeFull += ';charset=US-ASCII';
charset = 'US-ASCII';
}

@@ -59,5 +49,4 @@ // get the encoded data portion and decode URI-encoded chars

// set `.type` and `.typeFull` properties to MIME type
buffer.type = type;
buffer.typeFull = typeFull;
// set `.type` property to MIME type
buffer.type = meta[0] || 'text/plain';

@@ -64,0 +53,0 @@ // set the `.charset` property

{
"name": "data-uri-to-buffer",
"version": "1.1.0",
"version": "1.2.0",
"description": "Generate a Buffer instance from a Data URI string",
"main": "index.js",
"types": "index.d.ts",
"scripts": {

@@ -30,5 +29,2 @@ "test": "mocha --reporter spec"

"homepage": "https://github.com/TooTallNate/node-data-uri-to-buffer",
"dependencies": {
"@types/node": "^8.0.7"
},
"devDependencies": {

@@ -35,0 +31,0 @@ "mocha": "^3.4.2"

@@ -45,19 +45,11 @@ data-uri-to-buffer

The `type` property on the Buffer instance gets set to the main type portion of
The `type` property on the Buffer instance gets set to the Content-Type portion of
the "mediatype" portion of the "data" URI, or defaults to `"text/plain"` if not
specified.
The `typeFull` property on the Buffer instance gets set to the entire
"mediatype" portion of the "data" URI (including all parameters), or defaults
to `"text/plain;charset=US-ASCII"` if not specified.
The `charset` property on the Buffer instance gets set to the Charset portion of
the "mediatype" portion of the "data" URI, or defaults to `"US-ASCII"` if the
entire type is not specified, or defaults to `""` otherwise.
the "mediatype" portion of the "data" URI, or defaults to `"US-ASCII"` if not
specified.
*Note*: If the only the main type is specified but not the charset, e.g.
`"data:text/plain,abc"`, the charset is set to the empty string. The spec only
defaults to US-ASCII as charset if the entire type is not specified.
License

@@ -64,0 +56,0 @@ -------

@@ -16,4 +16,2 @@

assert.equal('text/plain', buf.type);
assert.equal('text/plain;charset=US-ASCII', buf.typeFull);
assert.equal('US-ASCII', buf.charset);
assert.equal('Hello, World!', buf.toString());

@@ -131,47 +129,2 @@ });

it('should not default to US-ASCII if main type is provided', function () {
var uri = 'data:text/plain,abc';
var buf = dataUriToBuffer(uri);
assert.equal('text/plain', buf.type);
assert.equal('text/plain', buf.typeFull);
assert.equal('', buf.charset);
assert.equal('abc', buf.toString());
});
it('should default to text/plain if main type is not provided', function () {
var uri = 'data:;charset=UTF-8,abc';
var buf = dataUriToBuffer(uri);
assert.equal('text/plain', buf.type);
assert.equal('text/plain;charset=UTF-8', buf.typeFull);
assert.equal('UTF-8', buf.charset);
assert.equal('abc', buf.toString());
});
it('should not allow charset without a leading ;', function () {
var uri = 'data:charset=UTF-8,abc';
var buf = dataUriToBuffer(uri);
assert.equal('charset=UTF-8', buf.type);
assert.equal('charset=UTF-8', buf.typeFull);
assert.equal('', buf.charset);
assert.equal('abc', buf.toString());
});
it('should allow custom media type parameters', function () {
var uri = 'data:application/javascript;version=1.8;charset=UTF-8,abc';
var buf = dataUriToBuffer(uri);
assert.equal('application/javascript', buf.type);
assert.equal('application/javascript;version=1.8;charset=UTF-8', buf.typeFull);
assert.equal('UTF-8', buf.charset);
assert.equal('abc', buf.toString());
});
it('should allow base64 annotation anywhere', function () {
var uri = 'data:text/plain;base64;charset=UTF-8,YWJj';
var buf = dataUriToBuffer(uri);
assert.equal('text/plain', buf.type);
assert.equal('text/plain;charset=UTF-8', buf.typeFull);
assert.equal('UTF-8', buf.charset);
assert.equal('abc', buf.toString());
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc