Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

image-to-base64

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-to-base64 - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

11

image-to-base64.js
"use strict";
const image2base64 = (url, param) => {

@@ -6,6 +7,6 @@ return new Promise(

let valid = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi.test(url);
if(valid == true){
let valid = new RegExp("(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?", "gi");
if(valid.test(param) === true){
fetch(

@@ -19,3 +20,3 @@ url,

(buffer) => {
return 'data:image/jpeg;base64,' + window.btoa(
return window.btoa(
[].slice.call(

@@ -25,3 +26,3 @@ new Uint8Array(buffer)

(bin) => String.fromCharCode(bin)
).join('')
).join("")
);

@@ -28,0 +29,0 @@ }

"use strict";
const fs = require('fs');
const path = require('path');
const fetch = require('node-fetch');
const fs = require("fs");
const path = require("path");
const fetch = require("node-fetch");

@@ -12,14 +12,10 @@ const image2base64 = (param) => {

let valid = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi.test(param);
if(!valid){
if(/(\.(jpg)|\.(png)|\.(jpeg))/gi.test(param)){
let valid = new RegExp("(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?", "gi");
if(valid !== true){
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{

@@ -44,5 +40,3 @@ reject(null);

(body) => {
resolve(
body.toString('base64')
);
resolve(body.toString("base64"));
}

@@ -49,0 +43,0 @@ );

{
"name": "image-to-base64",
"version": "1.3.0",
"version": "1.3.1",
"description": "Generate a image to base64.",

@@ -41,4 +41,4 @@ "main": "index.js",

"devDependencies": {
"mocha": "^4.1.0"
"mocha": "^5.0.1"
}
}

@@ -7,2 +7,5 @@ # image-to-base64

[![Build Status](https://travis-ci.org/renanbastos93/image-to-base64.svg?branch=master)](https://travis-ci.org/renanbastos93/image-to-base64)
[![devDependencies Status](https://david-dm.org/renanbastos93/image-to-base64/dev-status.svg)](https://david-dm.org/renanbastos93/image-to-base64?type=dev)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/319a6e0b35474cf3ada5b0894e959b65)](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)
<a href="https://www.npmjs.com/package/vue"><img src="https://img.shields.io/npm/l/vue.svg" alt="License"></a>

@@ -14,2 +17,3 @@ [npm-image]: https://img.shields.io/npm/v/image-to-base64.svg

## About

@@ -16,0 +20,0 @@ It was think for supplement any situation, as for example save one string in database, too send the string to front-end increment one tag `<img />`

@@ -1,30 +0,31 @@

const image2base64 = require('./../');
const assert = require('assert');
const pt = require('path')
const image2base64 = require("./../");
const assert = require("assert");
const pt = require("path");
let url = "http://jaystack.com/wp-content/uploads/2015/12/nodejs-logo-e1497443346889.png";
let path = pt.resolve("test/nodejs.png");
let validBase64 = new RegExp("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{0,2}==)$","gim");
describe("must to be resolved the promise", function(){
it('get image of the url and convert to base64', function(){
it("get image of the url and convert to base64", function(){
image2base64(url)
.then(
(data) => {
assert(/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{0,2}==)$/.test(data), true);
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(){
it("get image of the path and convert to base64", function(){
image2base64(path)
.then(
(data) => {
assert(/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{0,2}==)$/.test(data), true);
assert(validBase64.test(data).test(data), true);
}
)
.catch((err)=>assert(err, true));
})
.catch((err) => assert(err, true));
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc