Methods

static

appendToArray(array, value)

Append the elements in value to the end of array. This should be used instead of concat since it avoids creating a new array and the memory allocation/copy associated with it.

Parameters

Name Type Optional Description

array

Array

 

An array to which items should be appended.

value

Array

 

An array of values to append.

static

array2hex(array) → string

Returns the hex string representation of the given byte array.

Parameter

Name Type Optional Description

array

Uint8Array

 

The array whose hex representation is desired.

Returns

string 

The hex representation of the array.

static

base64urlDecode(value) → string

Decode the given string value from a base64 encoded string or a base64url encoded string. Valid padding is optional for all input.

Parameter

Name Type Optional Description

value

string

 

The string to be decoded.

Throws

Error 

When it has been determined that the encoding is invalid.

Returns

string 

The decoded value.

static

base64UrlDecodeByteArray(str) → Uint8Array

Decode the given base64 or base64url encoded string and return a byte array of the decoded data. Valid padding is optional for all input.

Parameter

Name Type Optional Description

str

string

 

The base64 or base64url encoded string to decode.

Throws

Error 

When it has been determined that the encoding is invalid.

Returns

Uint8Array 

The decoded byte array.

static

base64urlEncode(value) → string

Encode the given string value to a base64url string that does not include any padding.

Parameter

Name Type Optional Description

value

string

 

The string value to be encoded. The bytes encoded in base64 are the bytes of the string interpreted as UTF-8.

Returns

string 

The base64url string without padding characters.

static

base64UrlEncodeByteArray(array) → string

Encode the given byte array to a base64url string that does not include any padding.

Parameter

Name Type Optional Description

array

Uint8Array

 

The byte array to be encoded.

Returns

string 

The base64url string without padding characters.

static

hex2array(hex) → Uint8Array

Returns the byte array representation of the given hex encoded string.

Parameter

Name Type Optional Description

hex

string

 

The hexadecimal string representation of the data. When the string is not empty, it must contain only an even number of characters, which can be upper- or lowercase.

Throws

Error 

When the hex string contains illegal characters or cannot be converted in its entirety to a byte array.

Returns

Uint8Array 

The byte array representation of the data.

static

spliceArray(array, position, deleteCount, value, begin, end) → number

Insert the elements of value into the given array at the desired position. No elements will be removed from array during this operation.

Parameters

Name Type Optional Description

array

Array

 

The array into which the elements of value will be inserted.

position

number

 

The position in the given array where the insert is to be made. This should be set to array.length to perform the insertion at the end of the array.

deleteCount

number

 

The number of elements from the insertion position to remove as part of the insertion. The values in the range [position, position + deleteCount) will be removed from the given array.

value

Array

 

The value whose elements in the range [begin, end) are to be inserted into the given array.

begin

number

 

The inclusive beginning of the index range that determines which elements of the value array are inserted into the given array.

end

number

 

The exclusive end of the index range that determines which elements of the value array are inserted into the given array. This should be set to value.length to include the last element in the value array in the inserted data.

Returns

number 

The number of elements spliced into the array.

static

truncate(value, maxCodePoints) → string

Returns the truncated version of the given UTF-16 string, value, that contains no more than than the specified maximum number of code points, maxCodePoints.

If the input value isn't a string, it is returned as-is.

Parameters

Name Type Optional Description

value

string

 

The string value to be truncated.

maxCodePoints

number

 

The maximum number of code points to retain in the given value. This must be an integer greater than or equal to 0.

Returns

string 

The truncated string value.