@bloom-labs/url
v0.4.0
Published
Typescript library for building and parsing Bloom deep links
Downloads
16
Readme
@bloom-labs/url
TypeScript library for building and parsing Bloom deep links.
Installation
# NPM
npm i @bloom-labs/url
# Yarn
yarn add @bloom-labs/url
Usage
Building
import { buildDeepLink, BloomDeepLinkContext, WalletOperation } from '@bloom-labs/url'
const deepLink = buildDeepLink({
context: BloomDeepLinkContext.Wallet,
operation: WalletOperation.ImportToken,
parameters: {
chainId: 1071,
tokenAddress: '0x7EA2be2df7BA6E54B1A9C70676f668455E329d29',
}
})
console.log(deepLink)
// bloom://wallet/importToken?chainId=1071&tokenAddress=0x7EA2be2df7BA6E54B1A9C70676f668455E329d29
Parsing
import { parseDeepLink } from '@bloom-labs/url'
const deepLink = parseDeepLink('bloom://wallet/importToken?chainId=1071&tokenAddress=0x7EA2be2df7BA6E54B1A9C70676f668455E329d29')
console.log(deepLink)
// {
// protocol: BloomDeepLinkProtocol.Beta,
// context: BloomDeepLinkContext.Wallet,
// operation: WalletOperation.ImportToken,
// parameters: {
// chainId: 1071,
// tokenAddress: '0x7EA2be2df7BA6E54B1A9C70676f668455E329d29',
// },
// }
Configuring
It is possible to configure the library when using the build and parse functions to suit your particular needs. The following options are supported:
throwError
: tells the library if it should throw an error when building or parsing a deep linkfalse
by default, resulting in the build and parse functions returningundefined
in the case of an error
The way to set these parameters is simple:
import { buildDeepLink, IBloomDeepLinkLibraryConfiguration } from '@bloom-labs/url'
const config: IBloomDeepLinkLibraryConfiguration = {
throwError: true,
}
const deepLink = buildDeepLink({}, config) // throws an error
Contributing
Please feel free to make a contribution in the following ways:
- Filing a bug report
- Creating a pull request