JSLib Reference Manual / Exports
JSLib Reference Manual#
Table of contents#
Classes#
Interfaces#
Type Aliases#
Variables#
Functions#
Type Aliases#
ChannelMessageTypes#
Ƭ ChannelMessageTypes: "ack" | "keys" | "invalid" | "ready" | "encypted"
SBChannelId#
Ƭ SBChannelId: string
SBObjectType#
Ƭ SBObjectType: "f" | "p" | "b" | "t"
Variables#
SB#
• SB: Object
Type declaration#
Functions#
_appendBuffer#
▸ _appendBuffer(buffer1, buffer2): ArrayBuffer
Appends two buffers and returns a new buffer
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
ArrayBuffer
new buffer
_assertBase64#
▸ _assertBase64(base64): boolean
Returns ‘true’ if (and only if) string is well-formed base64. Works same on browsers and nodejs.
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
boolean
_sb_assert#
▸ _sb_assert(val, msg): void
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
void
_sb_exception#
▸ _sb_exception(loc, msg): void
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
void
_sb_resolve#
▸ _sb_resolve(val): any
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
any
arrayBuffer32ToBase62#
▸ arrayBuffer32ToBase62(buffer): string
arrayBuffer32ToBase62 converts an ArrayBuffer32 to a base62 encoded string.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
ArrayBuffer32 |
Returns#
string
base62 encoded string
arrayBufferToBase64#
▸ arrayBufferToBase64(buffer, variant?): string
Standardized ‘btoa()’-like function, e.g., takes a binary string (‘b’) and returns a Base64 encoded version (‘a’ used to be short for ‘ascii’).
Parameters#
Name |
Type |
Default value |
Description |
|---|---|---|---|
|
|
|
binary string |
|
|
|
‘b64’ or ‘url’ |
Returns#
string
returns Base64 encoded string
assemblePayload#
▸ assemblePayload(data): BodyInit | null
Assemble payload
Parameters#
Name |
Type |
|---|---|
|
Returns#
BodyInit | null
base62ToArrayBuffer32#
▸ base62ToArrayBuffer32(s): ArrayBuffer
base62ToArrayBuffer32 converts a base62 encoded string to an ArrayBuffer32.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
base62 encoded string |
Returns#
ArrayBuffer
ArrayBuffer32
base62ToBase64#
▸ base62ToBase64(s): string
base62ToBase64 converts a base62 encoded string to a base64 encoded string.
Throws
Error if the string is not a valid base62 encoded string
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
base62 encoded string |
Returns#
string
base64 encoded string
base64ToArrayBuffer#
▸ base64ToArrayBuffer(str): Uint8Array
Standardized ‘atob()’ function, e.g. takes the a Base64 encoded
input and decodes it. Note: always returns Uint8Array.
Accepts both regular Base64 and the URL-friendly variant,
where + => -, / => _, and the padding character is omitted.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
string in either regular or URL-friendly representation. |
Returns#
Uint8Array
returns decoded binary result
base64ToBase62#
▸ base64ToBase62(s): string
base64ToBase62 converts a base64 encoded string to a base62 encoded string.
Throws
Error if the string is not a valid base64 encoded string
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
base64 encoded string |
Returns#
string
base62 encoded string
cleanBase32mi#
▸ cleanBase32mi(s): string
Disambiguates strings that are known to be ‘base32mi’ type
::
'base32mi': '0123456789abcdefyhEjkLmNHpFrRTUW'
This is the base32mi disambiguation table
::
[OoQD] -> '0'
[lIiJ] -> '1'
[Zz] -> '2'
[A] -> '4'
[Ss] -> '5'
[G] -> '6'
[t] -> '7'
[B] -> '8'
[gq] -> '9'
[C] -> 'c'
[Y] -> 'y'
[KxX] -> 'k'
[M] -> 'm'
[n] -> 'N'
[P] -> 'p'
[uvV] -> 'U'
[w] -> 'W'
Another way to think of it is this transform (‘.’ means no change):
::
0123456789abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ
................9.1..1.N0.9.57UUk.248c0EF6.11kLm.0p0.5..Uky2
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
string
compareBuffers#
▸ compareBuffers(a, b): boolean
Compare buffers
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
boolean
decodeB64Url#
▸ decodeB64Url(input): string
Decode b64 URL
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
string
encodeB64Url#
▸ encodeB64Url(input): string
Encode into b64 URL
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
string
encryptedContentsMakeBinary#
▸ encryptedContentsMakeBinary(o): EncryptedContentsBin
Force EncryptedContents object to binary (interface supports either string or arrays). String contents implies base64 encoding.
Parameters#
Name |
Type |
|---|---|
|
Returns#
extractPayload#
▸ extractPayload(payload): SBPayload
Extract payload - this decodes from our binary (wire) format to a JS object. This provides a binary encoding of any JSON, and it allows some elements of the JSON to be raw (binary).
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
extractPayloadV1#
▸ extractPayloadV1(payload): SBPayload
Deprecated (older version of payloads, for older channels)
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
getRandomValues#
▸ getRandomValues(buffer): Uint8Array
Fills buffer with random data
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
Uint8Array
jsonParseWrapper#
▸ jsonParseWrapper(str, loc): any
There are many problems with JSON parsing, adding a wrapper to capture more info. The ‘loc’ parameter should be a (unique) string that allows you to find the usage in the code; one approach is the line number in the file (at some point).
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
any
partition#
▸ partition(str, n): void
Partition
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
void
simpleRand256#
▸ simpleRand256(): number
Returns random number
Returns#
number
integer 0..255
simpleRandomString#
▸ simpleRandomString(n, code): string
Returns a random string in requested encoding
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
string
random string
base32mi: 0123456789abcdefyhEjkLmNHpFrRTUW