Comparing version 1.0.0 to 1.1.0
@@ -1,1 +0,1 @@ | ||
(function(root,factory){if(typeof exports==="object"&&typeof module==="object")module.exports=factory();else if(typeof define==="function"&&define.amd)define(["svg64"],factory);else if(typeof exports==="object")exports["svg64"]=factory();else root["svg64"]=factory()})(this,function(){var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(input){var output="";var chr1,chr2,chr3,enc1,enc2,enc3,enc4;var i=0;input=Base64._utf8_encode(input);while(i<input.length){chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=(chr1&3)<<4|chr2>>4;enc3=(chr2&15)<<2|chr3>>6;enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64}else if(isNaN(chr3)){enc4=64}output=output+this._keyStr.charAt(enc1)+this._keyStr.charAt(enc2)+this._keyStr.charAt(enc3)+this._keyStr.charAt(enc4)}return output},decode:function(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(i<input.length){enc1=this._keyStr.indexOf(input.charAt(i++));enc2=this._keyStr.indexOf(input.charAt(i++));enc3=this._keyStr.indexOf(input.charAt(i++));enc4=this._keyStr.indexOf(input.charAt(i++));chr1=enc1<<2|enc2>>4;chr2=(enc2&15)<<4|enc3>>2;chr3=(enc3&3)<<6|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64){output=output+String.fromCharCode(chr2)}if(enc4!=64){output=output+String.fromCharCode(chr3)}}output=Base64._utf8_decode(output);return output},_utf8_encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c)}else if(c>127&&c<2048){utftext+=String.fromCharCode(c>>6|192);utftext+=String.fromCharCode(c&63|128)}else{utftext+=String.fromCharCode(c>>12|224);utftext+=String.fromCharCode(c>>6&63|128);utftext+=String.fromCharCode(c&63|128)}}return utftext},_utf8_decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++}else if(c>191&&c<224){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode((c&31)<<6|c2&63);i+=2}else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode((c&15)<<12|(c2&63)<<6|c3&63);i+=3}}return string}};var PREFIX="data:image/svg+xml;base64,";var detectInputType=function(input){if(typeof input==="string"){return"string"}if(typeof SVGElement!=="undefined"&&input instanceof SVGElement){return"element"}};var convertElement=function(element){var XMLS=new XMLSerializer;var svg=XMLS.serializeToString(element);return getBase64(svg)};var getBase64=function(svg){return PREFIX+Base64.encode(svg)};return function(svg){var type=detectInputType(svg);switch(type){case"string":return getBase64(svg);case"element":return convertElement(svg);default:return svg}}}); | ||
(function(root,factory){if(typeof exports==="object"&&typeof module==="object")module.exports=factory();else if(typeof define==="function"&&define.amd)define(["svg64"],factory);else if(typeof exports==="object")exports["svg64"]=factory();else root["svg64"]=factory()})(this,function(){var Base64={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(input){var output="";var chr1,chr2,chr3,enc1,enc2,enc3,enc4;var i=0;input=Base64.utf8Encode(input);while(i<input.length){chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=(chr1&3)<<4|chr2>>4;enc3=(chr2&15)<<2|chr3>>6;enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64}else if(isNaN(chr3)){enc4=64}output=output+this.characters.charAt(enc1)+this.characters.charAt(enc2)+this.characters.charAt(enc3)+this.characters.charAt(enc4)}return output},utf8Encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c)}else if(c>127&&c<2048){utftext+=String.fromCharCode(c>>6|192);utftext+=String.fromCharCode(c&63|128)}else{utftext+=String.fromCharCode(c>>12|224);utftext+=String.fromCharCode(c>>6&63|128);utftext+=String.fromCharCode(c&63|128)}}return utftext}};var PREFIX="data:image/svg+xml;base64,";var detectInputType=function(input){if(typeof input==="string"){return"string"}if(typeof SVGElement!=="undefined"&&input instanceof SVGElement){return"element"}};var convertElement=function(element){var XMLS=new XMLSerializer;var svg=XMLS.serializeToString(element);return getBase64(svg)};var getBase64=function(svg){return PREFIX+Base64.encode(svg)};return function(svg){var type=detectInputType(svg);switch(type){case"string":return getBase64(svg);case"element":return convertElement(svg);default:return svg}}}); |
{ | ||
"name": "svg64", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Convert SVG to base64 anywhere", | ||
@@ -23,5 +23,5 @@ "keywords": [ | ||
"devDependencies": { | ||
"uglify-js": "3.6.0" | ||
"uglify-js": "3.11.3" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -5,3 +5,3 @@ [![GitHub release](https://img.shields.io/github/release/scriptex/svg64.svg)](https://github.com/scriptex/svg64/releases/latest) | ||
[![Github file size](https://img.shields.io/github/size/scriptex/svg64/dist/svg64.js.svg)](https://github.com/scriptex/svg64) | ||
[![Build Status](https://travis-ci.org/scriptex/svg64.svg?branch=master)](https://travis-ci.org/scriptex/svg64) | ||
[![Build Status](https://travis-ci.com/scriptex/svg64.svg?branch=master)](https://travis-ci.com/scriptex/svg64) | ||
[![npm](https://img.shields.io/npm/dt/svg64.svg)](https://www.npmjs.com/package/svg64) | ||
@@ -87,4 +87,10 @@ [![npm](https://img.shields.io/npm/v/svg64.svg)](https://www.npmjs.com/package/svg64) | ||
## Support this project | ||
[![Tweet](https://img.shields.io/badge/Tweet-Share_this_repository-blue.svg?style=flat-square&logo=twitter&color=38A1F3)](https://twitter.com/intent/tweet?text=Checkout%20this%20awesome%20software%20project%3A&url=https%3A%2F%2Fgithub.com%2Fscriptex%2Fsvg64&via=scriptexbg&hashtags=software%2Cgithub%2Ccode%2Cawesome) | ||
[![Donate](https://img.shields.io/badge/Donate-Support_me_on_PayPal-blue.svg?style=flat-square&logo=paypal&color=222d65)](https://www.paypal.me/scriptex) | ||
[![Become a Patron](https://img.shields.io/badge/Become_Patron-Support_me_on_Patreon-blue.svg?style=flat-square&logo=patreon&color=e64413)](https://www.patreon.com/atanas) | ||
## LICENSE | ||
MIT |
115
src/svg64.js
@@ -1,17 +0,14 @@ | ||
(function(root, factory) { | ||
(function (root, factory) { | ||
if (typeof exports === 'object' && typeof module === 'object') module.exports = factory(); | ||
// @ts-ignore | ||
else if (typeof define === 'function' && define.amd) define(['svg64'], factory); | ||
else if (typeof exports === 'object') exports['svg64'] = factory(); | ||
else root['svg64'] = factory(); | ||
})(this, function() { | ||
})(this, function () { | ||
/** | ||
* Base64 encode / decode | ||
* http://www.webtoolkit.info/ | ||
* Code modified from http://www.webtoolkit.info/ | ||
**/ | ||
var Base64 = { | ||
// private property | ||
_keyStr: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', | ||
// public method for encoding | ||
encode: function(input) { | ||
characters: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', | ||
encode: function (input) { | ||
var output = ''; | ||
@@ -21,3 +18,3 @@ var chr1, chr2, chr3, enc1, enc2, enc3, enc4; | ||
input = Base64._utf8_encode(input); | ||
input = Base64.utf8Encode(input); | ||
@@ -42,6 +39,6 @@ while (i < input.length) { | ||
output + | ||
this._keyStr.charAt(enc1) + | ||
this._keyStr.charAt(enc2) + | ||
this._keyStr.charAt(enc3) + | ||
this._keyStr.charAt(enc4); | ||
this.characters.charAt(enc1) + | ||
this.characters.charAt(enc2) + | ||
this.characters.charAt(enc3) + | ||
this.characters.charAt(enc4); | ||
} | ||
@@ -51,39 +48,3 @@ | ||
}, | ||
// public method for decoding | ||
decode: function(input) { | ||
var output = ''; | ||
var chr1, chr2, chr3; | ||
var enc1, enc2, enc3, enc4; | ||
var i = 0; | ||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ''); | ||
while (i < input.length) { | ||
enc1 = this._keyStr.indexOf(input.charAt(i++)); | ||
enc2 = this._keyStr.indexOf(input.charAt(i++)); | ||
enc3 = this._keyStr.indexOf(input.charAt(i++)); | ||
enc4 = this._keyStr.indexOf(input.charAt(i++)); | ||
chr1 = (enc1 << 2) | (enc2 >> 4); | ||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); | ||
chr3 = ((enc3 & 3) << 6) | enc4; | ||
output = output + String.fromCharCode(chr1); | ||
if (enc3 != 64) { | ||
output = output + String.fromCharCode(chr2); | ||
} | ||
if (enc4 != 64) { | ||
output = output + String.fromCharCode(chr3); | ||
} | ||
} | ||
output = Base64._utf8_decode(output); | ||
return output; | ||
}, | ||
// private method for UTF-8 encoding | ||
_utf8_encode: function(string) { | ||
utf8Encode: function (string) { | ||
string = string.replace(/\r\n/g, '\n'); | ||
@@ -108,35 +69,5 @@ var utftext = ''; | ||
return utftext; | ||
}, | ||
// private method for UTF-8 decoding | ||
_utf8_decode: function(utftext) { | ||
var string = ''; | ||
var i = 0; | ||
var c = (c1 = c2 = 0); | ||
while (i < utftext.length) { | ||
c = utftext.charCodeAt(i); | ||
if (c < 128) { | ||
string += String.fromCharCode(c); | ||
i++; | ||
} else if (c > 191 && c < 224) { | ||
c2 = utftext.charCodeAt(i + 1); | ||
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); | ||
i += 2; | ||
} else { | ||
c2 = utftext.charCodeAt(i + 1); | ||
c3 = utftext.charCodeAt(i + 2); | ||
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); | ||
i += 3; | ||
} | ||
} | ||
return string; | ||
} | ||
}; | ||
/** | ||
* base64 prefix | ||
*/ | ||
var PREFIX = 'data:image/svg+xml;base64,'; | ||
@@ -147,7 +78,7 @@ | ||
* | ||
* @param {String|SVGElement} input | ||
* @param {string | SVGElement} input | ||
* | ||
* @return {String} | ||
* @return {string} | ||
*/ | ||
var detectInputType = function(input) { | ||
var detectInputType = function (input) { | ||
if (typeof input === 'string') { | ||
@@ -167,5 +98,5 @@ return 'string'; | ||
* | ||
* @return {String} | ||
* @return {string} | ||
*/ | ||
var convertElement = function(element) { | ||
var convertElement = function (element) { | ||
var XMLS = new XMLSerializer(); | ||
@@ -180,7 +111,7 @@ var svg = XMLS.serializeToString(element); | ||
* | ||
* @param {String} svg - Serialized SVG element or SVG string | ||
* @param {string} svg - Serialized SVG element or SVG string | ||
* | ||
* @return {String} | ||
* @return {string} | ||
*/ | ||
var getBase64 = function(svg) { | ||
var getBase64 = function (svg) { | ||
return PREFIX + Base64.encode(svg); | ||
@@ -192,7 +123,7 @@ }; | ||
* | ||
* @param {String|SVGElement} svg | ||
* @param {string | SVGElement} svg | ||
* | ||
* @return {String} | ||
* @return {string} | ||
*/ | ||
return function(svg) { | ||
return function (svg) { | ||
var type = detectInputType(svg); | ||
@@ -199,0 +130,0 @@ |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
95
0
11980
120