image-data-uri
Advanced tools
Comparing version 1.1.1 to 2.0.0
@@ -68,3 +68,3 @@ 'use strict'; | ||
function encodeFromURL(imageURL) { | ||
function encodeFromURL(imageURL, options) { | ||
return new Promise((resolve, reject) => { | ||
@@ -75,5 +75,6 @@ if (!imageURL) { | ||
} | ||
options = options || {}; | ||
request.get(imageURL, { | ||
encoding: null | ||
encoding: null, | ||
timeout: options.timeout || 6000 | ||
}, (err, response, body) => { | ||
@@ -85,2 +86,4 @@ if (err) { | ||
return resolve(ImageDataURI.encode(body, response.headers["content-type"])); | ||
} else { | ||
return reject('ImageDataURI :: Error :: GET -> ' + imageURL + ' returned an HTTP ' + response.statusCode + ' status!'); | ||
} | ||
@@ -87,0 +90,0 @@ }); |
{ | ||
"name": "image-data-uri", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "Library to easily decode/encode Data URI images", | ||
@@ -11,3 +11,3 @@ "main": "./lib/image-data-uri.js", | ||
"mime-types": "^2.1.18", | ||
"request": "^2.69.0" | ||
"request": "^2.88.0" | ||
}, | ||
@@ -14,0 +14,0 @@ "author": { |
@@ -43,2 +43,17 @@ const fs = require("fs-extra"); | ||
describe("encodeFromURL", () => { | ||
it("declares correct media type for a google logo", () => { | ||
return ImageDataURI.encodeFromURL("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png").then(dataURI => { | ||
const m = dataURI.match(matchMediaType); | ||
assert.equal("image/png", m[1]); | ||
}); | ||
}); | ||
it("fails on a 404 URL", () => { | ||
return ImageDataURI.encodeFromURL("http://150dcace0756dba5a895-b1479f7526781e2361a99185a4979d91.r53.cf1.rackcdn.com/library/assets/825127ec") | ||
.catch(err => { | ||
assert.ok(typeof err === 'string'); | ||
}); | ||
}); | ||
}); | ||
describe("outputFile", () => { | ||
@@ -45,0 +60,0 @@ const outputFilePath = `${__dirname}/tmp-output`; |
47722
157
Updatedrequest@^2.88.0