image-data-uri
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -24,3 +24,3 @@ 'use strict'; | ||
let regExMatches = dataURI.match('data:image/(.*);base64,(.*)'); | ||
let regExMatches = dataURI.match('data:(image/.*);base64,(.*)'); | ||
return { | ||
@@ -94,3 +94,5 @@ imageType: regExMatches[1], | ||
let imageDecoded = decode(dataURI); | ||
filePath = (!!path.extname(filePath)) ? filePath : filePath + '.' + imageDecoded.imageType; | ||
filePath = (!!path.extname(filePath)) | ||
? filePath | ||
: filePath + '.' + mimeTypes.extension(imageDecoded.imageType); | ||
fs.outputFile(filePath, imageDecoded.dataBuffer, err => { | ||
@@ -97,0 +99,0 @@ if (err) { |
{ | ||
"name": "image-data-uri", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Library to easily decode/encode Data URI images", | ||
@@ -5,0 +5,0 @@ "main": "./lib/image-data-uri.js", |
@@ -1,4 +0,5 @@ | ||
var assert = require("assert"); | ||
const fs = require("fs-extra"); | ||
const assert = require("assert"); | ||
var ImageDataURI = require("../lib/image-data-uri"); | ||
const ImageDataURI = require("../lib/image-data-uri"); | ||
@@ -41,2 +42,17 @@ const matchMediaType = /^data:([^;,]+)[;,]/; | ||
}); | ||
describe("outputFile", () => { | ||
const outputFilePath = `${__dirname}/tmp-output`; | ||
const expectedOutputFile = `${__dirname}/tmp-output.svg`; | ||
it("writes image/svg+xml data to a file with .svg extension", () => { | ||
return ImageDataURI.encodeFromFile("test/test-file.svg") | ||
.then(dataURI => ImageDataURI.outputFile(dataURI, outputFilePath)) | ||
.then(outputPath => assert.equal(expectedOutputFile, outputPath)); | ||
}); | ||
after(function() { | ||
fs.removeSync(expectedOutputFile); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46876
139
2