Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@onflow/decode

Package Overview
Dependencies
Maintainers
7
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onflow/decode

Flow SDK Decoder

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Maintainers
7
Created
Source

NOTE: Requires a Buffer polyfill

@onflow/bytes

This package provides methods that can decode a JSON-CDC payload from the Access API into JavaScript friendly types.

Install

npm install --save @onflow/decode

Usage

Decoding a Response

import { decodeResponse } from "@onflow/decode"
const decoded = await decodeResponse(myResponse)

Decoding a Response, with a Custom Decoder

A Custom Decoder is a way for users to define how to decode certain encoded types from the Access API

import { decodeResponse } from "@onflow/decode"
const decoded = await decodeResponse(myResponse, {
    "UInt8": (data) => Number(data)
})

Decoding a Response, with a Custom Decoder for a Resource

A Custom Decoder is a way for users to additionally define how to decode Resources.

import { decodeResponse } from "@onflow/decode"
const decoded = await decodeResponse(myResponse, {
    "CryptoKitty": (cryptoKitty) => ({
        name: cryptoKitty.kittyName || "Lil BUB The Magical Space Cat",
    })
})

Decoding a Response, with a Custom Decoder using Regex Lookup

You can specify Custom Decoders to be executed on types tested against with a regular expression. To denote a regular expression, write the key for that custom decoder between two slashes. Note that only global search is suppoted at this time.

import { decodeResponse } from "@onflow/decode"
const decoded = await decodeResponse(myResponse, {
    "/.CryptoKitty$/": myCryptoKittyDecoder
})

Decoding a JSON-CDC payload

You can additionally directly decode a JSON-CDC payload.

import { decode } from "@onflow/decode"

const jsonCDC = { type: "String", value: "https://discordapp.com/invite/WgAQhtB" }

const decoded = await deocde(jsonCDC)

expect(decoded).toStrictEqual("https://discordapp.com/invite/WgAQhtB")

FAQs

Package last updated on 20 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc