Base functionality used throughout XY Labs TypeScript/JavaScript libraries
npm install @xylabs/sdk-js[![logo][]](https://xylabs.com)
[![main-build][]][main-build-link]
[![npm-badge][]][npm-link]
[![npm-downloads-badge][]][npm-link]
[![jsdelivr-badge][]][jsdelivr-link]
[![npm-license-badge][]](LICENSE)
[![codacy-badge][]][codacy-link]
[![codeclimate-badge][]][codeclimate-link]
[![snyk-badge][]][snyk-link]
[![socket-badge][]][socket-link]
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
@xylabs/sdk-js
*
- ApiClient
- ApiEndpoint
- AxiosJson
- AxiosJsonUncompressed
- EthAddress
- ForgetPromise
- ~~Log~~
- ConsoleLogger
- IdLogger
- LevelLogger
- SilentLogger
- IsObjectFactory
- ObjectWrapper
- ValidatorBase
- PromiseEx
- ApiConfig
- ForgetNodeConfig
- HexConfig
- Logger
- ObjectTypeConfig
- Validator
- TypeCheckConfig
- TypeCheckRequiredConfig
- TypeCheckOptionalConfig
- PromiseType
- RetryConfig
- RetryConfigWithComplete
- ApiStage
- AssertExMessageFunc
- AssertExErrorFunc
- RawAxiosJsonRequestConfig
- RawAxiosJsonRequestUncompressedConfig
- Address
- HashBitLength
- Hash
- Hex
- LogFunction
- ~~LogLevel~~
- LogLevelKey
- LogVerbosity
- LogLevelValue
- EmptyObject
- EmptyObjectOf
- JsonValue
- JsonObject
- JsonArray
- OmitStartsWith
- DeepOmitStartsWith
- DeepRestrictToStringKeys
- Optional
- Override
- ~~PartialRecord~~
- PickStartsWith
- DeepPickStartsWith
- StringKeyObject
- WithAdditional
- OmitByPredicate
- PickByPredicate
- AnyObject
- AsTypeFunction
- AsOptionalTypeFunction
- Compare
- StringOrAlertFunction
- TypeCheck
- Profiler
- PromiseExSubFunc
- PromiseExFunc
- PromiseExValueFunc
- AnyNonPromise
- Promisable
- PromisableArray
- OptionalPromisable
- OptionalPromisableArray
- NullablePromisable
- NullablePromisableArray
- AsyncMutex
- ApiStage
- getApiStage
- containsAll
- distinct
- filterAs
- filterAsync
- findAs
- findLastAs
- flatten
- uniq
- uniqBy
- axios
- axiosUncompressed
- fromFixedPoint
- toDecimalPrecision
- toFixedPoint
- delay
- handleError
- handleErrorAsync
- isError
- isEthAddress
- ellipsize
- padHex
- exists
- defaultForgetNodeConfig
- forget
- functionName
- ZERO\_ADDRESS
- toAddress
- isAddress
- ZERO\_HASH
- HashBitLength
- isHashBitLength
- isHash
- hexFrom
- hexFromArrayBuffer
- hexFromBigInt
- hexFromHexString
- hexFromNumber
- isHex
- isHexZero
- toHexLegacy
- bitsToNibbles
- nibblesToBits
- hexRegex
- hexRegexWithPrefix
- toHex
- LogLevel
- NoOpLogFunction
- getFunctionName
- AsObjectFactory
- AsTypeFactory
- isJsonValue
- isJsonArray
- isValidJsonFieldPair
- isJsonObject
- asAnyObject
- deepMerge
- isObject
- isType
- omitBy
- omitByPrefix
- pickBy
- pickByPrefix
- removeFields
- toJsonArray
- toJsonObject
- toJsonValue
- toJsonString
- toJson
- createProfiler
- profile
- profileReport
- fulfilled
- fulfilledValues
- isPromise
- rejected
- retry
- difference
- intersection
- union
- setTimeoutEx
- clearTimeoutEx
- assertDefinedEx
- assertEx
- asAddress
- asHash
- asHex
- hexToBigInt
- createDeepMerge
- toPromise
- staticImplements
*
``ts`
new ApiClient(token?, stage?): ApiClient;
#### token?
null | string
#### stage?
ApiClient
`ts`
protected optional token: null | string;
*
`ts`
protected optional stage: ApiStage;
`ts`
abstract endPoint(): string;
string
*
T
`ts`
new ApiEndpoint
#### config
#### path
string
ApiEndpoint\<T\>
`ts`
get value(): undefined | T;
#### Returns
undefined \| T
`ts`
fetch(): Promise
Promise\<T\>
*
`ts`
get(): Promise
Promise\<T \| NonNullable\<T\>\>
*
`ts`
insert(value): Promise
#### value
T
Promise\<T\>
*
- Axios
`ts`
new AxiosJson(config?): AxiosJson;
#### config?
RawAxiosJsonRequestConfig\<any\>
AxiosJson
`ts`
Axios.constructor
`ts`
static optional defaultLogger: Logger;
`ts`
static finalPath(response): any;
#### response
AxiosResponse
any
*
- Axios
`ts`
new AxiosJsonUncompressed(config?): AxiosJsonUncompressed;
#### config?
RawAxiosJsonRequestUncompressedConfig\<any\>
AxiosJsonUncompressed
`ts`
Axios.constructor
`ts`
static optional defaultLogger: Logger;
`ts`
static finalPath(response): any;
#### response
AxiosResponse
any
*
Interface to handle overlap between Winston &
console with as much congruency as possible.
`ts`
new ConsoleLogger(level?): ConsoleLogger;
#### level?
ConsoleLogger
`ts`
readonly level: LogLevelValue;
*
`ts`
readonly logger: Logger;
`ts`
get debug(): LogFunction;
#### Returns
*
`ts`
get error(): LogFunction;
#### Returns
*
`ts`
get info(): LogFunction;
#### Returns
*
`ts`
get log(): LogFunction;
#### Returns
*
`ts`
get trace(): LogFunction;
#### Returns
*
`ts`
get warn(): LogFunction;
#### Returns
*
`ts`
readonly static type: "EthAddress" = "EthAddress";
*
`ts`
type: string;
`ts`
static fromString(value?, base?): undefined | EthAddress;
#### value?
string
#### base?
number
undefined \| EthAddress
*
`ts`
static parse(value, base?): undefined | EthAddress;
#### value
unknown
#### base?
number
undefined \| EthAddress
*
`ts`
static validate(address): boolean;
#### address
string
boolean
*
`ts`
equals(address?): boolean;
#### address?
null | string | EthAddress
boolean
*
`ts`
toBigNumber(): bigint;
bigint
*
`ts`
toHex(): string;
string
*
`ts`
toJSON(): string;
string
*
`ts`
toLowerCaseString(): string;
string
*
`ts`
toShortString(length?): string;
#### length?
number
string
*
`ts`
toString(checksum?, chainId?): string;
#### checksum?
boolean
#### chainId?
string
string
*
`ts`
validate(): boolean;
boolean
*
- ForgetPromise
`ts`
new ForgetPromise(): ForgetPromiseNode;
ForgetPromiseNode
`ts`
ForgetPromise.constructor
`ts`
static activeForgets: number;
`ts`
ForgetPromise.activeForgets
*
`ts`
static exceptedForgets: number;
`ts`
ForgetPromise.exceptedForgets
*
`ts`
static logger: Logger;
`ts`
ForgetPromise.logger
`ts`
get static active(): boolean;
#### Returns
boolean
`ts`
ForgetPromise.active
`ts`
static awaitInactive(interval?, timeout?): Promise
#### interval?
number
#### timeout?
number
Promise\<number\>
`ts`
ForgetPromise.awaitInactive
*
`ts`
static exceptionHandler(
error,
config,
externalStackTrace?): void;
#### error
Error
#### config
#### externalStackTrace?
string
void
`ts`
ForgetPromise.exceptionHandler
*
`ts`
static forget
Used to explicitly launch an async function (or Promise) with awaiting it
#### T
T
#### promise
Promisable\<T\>
The promise to forget
#### config?
ForgetNodeConfig\<T\>
Configuration of forget settings
void
`ts`
ForgetPromise.forget
*
`ts`
static timeoutHandler(
time,
config,
externalStackTrace?): void;
#### time
number
#### config
#### externalStackTrace?
string
void
`ts`
ForgetPromise.timeoutHandler
*
Interface to handle overlap between Winston &
console with as much congruency as possible.
- Logger
`ts`
new IdLogger(logger, id?): IdLogger;
#### logger
#### id?
() => string
IdLogger
`ts`
set id(id): void;
#### Parameters
##### id
string
#### Returns
void
`ts`
debug(...data): void;
#### data
...unknown[]
void
`ts`
Logger.debug
*
`ts`
error(...data): void;
#### data
...unknown[]
void
`ts`
Logger.error
*
`ts`
info(...data): void;
#### data
...unknown[]
void
`ts`
Logger.info
*
`ts`
log(...data): void;
#### data
...unknown[]
void
`ts`
Logger.log
*
`ts`
trace(...data): void;
#### data
...unknown[]
void
`ts`
Logger.trace
*
`ts`
warn(...data): void;
#### data
...unknown[]
void
`ts`
Logger.warn
*
T extends TypedObject
`ts`
new IsObjectFactory
IsObjectFactory\<T\>
`ts`
create(shape?, additionalChecks?): TypeCheck
#### shape?
ObjectTypeShape
#### additionalChecks?
TypeCheck\<TypedObject\>[]
TypeCheck\<T\>
*
Interface to handle overlap between Winston &
console with as much congruency as possible.
- Logger
`ts`
new LevelLogger(logger, level?): LevelLogger;
#### logger
#### level?
LevelLogger
`ts`
readonly level: LogLevelValue;
*
`ts`
readonly logger: Logger;
`ts`
get debug(): LogFunction;
#### Returns
*
`ts`
get error(): LogFunction;
#### Returns
*
`ts`
get info(): LogFunction;
#### Returns
*
`ts`
get log(): LogFunction;
#### Returns
*
`ts`
get trace(): LogFunction;
#### Returns
*
`ts`
get warn(): LogFunction;
#### Returns
*
use @xylabs/logger instead
`ts`
new Log(config): Log;
#### config
LogConfig
Log
`ts`
protected config: LogConfig;
`ts`
debug(...params): void;
#### params
...any[]
void
*
`ts`
error(...params): void;
#### params
...any[]
void
*
`ts`
info(...params): void;
#### params
...any[]
void
*
`ts`
log(...params): void;
#### params
...any[]
void
*
`ts`
warn(...params): void;
#### params
...any[]
void
*
T extends EmptyObject = EmptyObject
`ts`
new ObjectWrapper
#### obj
T
ObjectWrapper\<T\>
`ts`
readonly obj: T;
`ts`
get protected stringKeyObj(): StringKeyObject;
#### Returns
*
- Promise\<T\>
T
V = void
`ts`
new PromiseEx
#### func
PromiseExFunc\<T\>
#### value?
V
PromiseEx\<T, V\>
`ts`
Promise
`ts`
optional cancelled: boolean;
`ts`
then
onfulfilled?,
onrejected?,
onvalue?): Promise
Attaches callbacks for the resolution and/or rejection of the Promise.
#### TResult1
TResult1 = T
#### TResult2
TResult2 = never
#### onfulfilled?
The callback to execute when the Promise is resolved.
null | (value) => TResult1 \| PromiseLike\<TResult1\>
#### onrejected?
The callback to execute when the Promise is rejected.
null | (reason) => TResult2 \| PromiseLike\<TResult2\>
#### onvalue?
(value?) => boolean
Promise\<TResult1 \| TResult2\>
A Promise for the completion of which ever callback is executed.
`ts`
Promise.then
*
`ts`
value(onvalue?): this;
#### onvalue?
(value?) => boolean
this
*
A logger that does not log anything.
This is useful when you want to disable logging
like when running unit tests or in silent mode.
It implements the Logger interface but all methods
are no-op functions.
- Logger
`ts`
new SilentLogger(): SilentLogger;
SilentLogger
`ts`
readonly debug: (..._data) => undefined;
#### \_data
...unknown[]
undefined
*
`ts`
readonly error: (..._data) => undefined;
#### \_data
...unknown[]
undefined
*
`ts`
readonly info: (..._data) => undefined;
#### \_data
...unknown[]
undefined
*
`ts`
readonly log: (..._data) => undefined;
#### \_data
...unknown[]
undefined
*
`ts`
readonly trace: (..._data) => undefined;
#### \_data
...unknown[]
undefined
*
`ts`
readonly warn: (..._data) => undefined;
#### \_data
...unknown[]
undefined
*
- ObjectWrapper\<Partial\<T\>\>
T extends EmptyObject = AnyObject
- Validator\<T\>
`ts`
new ValidatorBase
#### obj
T
ValidatorBase\<T\>
`ts`
readonly obj: T;
`ts`
get protected stringKeyObj(): StringKeyObject;
#### Returns
`ts`
abstract validate(payload): Promisable
#### payload
T
Promisable\<Error[]\>
*
`ts`
function asAddress(value): undefined | Lowercase
unknown
undefined \| Lowercase\<string\>
`ts`
function asAddress(value, assert): Lowercase
unknown
AssertConfig
Lowercase\<string\>
*
`ts`
function asHash(value): undefined | Lowercase
unknown
undefined \| Lowercase\<string\>
`ts`
function asHash(value, assert): Lowercase
unknown
AssertConfig
Lowercase\<string\>
*
`ts`
function asHex(value): undefined | Lowercase
unknown
undefined \| Lowercase\<string\>
`ts`
function asHex(value, assert): Lowercase
unknown
AssertConfig
Lowercase\<string\>
*
`ts`
function assertDefinedEx
Intended for defined checks for variables
T
Expression to be evaluated for truthiness
undefined | T
AssertExMessageFunc\<T\>
T
Value of expression
AssertExError
`ts`
function assertDefinedEx
Intended for defined checks for variables
T
R extends Error
Expression to be evaluated for truthiness
undefined | T
AssertExErrorFunc\<T, R\>
T
Value of expression
AssertExError
`ts`
function assertDefinedEx
T
undefined | T
T
- passing a message will soon be required
`ts`
function assertDefinedEx
T
undefined | T
string
T
- replace string with () => string
*
`ts`
function assertEx
Intended for simple truthiness checks for variables
T
Expression to be evaluated for truthiness
undefined | null | T
AssertExMessageFunc\<T\>
T
Value of expression
AssertExError
`ts`
function assertEx
Intended for simple truthiness checks for variables
T
R extends Error
Expression to be evaluated for truthiness
undefined | null | T
AssertExErrorFunc\<T, R\>
T
Value of expression
AssertExError
`ts`
function assertEx
T
undefined | null | T
T
- passing a message will soon be required
`ts`
function assertEx
T
undefined | null | T
string
T
- replace string with () => string
*
`ts`
function createDeepMerge(options):
Creates a deep merge function with the specified options.
MergeOptions
Options for merging.
A deep merge function configured for the specified options.
`ts`
...T
MergeAll\<T\>
*
`ts`
function hexToBigInt(hex): bigint;
Lowercase\<string\>
bigint
*
`ts`
function staticImplements
Annotation to decorate classes which implement static methods
T
The decorated class requiring it to implement
the members of the the type as static properties/methods
`ts`
(constructor): void;
U
U
void
*
`ts`
function toPromise
T
Promisable\<T\>
Promise\<T\>
*
`ts`
apiDomain: string;
*
`ts`
optional apiKey: string;
*
`ts`
optional jwtToken: string;
*
`ts`
optional userid: string;
*
- ForgetConfig\<T\>
T = any
`ts`
optional name: string;
`ts`
ForgetConfig.name
*
`ts`
optional onCancel: () => void;
void
`ts`
ForgetConfig.onCancel
*
`ts`
optional onComplete: (result) => void;
#### result
\[undefined \| T, undefined \| Error\]
void
`ts`
ForgetConfig.onComplete
*
`ts`
optional onException: (error) => void;
#### error
Error
void
`ts`
ForgetConfig.onException
*
`ts`
optional timeout: number;
`ts`
ForgetConfig.timeout
*
`ts`
optional terminateOnException: boolean;
*
`ts`
optional terminateOnTimeout: boolean;
*
Configuration of validation and output format
`ts`
optional bitLength: number;
*
`ts`
optional byteSize: number;
*
`ts`
optional prefix: boolean;
*
Interface to handle overlap between Winston &
console with as much congruency as possible.
`ts`
debug: LogFunction;
*
`ts`
error: LogFunction;
*
`ts`
info: LogFunction;
*
`ts`
log: LogFunction;
*
`ts`
trace: LogFunction;
*
`ts`
warn: LogFunction;
*
`ts`
optional log: boolean | Logger;
*
`ts`
then: () => unknown;
unknown
*
`ts`
optional backoff: number;
*
`ts`
optional interval: number;
*
`ts`
optional retries: number;
*
T = unknown
`ts`
optional backoff: number;
*
`ts`
optional interval: number;
*
`ts`
optional retries: number;
*
`ts`
optional complete: (result?) => boolean;
#### result?
T
boolean
*
- ObjectTypeConfig
- TypeCheckRequiredConfig
- TypeCheckOptionalConfig
`ts`
optional log: boolean | Logger;
*
`ts`
optional log: boolean | Logger;
*
`ts`
required: false;
*
`ts`
optional log: boolean | Logger;
*
`ts`
required: true;
*
T extends EmptyObject = AnyObject
`ts`
validate(payload): Promisable
#### payload
T
Promisable\<Error[]\>
*
`ts`
type Address = Exclude
*
`ts`
type AnyNonPromise = Exclude
*
`ts`
type AnyObject = Record
Any object, which means that it does not enforce the set of fields that it has. Extending from AnyObject
will result in a type that includes the universal set of field names
*
`ts`
type ApiStage = EnumValue
*
`ts`
type AsOptionalTypeFunction
T extends AnyNonPromise = AnyNonPromise
undefined \| TType
*
`ts`
type AsTypeFunction
};
T extends AnyNonPromise = AnyNonPromise
`ts`
undefined \| TType
`ts`
TType
`ts`
TypeCheckConfig | TypeCheckOptionalConfig
undefined \| TType
`ts`
StringOrAlertFunction\<TType\>
undefined \| TType
`ts`
value,
assert,
config): TType;
StringOrAlertFunction\<TType\>
TType
`ts`
value,
assert,
config): undefined | TType;
StringOrAlertFunction\<TType\>
TypeCheckConfig | TypeCheckOptionalConfig
undefined \| TType
*
`ts`
type AssertExErrorFunc
T
R extends Error
T | null
R
*
`ts`
type AssertExMessageFunc
T
T | null
string
*
`ts`
type AsyncMutex
T
Used to document promises that are being used as Mutexes
*
`ts`
type Compare
T
T
T
number
*
`ts${Prefix}${string}
type DeepOmitStartsWith ? never : K : K]: DeepOmitStartsWith`
T
Prefix extends string
*
`ts${Prefix}${string}
type DeepPickStartsWith ? K : never : K]: DeepPickStartsWith`
T
Prefix extends string
*
`ts`
type DeepRestrictToStringKeys
T
*
`ts`
type EmptyObject
An empty object, which means that it does enforce the set of field names, defaulting to an empty set until
extended from, which then adds only those additional fields
T extends object = object
*
`ts`
type EmptyObjectOf
T extends object
*
`ts`
type Hash = Exclude
*
`ts`
type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
*
`ts`
type Hex = Exclude
*
`ts`
type JsonArray = JsonValue[];
*
`ts`
type JsonObject = object;
`ts`
[key: string]: JsonValue
*
`ts`
type JsonValue =
| string
| number
| boolean
| null
| JsonObject
| JsonArray;
*
`ts`
type LogFunction = (...data) => void;
...unknown[]
void
*
`ts`
type LogLevel = LogLevelValue;
Use LogLevelValue instead.LogLevel
This name conflicts with the enum and
makes it confusing to import
*
`ts`
type LogLevelKey = EnumKey
*
`ts`
type LogLevelValue = EnumValue
*
`ts`
type LogVerbosity = LogLevelKey;
*
`ts`
type NullablePromisable
T
V = never
*
`ts`
type NullablePromisableArray
T
V = never
*
`ts`
type OmitByPredicate
T extends EmptyObject = Record\<string, unknown\>
T\[keyof T\]
keyof T
boolean
*
`ts${Prefix}${string}
type OmitStartsWith ? never : K]: T[K] };`
T
Prefix extends string
*
`ts`
type Optional
T extends object
F extends keyof T
*
`ts`
type OptionalPromisable
T
V = never
*
`ts`
type OptionalPromisableArray
T
V = never
*
`ts`
type Override
T1
T2
*
`ts`
type PartialRecord
K extends keyof any
T
use Partial
*
`ts`
type PickByPredicate
T extends EmptyObject = Record\<string, unknown\>
T\[keyof T\]
keyof T
boolean
*
`ts${Prefix}${string}
type PickStartsWith ? K : never]: T[K] };`
T
Prefix extends string
*
`ts`
type Profiler = Record
*
`ts`
type Promisable
T
V = never
*
`ts`
type PromisableArray
T
V = never
*
`ts`
type PromiseExFunc
T
PromiseExSubFunc\<T, void\>
PromiseExSubFunc\<T, void\>
void
*
`ts`
type PromiseExSubFunc
T
TResult = T
T
TResult
*
`ts`
type PromiseExValueFunc
V
V
boolean
*
`ts`
type RawAxiosJsonRequestConfig
`ts`
optional compressLength: number;
D = any
### RawAxiosJsonRequestUncompressedConfig
*
`ts`
type RawAxiosJsonRequestUncompressedConfig
D = any
*
`ts`
type StringKeyObject
T = unknown
`ts`
[key: string]: T
*
`ts`
type StringOrAlertFunction
*
`ts`
type TypeCheck
(obj): obj is T;
(obj, config): obj is T;
(obj, config): obj is T;
};
T extends TypedValue
`ts`
(obj): obj is T;
obj is T
`ts`
(obj, config): obj is T;
obj is T
`ts`
(obj, config): obj is T;
undefined | number | TypeCheckConfig
obj is T
*
`ts`
type WithAdditional
TAdditional extends EmptyObject \| void = void
*
`ts`
const ApiStage: Enum<{
Beta: "beta";
Local: "local";
Prod: "prod";
}>;
*
`ts`
const AsObjectFactory: object;
`ts`
create:
#### T
T extends TypedObject
#### typeCheck
TypeCheck\<T\>
`ts`
createOptional:
#### T
T extends TypedObject
#### typeCheck
TypeCheck\<T\>
`ts`
(value): T | undefined;
#### Parameters
##### value
#### Returns
T \| undefined
*
`ts`
const AsTypeFactory: object;
`ts`
create:
#### T
#### typeCheck
TypeCheck\<T\>
AsTypeFunction\<T\>
`ts`
createOptional:
#### T
#### typeCheck
TypeCheck\<T\>
`ts`
(value): T | undefined;
#### Parameters
##### value
#### Returns
T \| undefined
*
`ts`
HashBitLength: HashBitLength[];
*
`ts`
const LogLevel: Enum<{
error: 1;
warn: 2;
info: 3;
log: 4;
debug: 5;
trace: 6;
}>;
*
`ts`
const NoOpLogFunction: (..._data) => undefined;
...unknown[]
undefined
*
`ts`
const ZERO_ADDRESS: Address;
*
`ts`
const ZERO_HASH: Hash;
*
`ts`
const asAnyObject: AsTypeFunction;
*
`ts`
const axios: AxiosJson;
*
`ts`
const axiosUncompressed: AxiosJsonUncompressed;
*
`ts`
const bitsToNibbles: (value) => number;
number
number
*
`ts`
const clearTimeoutEx: (id) => void;
string
void
*
`ts`
const containsAll:
T
T[]
T[]
boolean
*
`ts`
const createProfiler: () => Profiler;
*
`ts`
const deepMerge:
Deeply merges multiple objects into a new object.
...T
Multiple objects to merge deeply.
The function merges properties from all objects into a new object.
If a property exists in multiple objects, the last object's value will be used.
If a property is an object, it will be merged recursively.
If a property is an array, it will be overwritten by the last object's value.
If a property is a primitive value, it will be overwritten by the last object's value.
If a property is undefined in the source, it will be skipped.
If a property is a symbol, it will be merged as well.
MergeAll\<T\>
A new object with the merged properties.
*
`ts`
const defaultForgetNodeConfig: ForgetNodeConfig
*
`ts`
const delay: (ms) => Promise
number
Promise\<unknown\>
*
`ts`
const difference:
TKey
Set\<TKey\>
Set\<TKey\>
Set\<TKey\>
*
`ts`
const distinct:
T
T
number
T[]
boolean
*
`ts`
const ellipsize: (value, length?) => string;
string
number
string
*
`ts`
const exists:
Used to type narrow an object which is possibly null or undefined. Works well
with functional Array methods. For example:
T
The object which is potentially undefined or null
T | null
x is NonNullable
False if the object is null/undefined, true otherwise
`ts`
const payloads: XyoPayload[] = boundWitness._payloads?.filter(exists) || []
*
`ts`
const filterAs:
In
Out
In[]
(a) => Out
NonNullable\<Out\>[]
*
`ts`
const filterAsync:
Returns the elements of an array that meet the condition specified in a callback function.
T
T[]
The array to filter.
(value, index, array) => Promise\<boolean\>
A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
Promise\<T[]\>
The elements of an array that meet the condition specified in a callback function.
*
`ts`
const findAs:
In
Out
In[]
(a) => Out
NonNullable\<Out\> \| undefined
*
`ts`
const findLastAs:
In
Out
In[]
(a) => Out
NonNullable\<Out\> \| undefined
*
`ts`
const flatten:
T
T | ConcatArray\<T\>
T | ConcatArray\<T\>
T[]
*
`ts`
const forget:
T
Promisable\<T\>
ForgetNodeConfig\<T\>
void
*
`ts`
const fromFixedPoint: (value, places?) => bigint;
bigint
number
bigint
*
`ts`
const fulfilled:
For use with Promise.allSettled to filter only successful results
T
PromiseSettledResult\<T\>
val is PromiseFulfilledResult
*
`ts`
const fulfilledValues:
For use with Promise.allSettled to reduce to only successful result values
T
T[]
PromiseSettledResult\<T\>
T[]
`ts`
const resolved = Promise.resolve('resolved')
const rejected = Promise.reject('rejected')
const settled = await Promise.allSettled([resolved, rejected])
const results = settled.reduce(fulfilledValues, [] as string[])
// results === [ 'resolved' ]
`ts`
const resolved = Promise.resolve('resolved')
const rejected = Promise.reject('rejected')
const settled = await Promise.allSettled([resolved, rejected])
const results = settled.reduce
// results === [ 'resolved' ]
*
`ts`
const functionName: (depth?) => string;
number
string
*
`ts`
const getApiStage: (hostname) => "beta" | "local" | "prod";
string
"beta" \| "local" \| "prod"
*
`ts`
const getFunctionName: (depth?) => string;
number
string
*
`ts`
const handleError:
T
any
(error) => T
T
*
`ts`
const handleErrorAsync:
T
any
(error) => Promise\<T\>
Promise\<T\>
*
`ts`
const hexFrom: (value, config?) => Hex;
Takes unknown value and tries our best to convert it to a hex string
string | number | bigint | ArrayBufferLike
*
`ts`
const hexFromArrayBuffer: (buffer, config?) => Hex;
Convert an ArrayBuffer to a hex string
ArrayBufferLike
*
`ts`
const hexFromBigInt: (value, config?) => Hex;
Convert a bigint to a hex string
bigint
*
`ts`
const hexFromHexString: (value, config?) => Hex;
string
*
`ts`
const hexFromNumber: (value, config?) => Hex;
number
*
`ts`
const hexRegex: RegExp;
*
`ts`
const hexRegexWithPrefix: RegExp;
*
`ts``
const intersection: