-
-
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
10 changed files
with
87 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
var $TypeError = TypeError; | ||
|
||
module.exports = function (argument) { | ||
if (typeof argument == 'string') return argument; | ||
throw new $TypeError('Argument is not a string'); | ||
}; |
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,11 @@ | ||
'use strict'; | ||
var classof = require('../internals/classof-raw'); | ||
|
||
var $TypeError = TypeError; | ||
|
||
// Perform ? RequireInternalSlot(argument, [[TypedArrayName]]) | ||
// If argument.[[TypedArrayName]] is not "Uint8Array", throw a TypeError exception | ||
module.exports = function (argument) { | ||
if (classof(argument) === 'Uint8Array') return argument; | ||
throw new $TypeError('Argument is not an Uint8Array'); | ||
}; |
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,29 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var global = require('../internals/global'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var aString = require('../internals/a-string'); | ||
|
||
var Uint8Array = global.Uint8Array; | ||
var SyntaxError = global.SyntaxError; | ||
var parseInt = global.parseInt; | ||
var NOT_HEX = /[^\da-z]/i; | ||
var exec = uncurryThis(NOT_HEX.exec); | ||
var stringSlice = uncurryThis(''.slice); | ||
|
||
// `Uint8Array.fromHex` method | ||
// https://github.com/tc39/proposal-arraybuffer-base64 | ||
if (Uint8Array) $({ target: 'Uint8Array', stat: true }, { | ||
fromHex: function fromHex(string) { | ||
aString(string); | ||
var stringLength = string.length; | ||
if (stringLength % 2) throw new SyntaxError('String should have an even number of characters'); | ||
if (exec(NOT_HEX, string)) throw new SyntaxError('String should only contain hex characters'); | ||
var resultLength = stringLength / 2; | ||
var result = new Uint8Array(resultLength); | ||
for (var i = 0; i < stringLength; i += 2) { | ||
result[i / 2] = parseInt(stringSlice(string, i, i + 2), 16); | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var global = require('../internals/global'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var anUint8Array = require('../internals/an-uint8-array'); | ||
|
||
var Uint8Array = global.Uint8Array; | ||
var numberToString = uncurryThis(1.0.toString); | ||
|
||
// `Uint8Array..prototype.toHex` method | ||
// https://github.com/tc39/proposal-arraybuffer-base64 | ||
if (Uint8Array) $({ target: 'Uint8Array', proto: true }, { | ||
toHex: function toHex() { | ||
anUint8Array(this); | ||
var result = ''; | ||
for (var i = 0, length = this.length; i < length; i++) { | ||
var hex = numberToString(this[i], 16); | ||
result += hex.length === 1 ? '0' + hex : hex; | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
// https://github.com/tc39/proposal-arraybuffer-base64 | ||
require('../modules/esnext.uint8-array.from-hex'); | ||
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