@bloom-labs/url
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

@bloom-labs/url

@bloom-labs/url downloads CI

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 link
    • false by default, resulting in the build and parse functions returning undefined 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:

Package Sidebar

Install

npm i @bloom-labs/url

Weekly Downloads

10

Version

0.4.0

License

MIT

Unpacked Size

39.9 kB

Total Files

48

Last publish

Collaborators

  • jeeanribeiro
  • maxwellmattryan