Add missing Uint8Array methods for base64 and hex strings#4284
Add missing Uint8Array methods for base64 and hex strings#4284niloc132 wants to merge 1 commit intogoogle:masterfrom
Conversation
03cefd7 to
64b6c77
Compare
lauraharker
left a comment
There was a problem hiding this comment.
Thanks! This looks great overall. I've tried pulling it into the Google repo & all our tests pass.
Just have a few small stylistic/documentation nits.
| * @param {!string} string a base64 string encoded array | ||
| * @param {Uint8ArrayBase64Options=} options an object specifying how to read the base64 string | ||
| * @return {!Uint8Array} a newly created array with the specified bytes |
There was a problem hiding this comment.
Please remove the explicit ! nullability from {!string}, and add explicit nullability with ? to Uint8ArrayBase64Options.
(This is required by our internal style guide - I looked for any public wiki docs, but can't find anything... We do check for this in the linter pass in https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/lint/CheckNullabilityModifiers.java. The tl;dr, is that primitives should never have a redundant ! annotation, and all other reference types should have an explicit ? or !, since their nullability depends on whether they're a typedef/enum (non-null) or some other object (nullable by default)).
| * @param {!string} string a hex string encoded array of bytes | ||
| * @return {!Uint8Array} a newly created array with the specified bytes | ||
| * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromHex | ||
| */ | ||
| Uint8Array.fromHex = function(string) {}; | ||
|
|
||
| /** | ||
| * Sets the contents of the Uint8Array from a base64 encoded string. | ||
| * @param {!string} string a base64 string encoded array to write into this array | ||
| * @param {Uint8ArrayBase64Options=} options an object specifying how to read the base64 string | ||
| * @return {!Uint8ArraySetFromBase64Results} results about the operation | ||
| * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/setFromBase64 | ||
| */ | ||
| Uint8Array.prototype.setFromBase64 = function(string, options) {}; | ||
|
|
||
| /** | ||
| * Encodes the contents of the Uint8Array into a base64 string. | ||
| * @param {Uint8ArrayToBase64Options=} options an object specifying how to encode the base64 string | ||
| * @return {!string} a base64 encoded string representing the contents of this array | ||
| * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64 | ||
| */ | ||
| Uint8Array.prototype.toBase64 = function(options) {}; | ||
|
|
||
| /** | ||
| * Encodes the contents of the Uint8Array into a hex string. | ||
| * @return {!string} a hex encoded string representing the contents of this array |
There was a problem hiding this comment.
Same comments on ! and ? for these parameter types
|
|
||
|
|
||
| /** | ||
| * Options to use when decoding base64 into a Uint8Array. |
There was a problem hiding this comment.
Optionally - consider linking to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64#options & the other options descriptions for the other records
|
Thank you for the review, I'll try to turn this around promptly. |
No description provided.