image-to-base64
Advanced tools
| # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
| # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
| name: Tests | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize] | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| node-version: [8.x, 10.x, 12.x] | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v1 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - run: npm install -g mocha | ||
| - run: npm install | ||
| - run: npm test |
+21
| 'use strict'; | ||
| (function(escope) { | ||
| function base64ToBrowser(buffer) { | ||
| return window.btoa([].slice.call(new Uint8Array(buffer)).map(function(bin) { return String.fromCharCode(bin); }).join('')); | ||
| } | ||
| function imageToBase64Browser(urlOrImage, param) { | ||
| if (!('fetch' in window && 'Promise' in window)) { | ||
| return Promise.reject('[*] It\'s image2base64 not compatible with your browser.'); | ||
| } | ||
| return fetch(urlOrImage, param || {}).then(function(response) { | ||
| return response.arrayBuffer(); | ||
| }).then(base64ToBrowser); | ||
| } | ||
| if (typeof module !== 'undefined') { | ||
| module.exports = imageToBase64Browser; | ||
| } else { | ||
| escope.imageToBase64 = imageToBase64Browser; | ||
| } | ||
| })(this); |
| "use strict";!function(e){function t(e){return window.btoa([].slice.call(new Uint8Array(e)).map(function(e){return String.fromCharCode(e)}).join(""))}function n(e,n){return"fetch"in window&&"Promise"in window?fetch(e,n||{}).then(function(e){return e.arrayBuffer()}).then(t):Promise.reject("[*] It's image2base64 not compatible with your browser.")}"undefined"!=typeof module?module.exports=n:e.imageToBase64=n}(this); |
+0
-0
@@ -0,0 +0,0 @@ # http://editorconfig.org |
+0
-0
| language: node_js | ||
| node_js: | ||
| - "9" |
+39
-67
@@ -1,72 +0,44 @@ | ||
| (function(escope){ | ||
| "use strict"; | ||
| function validUrl (url) { | ||
| return /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi.test(url); | ||
| 'use strict'; | ||
| function validUrl(url) { | ||
| return /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi.test(url); | ||
| } | ||
| function validTypeImage(image) { | ||
| return /(\.(jpg)|\.(png)|\.(jpeg))/gi.test(image); | ||
| } | ||
| function base64ToNode(buffer) { | ||
| return buffer.toString('base64'); | ||
| } | ||
| function readFileAndConvert(fileName) { | ||
| var fileSystem = require('fs'); | ||
| var path = require('path'); | ||
| if (fileSystem.statSync(fileName).isFile()) { | ||
| return base64ToNode(fileSystem.readFileSync(path.resolve(fileName)).toString('base64')); | ||
| } | ||
| function validTypeImage (image) { | ||
| return /(\.(jpg)|\.(png)|\.(jpeg))/gi.test(image); | ||
| return null; | ||
| } | ||
| function isImage(urlOrImage) { | ||
| if (validTypeImage(urlOrImage)) { | ||
| return Promise.resolve(readFileAndConvert(urlOrImage)); | ||
| } else { | ||
| return Promise.reject('[*] Occurent some error... [validTypeImage] == false'); | ||
| } | ||
| function base64ToBrowser (buffer) { | ||
| return window.btoa([].slice.call(new Uint8Array(buffer)).map(function(bin) { return String.fromCharCode(bin) }).join("")); | ||
| } | ||
| function base64ToNode (buffer) { | ||
| return buffer.toString("base64"); | ||
| } | ||
| function readFileAndConvert (fileName) { | ||
| var fileSystem = require("fs"); | ||
| var path = require("path"); | ||
| if (fileSystem.statSync(fileName).isFile()) { | ||
| return base64ToNode(fileSystem.readFileSync(path.resolve(fileName)).toString("base64")); | ||
| } | ||
| return null; | ||
| } | ||
| function isImage (urlOrImage) { | ||
| if (validTypeImage(urlOrImage)) { | ||
| return Promise.resolve(readFileAndConvert(urlOrImage)); | ||
| } else { | ||
| return Promise.reject("[*] Occurent some error... [validTypeImage] == false"); | ||
| } | ||
| } | ||
| function isBrowser (urlOrImage, param) { | ||
| if (!("fetch" in window && "Promise" in window)) { | ||
| return Promise.reject("[*] It's image2base64 not compatible with your browser."); | ||
| } | ||
| return fetch(urlOrImage, param || {}).then(function(response){ | ||
| return response.arrayBuffer() | ||
| }).then(base64ToBrowser); | ||
| } | ||
| function isNodeJs (urlOrImage) { | ||
| if (validUrl(urlOrImage)) { | ||
| var fetch = require("node-fetch"); | ||
| return fetch(urlOrImage).then(function(response){ | ||
| return response.buffer() | ||
| }).then(base64ToNode); | ||
| } else { | ||
| return isImage(urlOrImage); | ||
| } | ||
| } | ||
| function imageToBase64(urlOrImage, param) { | ||
| if (typeof window !== "undefined" && ("document" in window && "navigator" in window)) { | ||
| return isBrowser(urlOrImage, param); | ||
| } else { | ||
| return isNodeJs(urlOrImage); | ||
| } | ||
| } | ||
| if (typeof module !== "undefined") { | ||
| module.exports = imageToBase64; | ||
| } | ||
| function imageToBase64(urlOrImage) { | ||
| if (validUrl(urlOrImage)) { | ||
| var fetch = require('node-fetch'); | ||
| return fetch(urlOrImage).then(function(response) { | ||
| return response.buffer(); | ||
| }).then(base64ToNode); | ||
| } else { | ||
| escope.imageToBase64 = imageToBase64; | ||
| return isImage(urlOrImage); | ||
| } | ||
| } | ||
| })(this); | ||
| module.exports = imageToBase64; |
@@ -1,1 +0,1 @@ | ||
| !function(e){"use strict";function o(e){return window.btoa([].slice.call(new Uint8Array(e)).map(function(e){return String.fromCharCode(e)}).join(""))}function u(e){return e.toString("base64")}function s(e){return/(\.(jpg)|\.(png)|\.(jpeg))/gi.test(e)?Promise.resolve((n=e,t=require("fs"),r=require("path"),t.statSync(n).isFile()?u(t.readFileSync(r.resolve(n)).toString("base64")):null)):Promise.reject("[*] Occurent some error... [validTypeImage] == false");var n,t,r}function n(e,n){return"undefined"!=typeof window&&"document"in window&&"navigator"in window?(r=e,i=n,"fetch"in window&&"Promise"in window?fetch(r,i||{}).then(function(e){return e.arrayBuffer()}).then(o):Promise.reject("[*] It's image2base64 not compatible with your browser.")):/(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi.test(t=e)?require("node-fetch")(t).then(function(e){return e.buffer()}).then(u):s(t);var t,r,i}"undefined"!=typeof module?module.exports=n:e.imageToBase64=n}(this); | ||
| "use strict";function validUrl(e){return/(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi.test(e)}function validTypeImage(e){return/(\.(jpg)|\.(png)|\.(jpeg))/gi.test(e)}function base64ToNode(e){return e.toString("base64")}function readFileAndConvert(e){var r=require("fs"),t=require("path");return r.statSync(e).isFile()?base64ToNode(r.readFileSync(t.resolve(e)).toString("base64")):null}function isImage(e){return validTypeImage(e)?Promise.resolve(readFileAndConvert(e)):Promise.reject("[*] Occurent some error... [validTypeImage] == false")}function imageToBase64(e){return validUrl(e)?require("node-fetch")(e).then(function(e){return e.buffer()}).then(base64ToNode):isImage(e)}module.exports=imageToBase64; |
+0
-0
@@ -0,0 +0,0 @@ MIT License |
+45
-41
| { | ||
| "name": "image-to-base64", | ||
| "version": "2.0.1", | ||
| "description": "Generate a image to base64.", | ||
| "main": "image-to-base64.min.js", | ||
| "scripts": { | ||
| "test": "mocha ./test" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/renanbastos93/image-to-base64.git" | ||
| }, | ||
| "keywords": [ | ||
| "node", | ||
| "nodejs", | ||
| "module convert base64 nodejs", | ||
| "image2base64", | ||
| "image-to-base64", | ||
| "convert-image-base64", | ||
| "convert", | ||
| "save", | ||
| "code", | ||
| "base64", | ||
| "image", | ||
| "webpack", | ||
| "loader", | ||
| "img", | ||
| "src", | ||
| "img src" | ||
| ], | ||
| "author": "Renan Bastos - <renanbastos.tec@gmail.com>", | ||
| "license": "MIT", | ||
| "bugs": { | ||
| "url": "https://github.com/renanbastos93/image-to-base64/issues" | ||
| }, | ||
| "homepage": "https://github.com/renanbastos93/image-to-base64#readme", | ||
| "dependencies": { | ||
| "node-fetch": "^1.7.3" | ||
| }, | ||
| "devDependencies": { | ||
| "mocha": "^5.0.1" | ||
| } | ||
| "name": "image-to-base64", | ||
| "version": "2.1.0", | ||
| "description": "Generate a image to base64.", | ||
| "main": "image-to-base64.min.js", | ||
| "scripts": { | ||
| "minify:base": "uglifyjs image-to-base64.js -c -m -o image-to-base64.min.js", | ||
| "minify:browser": "uglifyjs browser.js -c -m -o browser.min.js", | ||
| "minify": "npm run minify:base && npm run minify:browser", | ||
| "test": "mocha ./test" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/renanbastos93/image-to-base64.git" | ||
| }, | ||
| "keywords": [ | ||
| "node", | ||
| "nodejs", | ||
| "module convert base64 nodejs", | ||
| "image2base64", | ||
| "image-to-base64", | ||
| "convert-image-base64", | ||
| "convert", | ||
| "save", | ||
| "code", | ||
| "base64", | ||
| "image", | ||
| "webpack", | ||
| "loader", | ||
| "img", | ||
| "src", | ||
| "img src" | ||
| ], | ||
| "author": "Renan Bastos - <renanbastos.tec@gmail.com>", | ||
| "license": "MIT", | ||
| "bugs": { | ||
| "url": "https://github.com/renanbastos93/image-to-base64/issues" | ||
| }, | ||
| "homepage": "https://github.com/renanbastos93/image-to-base64#readme", | ||
| "dependencies": { | ||
| "node-fetch": "^1.7.3" | ||
| }, | ||
| "devDependencies": { | ||
| "uglify-js": "^3.9.1", | ||
| "mocha": "^7.1.1" | ||
| } | ||
| } |
+4
-3
@@ -7,2 +7,3 @@ # image-to-base64 | ||
| [](https://travis-ci.org/renanbastos93/image-to-base64) | ||
|  | ||
| [](https://david-dm.org/renanbastos93/image-to-base64?type=dev) | ||
@@ -28,4 +29,4 @@ [](https://www.codacy.com/app/renanbastos93/image-to-base64?utm_source=github.com&utm_medium=referral&utm_content=renanbastos93/image-to-base64&utm_campaign=Badge_Grade) | ||
| ```js | ||
| const image2base64 = require('image-to-base64'); | ||
| image2base64("path/to/file.jpg") // you can also to use url | ||
| const imageToBase64 = require('image-to-base64'); | ||
| imageToBase64("path/to/file.jpg") // you can also to use url | ||
| .then( | ||
@@ -53,3 +54,3 @@ (response) => { | ||
| ```js | ||
| image2base64("https://whatever-image/") | ||
| imageToBase64("https://whatever-image/") | ||
| .then( | ||
@@ -56,0 +57,0 @@ (response) => { |
+3
-3
@@ -10,3 +10,3 @@ const image2base64 = require("./../image-to-base64.js"); | ||
| describe("must to be resolved the promise", function(){ | ||
| it("get image of the url and convert to base64", function(){ | ||
@@ -21,3 +21,3 @@ image2base64(url) | ||
| }); | ||
| it("get image of the path and convert to base64", function(){ | ||
@@ -32,3 +32,3 @@ image2base64(path) | ||
| }); | ||
| }); |
Network access
Supply chain riskThis module accesses the network.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
Network access
Supply chain riskThis module accesses the network.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
26982
4.59%12
33.33%67
1.52%2
100%81
-10%2
100%