String, TypedArray and Base64 encoders/decoders.
- Copyright:
- Mat. 2018-present
- License:
- Apache-2.0
- Source:
Methods
(inner) b64ToHex(input) → {String}
Covert a given b64-encoded string to a hex-encoded string.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
input |
String
|
Returns:
- Type:
-
String
(inner) b64ToString(s) → {String}
Base64 decoding for strings (b64-string to utf8-string).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
s |
String
|
Returns:
- Type:
-
String
(inner) b64dec(s) → {Uint8Array}
Decode given Base64-encoded string into byte array (Uint8Array).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
s |
String
|
Returns:
- Type:
-
Uint8Array
(inner) b64enc(bytes) → {String}
Base64-encode given byte array (Uint8Array).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
bytes |
Uint8Array
|
Returns:
- Type:
-
String
(inner) bytesToHex(bytes) → {String}
Convert a given byte array (Uint8Array) to a hex-encoded string. Each byte is encoded on the two hexadecimal digits.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
bytes |
Uint8Array
|
Returns:
- Type:
-
String
(inner) bytesToString(bytes) → {String}
Convert a given byte array (Uint8Array) to an utf8-encoded string.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
bytes |
Uint8Array
|
Returns:
- Type:
-
String
(inner) compareBytes(u8a1, u8a2) → {Boolean}
Compare two byte arrays.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
u8a1 |
Uint8Array
|
|
u8a2 |
Uint8Array
|
Returns:
- Type:
-
Boolean
(inner) concatBytes(…u8as) → {Uint8Array}
Concatenate contents of a given byte arrays (Uint8Array) into a new byte array (Uint8Array).
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
u8as |
Uint8Array
|
<repeatable> |
Returns:
- Type:
-
Uint8Array
(inner) csv(input, sepopt)
Parse input string as a CSV data.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
String
|
csv text |
||
sep |
String
|
<optional> |
"," |
default field separator |
Returns:
Array of parsed lines - each line is an array of string fields.
(inner) hexToB64(input) → {String}
Covert a given hex-encoded string to a b64-encoded string.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
input |
String
|
Returns:
- Type:
-
String
(inner) hexToBytes(input) → {Uint8Array}
Convert a hex-encoded string to a byte array (Uint8Array).
If given hexInput
is of odd length (hexInput.length % 2 !== 0)
then the last hex-digit is treated as full byte representation,
i.e.:
hexToBytes("fa6") <=> hexToBytes("fa06") <=> Uint8Array [ 250, 6 ]
All unrecognized hex-digit groups (e.g. "zz") are treated
by parseInt()
as NaN
and then effectively converted
to Uint8Array [ 0 ]
.
Input parameter (hexInput
) can be prefixed with 0x
.
All whitespaces, tabs and carriage returns are stripped out from the input.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
input |
String
|
Returns:
- Type:
-
Uint8Array
(async, inner) random(sizeopt) → {Promise.<Uint8Array>}
Get random bytes.
Uses Web Crypto API when in browser
and crypto
module when in node.js.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
size |
Number
|
<optional> |
64 |
Returns:
- Type:
-
Promise.<Uint8Array>
(inner) stringToB64(s) → {String}
Base64 encoding for strings (utf8-string to b64-string)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
s |
String
|
Returns:
- Type:
-
String
(inner) stringToBytes(s) → {Uint8Array}
Convert a given utf8-encoded string to byte array (Uint8Array).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
s |
String
|
Returns:
- Type:
-
Uint8Array
(inner) timestamp() → {Uint8Array}
Generate 48 bits (6 bytes) timestamp - milliseconds since epoch.
- Source:
Returns:
- Type:
-
Uint8Array