js-base64 2.6.3 → 2.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  Yet another Base64 transcoder
6
6
 
7
- ## Install
7
+ ## Usage
8
+
9
+ ### Install
8
10
 
9
11
  ```javascript
10
12
  $ npm install --save js-base64
@@ -19,14 +21,26 @@ $ npm install --save babel-preset-env
19
21
  Note `js-base64` itself is stand-alone so its `package.json` has no `dependencies`.  However, it is also tested on ES6 environment so `"babel-preset-env": "^1.7.0"` is on `devDependencies`.
20
22
 
21
23
 
22
- ## Usage
23
-
24
24
  ### In Browser
25
25
 
26
+ * Locally
27
+
26
28
  ```html
27
29
  <script src="base64.js"></script>
28
30
  ```
29
31
 
32
+ * Directly from CDN. In which case you don't even need to install.
33
+
34
+ ```html
35
+ <!-- the latest -->
36
+ <script src="https://cdn.jsdelivr.net/npm/js-base64/base64.min.js">
37
+ ```
38
+
39
+ ```html
40
+ <!-- with version fixed -->
41
+ <script src="https://cdn.jsdelivr.net/npm/js-base64@2.6.4/base64.min.js">
42
+ ```
43
+
30
44
  ### node.js
31
45
 
32
46
  ```javascript
package/base64.js CHANGED
@@ -22,7 +22,7 @@
22
22
  // existing version for noConflict()
23
23
  global = global || {};
24
24
  var _Base64 = global.Base64;
25
- var version = "2.6.3";
25
+ var version = "2.6.4";
26
26
  // constants
27
27
  var b64chars
28
28
  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
