Utility Functions
General helper/utility functions. Most functions do not require stdlib
or other dependencies.
- Utility Functions
checkVersionChanged
setAppVersion
copyToClipboard
formatAddress
formatCurrency
formatCurrencyLocale
formatNumberShort
asMaybe
asMaybeNone
fromMaybe
isMaybe
isSome
isNone
getBlockchain
getBlockchainNetwork
isImageFile
isVideoFile
listSupportedNetworks
noOp
selectBlockchain
selectBlockchainNetwork
trimByteString
truncateString
- Site Menu
checkVersionChanged
App Migration helper: check if your app version has changed
function checkVersionChanged(currentVersion: string | number, APP_VERSION_KEY?: string): string;
setAppVersion
App Migration helper: set your current app version
function setAppVersion(version: string | number, APP_VERSION_KEY?: string): string;
copyToClipboard
Copy text to clipboard
function copyToClipboard(val: string): Promise<void>;
formatAddress
Requires stdlib
. Convenience over stdlib.formatAddress
function formatAddress(acc: ReachAccount): string;
formatCurrency
Requires stdlib
. UI-friendly currency formatting. Takes the decimal
places of the currency, and
an abbr
boolean which, when true, will abbreviate the formatted value
function formatCurrency(amount: any, decimals?: number | undefined, abbr?: boolean): string;
formatCurrencyLocale
Builtin JS locale currency formatter (returns comma-delineated string)
function formatCurrencyLocale(val: number): string;
formatNumberShort
Abbreviated number formatting (e.g. 1000
-> 1K
)
function formatNumberShort(val: number, decimalPlaces?: number): string;
asMaybe
Convert a value into a Maybe
value-type
function asMaybe<T>(val: T): Maybe<T>;
asMaybeNone
Generate a falsy (null
) Maybe
value
function asMaybeNone(): Maybe<T>;
fromMaybe
Extract a value from a Maybe
value, or provide a fallback
function fromMaybe<T>(mVal: Maybe<T>, format?: (v: T) => any, fallback?: any): any;
isMaybe
Assert a value is a Maybe
value
function isMaybe(mVal: any): boolean;
isSome
Assert a value is a Maybe
type that resolves to a defined value
function isSome(mVal: any): boolean;
isNone
Assert a value is a Maybe
type that resolves to null
function isNone(mVal: any): boolean;
getBlockchain
Get the current stdlib instance’s connector
(blockchain)
function getBlockchain(): string;
getBlockchainNetwork
Get current chain network. (e.g "TestNet" | "MainNet"
on Algorand)
function getBlockchainNetwork(): string;
isImageFile
Assert path
represents an image file
function isImageFile(path: string): boolean;
isVideoFile
Assert path
represents a video file
function isVideoFile(path: string): boolean;
listSupportedNetworks
/* List all networks currently supported by this library */
function listSupportedNetworks(): NetworkData[];
noOp
Doesn’t do anything. Useful when you need a function stub.
function noOp(): null;
selectBlockchain
Set current consensus network (e.g. Algorand or Ethereum). May trigger window reload. Requires an stdlib
instance.
This will affect what createConnectorAPI
returns, if you call the latter without arguments.
This function may trigger window reload if a second argument is specified.
function selectBlockchain(network: string, reload?: boolean): string;
selectBlockchainNetwork
Set network provider preference MainNet
or TestNet
(or BetaNet
on Algo). BetaNet
is only supported on Algorand.
This function may trigger window reload if a second argument is specified.
function selectBlockchainNetwork(network: "MainNet" | "TestNet" | "BetaNet", reload?: boolean): string;
trimByteString
Trims empty bytes (\0...
) from a string
function trimByteString(str: string): string;
truncateString
Shrink an address to radius
…radius
-length string. Default would be
(WXWXWXWXWXWXWXWXWXWXWXWXWXWXWXWX) => “WXWXWX…WXWXWX”
function truncateString(acct: string, radius = 6): string;