-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
325 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var parent = require('../stable/atob'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var parent = require('../stable/btoa'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var parent = require('../actual/atob'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var parent = require('../actual/btoa'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var itoc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
var ctoi = {}; | ||
|
||
for (var index = 0; index < 66; index++) ctoi[itoc.charAt(index)] = index; | ||
|
||
module.exports = { | ||
itoc: itoc, | ||
ctoi: ctoi | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var $ = require('../internals/export'); | ||
var getBuiltIn = require('../internals/get-built-in'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var fails = require('../internals/fails'); | ||
var toString = require('../internals/to-string'); | ||
var hasOwn = require('../internals/has-own-property'); | ||
var validateArgumentsLength = require('../internals/validate-arguments-length'); | ||
var ctoi = require('../internals/base64-map').ctoi; | ||
|
||
var disallowed = /[^\d+/a-z]/i; | ||
var whitespaces = /[\t\n\f\r ]+/g; | ||
var finalEq = /[=]+$/; | ||
|
||
var $atob = getBuiltIn('atob'); | ||
var fromCharCode = String.fromCharCode; | ||
var charAt = uncurryThis(''.charAt); | ||
var replace = uncurryThis(''.replace); | ||
var exec = uncurryThis(disallowed.exec); | ||
|
||
var NO_SPACES_IGNORE = fails(function () { | ||
return atob(' ') !== ''; | ||
}); | ||
|
||
var NO_ARG_RECEIVING_CHECK = !NO_SPACES_IGNORE && !fails(function () { | ||
$atob(); | ||
}); | ||
|
||
// `atob` method | ||
// https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob | ||
$({ global: true, enumerable: true, forced: NO_SPACES_IGNORE || NO_ARG_RECEIVING_CHECK }, { | ||
atob: function atob(data) { | ||
validateArgumentsLength(arguments.length, 1); | ||
if (NO_ARG_RECEIVING_CHECK) return $atob(data); | ||
var string = replace(toString(data), whitespaces, ''); | ||
var output = ''; | ||
var position = 0; | ||
var bc = 0; | ||
var chr, bs; | ||
if (string.length % 4 == 0) { | ||
string = replace(string, finalEq, ''); | ||
} | ||
if (string.length % 4 == 1 || exec(disallowed, string)) { | ||
throw new (getBuiltIn('DOMException'))('The string is not correctly encoded', 'InvalidCharacterError'); | ||
} | ||
while (chr = charAt(string, position++)) { | ||
if (hasOwn(ctoi, chr)) { | ||
bs = bc % 4 ? bs * 64 + ctoi[chr] : ctoi[chr]; | ||
if (bc++ % 4) output += fromCharCode(255 & bs >> (-2 * bc & 6)); | ||
} | ||
} return output; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var $ = require('../internals/export'); | ||
var getBuiltIn = require('../internals/get-built-in'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var fails = require('../internals/fails'); | ||
var toString = require('../internals/to-string'); | ||
var validateArgumentsLength = require('../internals/validate-arguments-length'); | ||
var itoc = require('../internals/base64-map').itoc; | ||
|
||
var $btoa = getBuiltIn('btoa'); | ||
var charAt = uncurryThis(''.charAt); | ||
var charCodeAt = uncurryThis(''.charCodeAt); | ||
|
||
var NO_ARG_RECEIVING_CHECK = !!$btoa && !fails(function () { | ||
$btoa(); | ||
}); | ||
|
||
// `btoa` method | ||
// https://html.spec.whatwg.org/multipage/webappapis.html#dom-btoa | ||
$({ global: true, enumerable: true, forced: NO_ARG_RECEIVING_CHECK }, { | ||
btoa: function btoa(data) { | ||
validateArgumentsLength(arguments.length, 1); | ||
if (NO_ARG_RECEIVING_CHECK) return $btoa(data); | ||
var string = toString(data); | ||
var output = ''; | ||
var position = 0; | ||
var map = itoc; | ||
var block, charCode; | ||
while (charAt(string, position) || (map = '=', position % 1)) { | ||
charCode = charCodeAt(string, position += 3 / 4); | ||
if (charCode > 0xFF) { | ||
throw new (getBuiltIn('DOMException'))('The string contains characters outside of the Latin1 range', 'InvalidCharacterError'); | ||
} | ||
block = block << 8 | charCode; | ||
output += charAt(map, 63 & block >> 8 - position % 1 * 8); | ||
} return output; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require('../modules/es.error.to-string'); | ||
require('../modules/es.object.to-string'); | ||
require('../modules/web.atob'); | ||
require('../modules/web.dom-exception.constructor'); | ||
require('../modules/web.dom-exception.stack'); | ||
require('../modules/web.dom-exception.to-string-tag'); | ||
var path = require('../internals/path'); | ||
|
||
module.exports = path.atob; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require('../modules/es.error.to-string'); | ||
require('../modules/es.object.to-string'); | ||
require('../modules/web.btoa'); | ||
require('../modules/web.dom-exception.constructor'); | ||
require('../modules/web.dom-exception.stack'); | ||
require('../modules/web.dom-exception.to-string-tag'); | ||
var path = require('../internals/path'); | ||
|
||
module.exports = path.btoa; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// based on https://github.com/davidchambers/Base64.js/blob/master/test/base64.js | ||
import atob from 'core-js-pure/stable/atob'; | ||
|
||
QUnit.test('atob', assert => { | ||
assert.isFunction(atob); | ||
assert.arity(atob, 1); | ||
|
||
assert.same(atob(''), ''); | ||
assert.same(atob('Zg=='), 'f'); | ||
assert.same(atob('Zm8='), 'fo'); | ||
assert.same(atob('Zm9v'), 'foo'); | ||
assert.same(atob('cXV1eA=='), 'quux'); | ||
assert.same(atob('ISIjJCU='), '!"#$%'); | ||
assert.same(atob('JicoKSor'), "&'()*+"); | ||
assert.same(atob('LC0uLzAxMg=='), ',-./012'); | ||
assert.same(atob('MzQ1Njc4OTo='), '3456789:'); | ||
assert.same(atob('Ozw9Pj9AQUJD'), ';<=>?@ABC'); | ||
assert.same(atob('REVGR0hJSktMTQ=='), 'DEFGHIJKLM'); | ||
assert.same(atob('Tk9QUVJTVFVWV1g='), 'NOPQRSTUVWX'); | ||
assert.same(atob('WVpbXF1eX2BhYmM='), 'YZ[\\]^_`abc'); | ||
assert.same(atob('ZGVmZ2hpamtsbW5vcA=='), 'defghijklmnop'); | ||
assert.same(atob('cXJzdHV2d3h5ent8fX4='), 'qrstuvwxyz{|}~'); | ||
assert.same(atob(' '), ''); | ||
|
||
assert.same(atob(42), atob('42')); | ||
assert.same(atob(null), atob('null')); | ||
|
||
assert.throws(() => atob(), TypeError, 'no args'); | ||
assert.throws(() => atob('a'), 'invalid #1'); | ||
assert.throws(() => atob('a '), 'invalid #2'); | ||
assert.throws(() => atob('aaaaa'), 'invalid #3'); | ||
assert.throws(() => atob('[object Object]'), 'invalid #4'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// based on https://github.com/davidchambers/Base64.js/blob/master/test/base64.js | ||
import btoa from 'core-js-pure/stable/btoa'; | ||
|
||
QUnit.test('btoa', assert => { | ||
assert.isFunction(btoa); | ||
assert.arity(btoa, 1); | ||
|
||
assert.same(btoa(''), ''); | ||
assert.same(btoa('f'), 'Zg=='); | ||
assert.same(btoa('fo'), 'Zm8='); | ||
assert.same(btoa('foo'), 'Zm9v'); | ||
assert.same(btoa('quux'), 'cXV1eA=='); | ||
assert.same(btoa('!"#$%'), 'ISIjJCU='); | ||
assert.same(btoa("&'()*+"), 'JicoKSor'); | ||
assert.same(btoa(',-./012'), 'LC0uLzAxMg=='); | ||
assert.same(btoa('3456789:'), 'MzQ1Njc4OTo='); | ||
assert.same(btoa(';<=>?@ABC'), 'Ozw9Pj9AQUJD'); | ||
assert.same(btoa('DEFGHIJKLM'), 'REVGR0hJSktMTQ=='); | ||
assert.same(btoa('NOPQRSTUVWX'), 'Tk9QUVJTVFVWV1g='); | ||
assert.same(btoa('YZ[\\]^_`abc'), 'WVpbXF1eX2BhYmM='); | ||
assert.same(btoa('defghijklmnop'), 'ZGVmZ2hpamtsbW5vcA=='); | ||
assert.same(btoa('qrstuvwxyz{|}~'), 'cXJzdHV2d3h5ent8fX4='); | ||
assert.same(btoa('qrstuvwxyz{|}~'), 'cXJzdHV2d3h5ent8fX4='); | ||
|
||
assert.same(btoa(42), btoa('42')); | ||
assert.same(btoa(null), btoa('null')); | ||
assert.same(btoa({ x: 1 }), btoa('[object Object]')); | ||
|
||
assert.throws(() => btoa(), TypeError, 'no args'); | ||
assert.throws(() => btoa('✈'), 'non-ASCII'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// based on https://github.com/davidchambers/Base64.js/blob/master/test/base64.js | ||
import { NODE } from '../helpers/constants'; | ||
|
||
QUnit.test('atob', assert => { | ||
assert.isFunction(atob); | ||
assert.arity(atob, 1); | ||
assert.name(atob, 'atob'); | ||
if (!NODE) assert.looksNative(atob); | ||
|
||
assert.same(atob(''), ''); | ||
assert.same(atob('Zg=='), 'f'); | ||
assert.same(atob('Zm8='), 'fo'); | ||
assert.same(atob('Zm9v'), 'foo'); | ||
assert.same(atob('cXV1eA=='), 'quux'); | ||
assert.same(atob('ISIjJCU='), '!"#$%'); | ||
assert.same(atob('JicoKSor'), "&'()*+"); | ||
assert.same(atob('LC0uLzAxMg=='), ',-./012'); | ||
assert.same(atob('MzQ1Njc4OTo='), '3456789:'); | ||
assert.same(atob('Ozw9Pj9AQUJD'), ';<=>?@ABC'); | ||
assert.same(atob('REVGR0hJSktMTQ=='), 'DEFGHIJKLM'); | ||
assert.same(atob('Tk9QUVJTVFVWV1g='), 'NOPQRSTUVWX'); | ||
assert.same(atob('WVpbXF1eX2BhYmM='), 'YZ[\\]^_`abc'); | ||
assert.same(atob('ZGVmZ2hpamtsbW5vcA=='), 'defghijklmnop'); | ||
assert.same(atob('cXJzdHV2d3h5ent8fX4='), 'qrstuvwxyz{|}~'); | ||
assert.same(atob(' '), ''); | ||
|
||
assert.same(atob(42), atob('42')); | ||
assert.same(atob(null), atob('null')); | ||
|
||
assert.throws(() => atob(), TypeError, 'no args'); | ||
assert.throws(() => atob('a'), 'invalid #1'); | ||
assert.throws(() => atob('a '), 'invalid #2'); | ||
assert.throws(() => atob('aaaaa'), 'invalid #3'); | ||
assert.throws(() => atob('[object Object]'), 'invalid #4'); | ||
}); |
Oops, something went wrong.