js-base64 2.6.0 → 2.6.1

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
@@ -44,12 +44,20 @@ import { Base64 } from 'js-base64';
44
44
  ```javascript
45
45
  Base64.encode('dankogai'); // ZGFua29nYWk=
46
46
  Base64.btoa( 'dankogai'); // ZGFua29nYWk=
47
- Base64.encode('小飼弾'); // 5bCP6aO85by+
48
- Base64.encodeURI('小飼弾'); // 5bCP6aO85by-
49
- Base64.btoa( '小飼弾'); // raises exception
47
+ Base64.fromUint8Array( // ZGFua29nYWk=
48
+ new Uint8Array([100,97,110,107,111,103,97,105])
49
+ );
50
+ Base64.encode( '小飼弾'); // 5bCP6aO85by+
51
+ Base64.encodeURI('小飼弾'); // 5bCP6aO85by- which equals to Base64.encode('小飼弾', true)
52
+ Base64.btoa( '小飼弾'); // raises exception
53
+ ```
50
54
 
55
+ ```javascript
51
56
  Base64.decode('ZGFua29nYWk='); // dankogai
52
57
  Base64.atob( 'ZGFua29nYWk='); // dankogai
58
+ Base64.toUint8Array( // new Uint8Array([100,97,110,107,111,103,97,105])
59
+ 'ZGFua29nYWk='
60
+ );
53
61
  Base64.decode('5bCP6aO85by+'); // 小飼弾
54
62
  // note .decodeURI() is unnecessary since it accepts both flavors
55
63
  Base64.decode('5bCP6aO85by-'); // 小飼弾
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.0";
25
+ var version = "2.6.1";
26
26
  // constants
27
27
  var b64chars
28
28
  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@@ -77,18 +77,21 @@
77
77
  return b.replace(/[\s\S]{1,3}/g, cb_encode);
78
78
  };
79
79
  var _encode = function(u) {
80
- var isUint8Array = Object.prototype.toString.call(u) === '[object Uint8Array]';
81
- return isUint8Array ? u.toString('base64')
82
- : btoa(utob(String(u)));
83
- }
80
+ return btoa(utob(String(u)));
81
+ };
84
82
  var encode = function(u, urisafe) {
85
83
  return !urisafe
86
- ? _encode(u)
84
+ ? _encode(String(u))
87
85
  : _encode(String(u)).replace(/[+\/]/g, function(m0) {
88
86
  return m0 == '+' ? '-' : '_';
89
87
  }).replace(/=/g, '');
90
88
  };
91
89
  var encodeURI = function(u) { return encode(u, true) };
90
+ var fromUint8Array = function(a) {
91
+ return btoa(Array.from(a, function(c) {
92
+ return String.fromCharCode(c)
93
+ }).join(''));
94
+ };
92
95
  // decoder stuff
93
96
  var re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
94
97
  var cb_btou = function(cccc) {
@@ -142,10 +145,16 @@
142
145
  var _decode = function(a) { return btou(_atob(a)) };
143
146
  var decode = function(a){
144
147
  return _decode(
145
- String(a).replace(/[-_]/g, function(m0) { return m0 == '-' ? '+' : '/' })
146
- .replace(/[^A-Za-z0-9\+\/]/g, '')
148
+ String(a).replace(/[-_]/g, function(m0) {
149
+ return m0 == '-' ? '+' : '/'
150
+ }).replace(/[^A-Za-z0-9\+\/]/g, '')
147
151
  );
148
152
  };
153
+ var toUint8Array = function(a) {
154
+ return Uint8Array.from(atob(a), function(c) {
155
+ return c.charCodeAt(0);
156
+ });
157
+ };
149
158
  var noConflict = function() {
150
159
  var Base64 = global.Base64;
151
160
  global.Base64 = _Base64;
@@ -164,6 +173,8 @@
164
173
  btou: btou,
165
174
  decode: decode,
166
175
  noConflict: noConflict,
176
+ fromUint8Array: fromUint8Array,
177
+ toUint8Array: toUint8Array
167
178
  };
168
179
  // if ES5 is available, make Base64.extendString() available
169
180
  if (typeof Object.defineProperty === 'function') {
@@ -203,4 +214,3 @@
203
214
  // that's it!
204
215
  return {Base64: global.Base64}
205
216
  }));
206
-
package/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-base64",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "license": "BSD-3-Clause",
5
5
  "main": [
6
6
  "./base64.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-base64",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "description": "Yet another Base64 transcoder in pure-JS",
5
5
  "main": "base64.js",
6
6
  "directories": {