package/base64.min.js ADDED
@@ -0,0 +1 @@
1
+ (function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory(global):typeof define==="function"&&define.amd?define(factory):factory(global)})(typeof self!=="undefined"?self:typeof window!=="undefined"?window:typeof global!=="undefined"?global:this,function(global){"use strict";global=global||{};var _Base64=global.Base64;var version="2.6.4";var b64chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var b64tab=function(bin){var t={};for(var i=0,l=bin.length;i<l;i++)t[bin.charAt(i)]=i;return t}(b64chars);var fromCharCode=String.fromCharCode;var cb_utob=function(c){if(c.length<2){var cc=c.charCodeAt(0);return cc<128?c:cc<2048?fromCharCode(192|cc>>>6)+fromCharCode(128|cc&63):fromCharCode(224|cc>>>12&15)+fromCharCode(128|cc>>>6&63)+fromCharCode(128|cc&63)}else{var cc=65536+(c.charCodeAt(0)-55296)*1024+(c.charCodeAt(1)-56320);return fromCharCode(240|cc>>>18&7)+fromCharCode(128|cc>>>12&63)+fromCharCode(128|cc>>>6&63)+fromCharCode(128|cc&63)}};var re_utob=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;var utob=function(u){return u.replace(re_utob,cb_utob)};var cb_encode=function(ccc){var padlen=[0,2,1][ccc.length%3],ord=ccc.charCodeAt(0)<<16|(ccc.length>1?ccc.charCodeAt(1):0)<<8|(ccc.length>2?ccc.charCodeAt(2):0),chars=[b64chars.charAt(ord>>>18),b64chars.charAt(ord>>>12&63),padlen>=2?"=":b64chars.charAt(ord>>>6&63),padlen>=1?"=":b64chars.charAt(ord&63)];return chars.join("")};var btoa=global.btoa&&typeof global.btoa=="function"?function(b){return global.btoa(b)}:function(b){if(b.match(/[^\x00-\xFF]/))throw new RangeError("The string contains invalid characters.");return b.replace(/[\s\S]{1,3}/g,cb_encode)};var _encode=function(u){return btoa(utob(String(u)))};var mkUriSafe=function(b64){return b64.replace(/[+\/]/g,function(m0){return m0=="+"?"-":"_"}).replace(/=/g,"")};var encode=function(u,urisafe){return urisafe?mkUriSafe(_encode(u)):_encode(u)};var encodeURI=function(u){return encode(u,true)};var fromUint8Array;if(global.Uint8Array)fromUint8Array=function(a,urisafe){var b64="";for(var i=0,l=a.length;i<l;i+=3){var a0=a[i],a1=a[i+1],a2=a[i+2];var ord=a0<<16|a1<<8|a2;b64+=b64chars.charAt(ord>>>18)+b64chars.charAt(ord>>>12&63)+(typeof a1!="undefined"?b64chars.charAt(ord>>>6&63):"=")+(typeof a2!="undefined"?b64chars.charAt(ord&63):"=")}return urisafe?mkUriSafe(b64):b64};var re_btou=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;var cb_btou=function(cccc){switch(cccc.length){case 4:var cp=(7&cccc.charCodeAt(0))<<18|(63&cccc.charCodeAt(1))<<12|(63&cccc.charCodeAt(2))<<6|63&cccc.charCodeAt(3),offset=cp-65536;return fromCharCode((offset>>>10)+55296)+fromCharCode((offset&1023)+56320);case 3:return fromCharCode((15&cccc.charCodeAt(0))<<12|(63&cccc.charCodeAt(1))<<6|63&cccc.charCodeAt(2));default:return fromCharCode((31&cccc.charCodeAt(0))<<6|63&cccc.charCodeAt(1))}};var btou=function(b){return b.replace(re_btou,cb_btou)};var cb_decode=function(cccc){var len=cccc.length,padlen=len%4,n=(len>0?b64tab[cccc.charAt(0)]<<18:0)|(len>1?b64tab[cccc.charAt(1)]<<12:0)|(len>2?b64tab[cccc.charAt(2)]<<6:0)|(len>3?b64tab[cccc.charAt(3)]:0),chars=[fromCharCode(n>>>16),fromCharCode(n>>>8&255),fromCharCode(n&255)];chars.length-=[0,0,2,1][padlen];return chars.join("")};var _atob=global.atob&&typeof global.atob=="function"?function(a){return global.atob(a)}:function(a){return a.replace(/\S{1,4}/g,cb_decode)};var atob=function(a){return _atob(String(a).replace(/[^A-Za-z0-9\+\/]/g,""))};var _decode=function(a){return btou(_atob(a))};var _fromURI=function(a){return String(a).replace(/[-_]/g,function(m0){return m0=="-"?"+":"/"}).replace(/[^A-Za-z0-9\+\/]/g,"")};var decode=function(a){return _decode(_fromURI(a))};var toUint8Array;if(global.Uint8Array)toUint8Array=function(a){return Uint8Array.from(atob(_fromURI(a)),function(c){return c.charCodeAt(0)})};var noConflict=function(){var Base64=global.Base64;global.Base64=_Base64;return Base64};global.Base64={VERSION:version,atob:atob,btoa:btoa,fromBase64:decode,toBase64:encode,utob:utob,encode:encode,encodeURI:encodeURI,btou:btou,decode:decode,noConflict:noConflict,fromUint8Array:fromUint8Array,toUint8Array:toUint8Array};if(typeof Object.defineProperty==="function"){var noEnum=function(v){return{value:v,enumerable:false,writable:true,configurable:true}};global.Base64.extendString=function(){Object.defineProperty(String.prototype,"fromBase64",noEnum(function(){return decode(this)}));Object.defineProperty(String.prototype,"toBase64",noEnum(function(urisafe){return encode(this,urisafe)}));Object.defineProperty(String.prototype,"toBase64URI",noEnum(function(){return encode(this,true)}))}}if(global["Meteor"]){Base64=global.Base64}if(typeof module!=="undefined"&&module.exports){module.exports.Base64=global.Base64}else if(typeof define==="function"&&define.amd){define([],function(){return global.Base64})}return{Base64:global.Base64}});
package/package.json CHANGED
@@ -1,18 +1,25 @@
1
1
  {
2
2
  "name": "js-base64",
3
- "version": "2.6.3",
3
+ "version": "2.6.4",
4
4
  "description": "Yet another Base64 transcoder in pure-JS",
5
5
  "main": "base64.js",
6
+ "files": [
7
+ "base64.js",
8
+ "base64.min.js"
9
+ ],
6
10
  "directories": {
7
11
  "test": "test"
8
12
  },
9
13
  "scripts": {
10
- "test": "mocha --compilers js:babel-register"
14
+ "test": "mocha --require @babel/register",
15
+ "minify": "uglifyjs base64.js > base64.min.js"
11
16
  },
12
17
  "devDependencies": {
13
- "babel-preset-env": "^1.7.0",
14
- "babel-register": "^6.26.0",
15
- "mocha": "5.x.x"
18
+ "@babel/core": "^7.10.5",
19
+ "@babel/preset-env": "^7.10.5",
20
+ "@babel/register": "^7.10.5",
21
+ "mocha": "^8.0.0",
22
+ "uglify-js": "^3.10.0"
16
23
  },
17
24
  "repository": {
18
25
  "type": "git",
@@ -1,44 +0,0 @@
1
- /*
2
- * $Id: dankogai.js,v 0.4 2012/08/24 05:23:18 dankogai Exp dankogai $
3
- *
4
- * use mocha to test me
5
- * http://visionmedia.github.com/mocha/
6
- */
7
- var assert = assert || require("assert");
8
- var Base64 = Base64 || require('../base64.js').Base64;
9
- var is = function (a, e, m) {
10
- return function () {
11
- assert.equal(a, e, m)
12
- }
13
- };
14
-
15
- describe('basic', function () {
16
- it('d', is(Base64.encode('d'), 'ZA=='));
17
- it('da', is(Base64.encode('da'), 'ZGE='));
18
- it('dan', is(Base64.encode('dan'), 'ZGFu'));
19
- it('ZA==', is(Base64.decode('ZA=='), 'd' ));
20
- it('ZGE=', is(Base64.decode('ZGE='), 'da' ));
21
- it('ZGFu', is(Base64.decode('ZGFu'), 'dan' ));
22
- });
23
-
24
- describe('whitespace', function () {
25
- it('Z A==', is(Base64.decode('ZA =='), 'd' ));
26
- it('ZG E=', is(Base64.decode('ZG E='), 'da' ));
27
- it('ZGF u', is(Base64.decode('ZGF u'), 'dan' ));
28
- });
29
-
30
- describe('null', function () {
31
- it('\\0', is(Base64.encode('\0'), 'AA=='));
32
- it('\\0\\0', is(Base64.encode('\0\0'), 'AAA='));
33
- it('\\0\\0\\0', is(Base64.encode('\0\0\0'), 'AAAA'));
34
- it('AA==', is(Base64.decode('AA=='), '\0' ));
35
- it('AAA=', is(Base64.decode('AAA='), '\0\0' ));
36
- it('AAAA', is(Base64.decode('AAAA'), '\0\0\0'));
37
- });
38
-
39
- describe('Base64', function () {
40
- it('.encode', is(Base64.encode('小飼弾'), '5bCP6aO85by+'));
41
- it('.encodeURI', is(Base64.encodeURI('小飼弾'), '5bCP6aO85by-'));
42
- it('.decode', is(Base64.decode('5bCP6aO85by+'), '小飼弾'));
43
- it('.decode', is(Base64.decode('5bCP6aO85by-'), '小飼弾'));
44
- });
@@ -1,24 +0,0 @@
1
- /*
2
- * $Id: es5.js,v 0.1 2012/08/23 19:43:17 dankogai Exp dankogai $
3
- *
4
- * use mocha to test me
5
- * http://visionmedia.github.com/mocha/
6
- */
7
- var assert = assert || require("assert");
8
- var Base64 = Base64 || require('../base64.js').Base64;
9
- var is = function (a, e, m) {
10
- return function () {
11
- assert.equal(a, e, m)
12
- }
13
- };
14
-
15
- if ('extendString' in Base64){
16
- Base64.extendString();
17
- describe('String', function () {
18
- it('.toBase64', is('小飼弾'.toBase64(), '5bCP6aO85by+'));
19
- it('.toBase64', is('小飼弾'.toBase64(true), '5bCP6aO85by-'));
20
- it('.toBase64URI', is('小飼弾'.toBase64URI(), '5bCP6aO85by-'));
21
- it('.fromBase64', is('5bCP6aO85by+'.fromBase64(), '小飼弾'));
22
- it('.fromBase64', is('5bCP6aO85by-'.fromBase64(), '小飼弾'));
23
- });
24
- }
@@ -1,25 +0,0 @@
1
- /*
2
- * $Id: es6.js,v 0.1 2017/11/29 21:43:17 ufolux Exp ufolux $
3
- *
4
- * use mocha to test me
5
- * http://visionmedia.github.com/mocha/
6
- */
7
- import {Base64} from '../base64'
8
-
9
- var assert = assert || require("assert");
10
- var is = function (a, e, m) {
11
- return function () {
12
- assert.equal(a, e, m)
13
- }
14
- };
15
-
16
- if ('extendString' in Base64){
17
- Base64.extendString();
18
- describe('String', function () {
19
- it('.toBase64', is('小飼弾'.toBase64(), '5bCP6aO85by+'));
20
- it('.toBase64', is('小飼弾'.toBase64(true), '5bCP6aO85by-'));
21
- it('.toBase64URI', is('小飼弾'.toBase64URI(), '5bCP6aO85by-'));
22
- it('.fromBase64', is('5bCP6aO85by+'.fromBase64(), '小飼弾'));
23
- it('.fromBase64', is('5bCP6aO85by-'.fromBase64(), '小飼弾'));
24
- });
25
- }
@@ -1,40 +0,0 @@
1
- <html>
2
- <head>
3
- <meta charset="utf-8">
4
- <title>Mocha Tests</title>
5
- <link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet" />
6
- </head>
7
- <body>
8
- <div id="mocha"></div>
9
-
10
- <script src="https://cdn.rawgit.com/jquery/jquery/2.1.4/dist/jquery.min.js"></script>
11
- <script src="https://cdn.rawgit.com/Automattic/expect.js/0.3.1/index.js"></script>
12
- <script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script>
13
- <script>
14
- mocha.setup('bdd');
15
- </script>
16
- <script src="./moment.js"></script>
17
- <script src="../base64.js"></script>
18
- <script>
19
- var assert = function(expr, msg) {
20
- if (!expr) throw new Error(msg || 'failed');
21
- };
22
- assert.equal = function(a, b, msg) {
23
- if (a !== b) throw new Error(msg || ('failed : '+a+','+b));
24
- };
25
- </script>
26
- <script src="./dankogai.js"></script>
27
- <script src="./es5.js"></script>
28
- <script src="./large.js"></script>
29
- <script src="./yoshinoya.js"></script>
30
- <script>
31
- $(function() {
32
- mocha.run();
33
- });
34
- </script>
35
- </head>
36
- <body>
37
- $Id: index.html,v 0.3 2017/09/11 08:43:43 dankogai Exp dankogai $
38
- <div id="mocha"></div>
39
- </body>
40
- </html>
@@ -1,25 +0,0 @@
1
- /*
2
- * $Id: large.js,v 0.3 2012/08/23 19:14:37 dankogai Exp dankogai $
3
- *
4
- * use mocha to test me
5
- * http://visionmedia.github.com/mocha/
6
- */
7
- var assert = assert || require("assert");
8
- var Base64 = Base64 || require('../base64.js').Base64;
9
- var is = function (a, e, m) {
10
- return function () {
11
- assert.equal(a, e, m)
12
- }
13
- };
14
- var seed = function () {
15
- var a, i;
16
- for (a = [], i = 0; i < 256; i++) {
17
- a.push(String.fromCharCode(i));
18
- }
19
- return a.join('');
20
- }();
21
- describe('Base64', function () {
22
- for (var i = 0, str = seed; i < 16; str += str, i++) {
23
- it(''+str.length, is(Base64.decode(Base64.encode(str)), str));
24
- }
25
- });