-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
13 changed files
with
101 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
'use strict'; | ||
var itoc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | ||
var ctoi = {}; | ||
var commonAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
var base64Alphabet = commonAlphabet + '+/'; | ||
var base64UrlAlphabet = commonAlphabet + '-_'; | ||
|
||
for (var index = 0; index < 64; index++) ctoi[itoc.charAt(index)] = index; | ||
var inverse = function (characters) { | ||
var result = {}; | ||
var index = 0; | ||
for (; index < 64; index++) result[characters.charAt(index)] = index; | ||
return result; | ||
}; | ||
|
||
module.exports = { | ||
itoc: itoc, | ||
ctoi: ctoi | ||
i2c: base64Alphabet, | ||
c2i: inverse(base64Alphabet), | ||
i2cUrl: base64UrlAlphabet, | ||
c2iUrl: inverse(base64UrlAlphabet) | ||
}; |
16 changes: 16 additions & 0 deletions
16
packages/core-js/modules/esnext.uint8-array.from-base64.js
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,16 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var global = require('../internals/global'); | ||
var aString = require('../internals/a-string'); | ||
|
||
var Uint8Array = global.Uint8Array; | ||
|
||
// `Uint8Array.fromBase64` method | ||
// https://github.com/tc39/proposal-arraybuffer-base64 | ||
if (Uint8Array) $({ target: 'Uint8Array', stat: true, forced: true }, { | ||
fromBase64: function fromBase64(string) { | ||
aString(string); | ||
// TODO | ||
return new Uint8Array(8); | ||
} | ||
}); |
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,51 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var global = require('../internals/global'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var isObject = require('../internals/is-object'); | ||
var anUint8Array = require('../internals/an-uint8-array'); | ||
var base64Map = require('../internals/base64-map'); | ||
|
||
var base64Alphabet = base64Map.i2c; | ||
var base64UrlAlphabet = base64Map.i2cUrl; | ||
|
||
var Uint8Array = global.Uint8Array; | ||
var TypeError = global.TypeError; | ||
var charAt = uncurryThis(''.charAt); | ||
var BASE64 = 'base64'; | ||
|
||
// `Uint8Array..prototype.toBase64` method | ||
// https://github.com/tc39/proposal-arraybuffer-base64 | ||
if (Uint8Array) $({ target: 'Uint8Array', proto: true, forced: true }, { | ||
toBase64: function toBase64(options) { | ||
var array = anUint8Array(this); | ||
if (options !== undefined && !isObject(options)) throw new TypeError('Incorrect options'); | ||
var $alphabet = options && options.alphabet; | ||
if ($alphabet === undefined) $alphabet = BASE64; | ||
if ($alphabet !== BASE64 && $alphabet !== 'base64url') throw new TypeError('Incorrect `alphabet` option'); | ||
var alphabet = $alphabet === BASE64 ? base64Alphabet : base64UrlAlphabet; | ||
|
||
var result = ''; | ||
var i = 0; | ||
var length = array.length; | ||
var triplet; | ||
|
||
var at = function (bit) { | ||
return charAt(alphabet, (triplet >> bit) & 63); | ||
}; | ||
|
||
for (; i + 2 < length; i += 3) { | ||
triplet = (array[i] << 16) + (array[i + 1] << 8) + array[i + 2]; | ||
result += at(18) + at(12) + at(6) + at(0); | ||
} | ||
if (i + 2 === length) { | ||
triplet = (array[i] << 16) + (array[i + 1] << 8); | ||
result += at(18) + at(12) + at(6) + '='; | ||
} else if (i + 1 === length) { | ||
triplet = array[i] << 16; | ||
result += at(18) + at(12) + '=='; | ||
} | ||
|
||
return result; | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
'use strict'; | ||
// https://github.com/tc39/proposal-arraybuffer-base64 | ||
require('../modules/esnext.uint8-array.from-base64'); | ||
require('../modules/esnext.uint8-array.from-hex'); | ||
require('../modules/esnext.uint8-array.to-base64'); | ||
require('../modules/esnext.uint8-array.to-hex'); |
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