diff --git a/image-to-base64.js b/image-to-base64.js index 1ba3492..32a98d4 100644 --- a/image-to-base64.js +++ b/image-to-base64.js @@ -16,7 +16,7 @@ const image2base64 = (url, param) => { ) .then( (buffer) => { - return "data:image/jpeg;base64," + window.btoa( + return window.btoa( [].slice.call( new Uint8Array(buffer) ).map( diff --git a/index.js b/index.js index 8761ae9..83676e7 100644 --- a/index.js +++ b/index.js @@ -15,12 +15,8 @@ const image2base64 = (param) => { let validTypeImage = new RegExp("(\.(jpg)|\.(png)|\.(jpeg))", "gi"); if(validTypeImage.test(param)){ - if(fs.statSync(param).isFile()){ - resolve( - fs.readFileSync( - path.resolve(param) - ).toString("base64") - ); + if(fs.statSync(param).isFile() === true){ + resolve(fs.readFileSync(path.resolve(param)).toString("base64")); }else{ reject(null); } @@ -40,9 +36,7 @@ const image2base64 = (param) => { ) .then( (body) => { - resolve( - body.toString("base64") - ); + resolve(body.toString("base64")); } ); diff --git a/test/index.js b/test/index.js index 07db574..109612c 100644 --- a/test/index.js +++ b/test/index.js @@ -15,7 +15,7 @@ describe("must to be resolved the promise", function(){ assert(validBase64.test(data), true); } ) - .catch((err)=>assert(err, true)); + .catch((err) => assert(err, true)); }); it("get image of the path and convert to base64", function(){ @@ -25,7 +25,7 @@ describe("must to be resolved the promise", function(){ assert(validBase64.test(data).test(data), true); } ) - .catch((err)=>assert(err, true)); + .catch((err) => assert(err, true)); }); }); \ No newline at end of file