Comparing version 1.1.5 to 2.0.0
@@ -7,14 +7,14 @@ var iconv = require('iconv-lite'); | ||
var urldecodeBuffer = function(urlencoded){ | ||
var arrBuffers = urlencoded.split( | ||
var urldecodeBuffer = urlencoded => Buffer.concat( | ||
// an Array of Buffers is generated from various parts of `urlencoded`: | ||
urlencoded.split( | ||
/(%[0-9A-Fa-f]{2})/ | ||
).map(function(fragment, idx){ | ||
).map((fragment, idx) => { | ||
if( idx % 2 === 0 ){ // simple string fragment's index: 0, 2, 4... | ||
return new Buffer(fragment, 'binary'); | ||
return Buffer.from(fragment, 'binary'); | ||
} else { // regex-captured fragment's index: 1, 3, 5... | ||
return new Buffer(fragment.replace(/%/g, ''), 'hex'); | ||
return Buffer.from(fragment.replace(/%/g, ''), 'hex'); | ||
} | ||
}); | ||
return Buffer.concat(arrBuffers); | ||
}; | ||
}) | ||
); | ||
@@ -28,5 +28,6 @@ Dauria.prototype.getBase64DataURI = function(sourceBuffer, MIME){ | ||
Dauria.prototype.parseDataURI = function(dataURI){ | ||
if( dataURI.indexOf('data:') !== 0 ){ | ||
throw new Error(this.errors.MISSING_PREFIX); | ||
} | ||
if(!( dataURI.startsWith('data:') )) throw new Error( | ||
this.errors.MISSING_PREFIX | ||
); | ||
var commaSplit = dataURI.slice('data:'.length).split(','); | ||
@@ -49,3 +50,3 @@ if( commaSplit.length < 2 ) throw new Error(this.errors.MISSING_COMMA); | ||
if( base64 ){ | ||
decodedBuffer = new Buffer(encodedData, 'base64'); | ||
decodedBuffer = Buffer.from(encodedData, 'base64'); | ||
} else { // not base64, i.e. urlencoded | ||
@@ -59,3 +60,3 @@ decodedBuffer = urldecodeBuffer(encodedData); | ||
var mediaType = semicolonSplit.join(';'); | ||
if( MIME.toLowerCase().indexOf('text/') !== 0 ){ // not a text | ||
if(!( MIME.toLowerCase().startsWith('text/') )){ // not a text | ||
return { | ||
@@ -71,4 +72,4 @@ 'MIME': MIME, | ||
semicolonSplit.shift(); | ||
semicolonSplit = semicolonSplit.map(function(urlparam){ | ||
if( urlparam.toLowerCase().indexOf('charset=') !== 0 ){ | ||
semicolonSplit = semicolonSplit.map(urlparam => { | ||
if(!( urlparam.toLowerCase().startsWith('charset=') )){ | ||
return null; // not a charset parameter, drop it | ||
@@ -78,5 +79,3 @@ } | ||
return charset; | ||
}).filter(function(charset){ | ||
return charset !== null; | ||
}); | ||
}).filter(charset => charset !== null); | ||
if( semicolonSplit.length === 0 ) semicolonSplit = ['US-ASCII']; | ||
@@ -83,0 +82,0 @@ var decodedText; |
{ | ||
"name": "dauria", | ||
"main": "dauria.js", | ||
"version": "1.1.5", | ||
"version": "2.0.0", | ||
"description": "Node.js module for Data URI applications. It performs conversions between Node.js Buffers and RFC2397-compliant Data URIs, or vice versa.", | ||
@@ -6,0 +6,0 @@ "keywords": ["data uri", "data url", "data uris", "data urls", "rfc2397", "rfc 2397"], |
This Node.js module for <b>Da</b>ta <b>URI a</b>pplications is called **Dauria** (after a part of [Transbaikal](http://en.wikipedia.org/wiki/Transbaikal)). | ||
It performs conversions between Node.js [Buffers](http://nodejs.org/docs/latest/api/buffer.html) and [RFC2397-compliant](http://tools.ietf.org/html/rfc2397) Data URIs, or vice versa. | ||
Dauria performs conversions between Node.js [Buffers](http://nodejs.org/docs/latest/api/buffer.html) and [RFC2397-compliant](http://tools.ietf.org/html/rfc2397) Data URIs, or vice versa. | ||
It is tested against Node.js v0.10.x, Node.js v0.12.x, Node.js v4, Node.js v5, Node.js v6 and the latest stable version of Node.js. | ||
Dauria is written in JavaScript and requires [Node.js](http://nodejs.org/) to run. | ||
* Starting from v2.0.0, Dauria requires Node.js version 5.10.0 or newer because it is rewritten in ECMAScript 2015 (ES6) and also uses the [`Buffer.from`](https://nodejs.org/docs/latest/api/buffer.html#buffer_class_method_buffer_from_string_encoding) method. | ||
* You may run older versions of Dauria (that precede v2.0.0) with older Node.js versions (0.10.x or 0.12.x). However, those older versions of Node.js are themselves not maintained by their developers after 2016-12-31. | ||
Dauria is tested against Node.js v5, Node.js v6, Node.js v7 and the latest stable version of Node.js. | ||
## Installing Dauria | ||
@@ -8,0 +12,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
11541
78
85