@rayvin-flow/flow-json-cadence-decoder
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

flow-json-cadence-decoder is a JavaScript library to assist in decoding Cadence JSON values found in the JSON-Cadence Data Interchange Format Spec


Installation

npm i @rayvin-flow/flow-json-cadence-decoder

Example

import { decodeCadenceValues } from '@rayvin-flow/flow-json-cadence-decoder'

const decoded = decodeCadenceValues([
  {
    name: 'OptionalWithoutValue',
    value: {
      type: 'Optional',
      value: null,
    },
  },
  {
    name: 'OptionalWithValue',
    value: {
      type: 'Optional',
      value: {
        type: 'UInt8',
        value: '123',
      },
    },
  },
  {
    name: 'BooleanTrue',
    value: {
      type: 'Bool',
      value: true,
    },
  },
  {
    name: 'BooleanFalse',
    value: {
      type: 'Bool',
      value: false,
    },
  },
  {
    name: 'String',
    value: {
      type: 'String',
      value: 'Hello, world!',
    },
  },
])

// decoded will equal
// {
//   'OptionalWithoutValue': null, 
//   'OptionalWithValue': 123,
//   'BooleanTrue': true,
//   'BooleanFalse': false,
//   'String': 'Hello, world!',
// }

Or to decode a single value:

import { decodeCadenceValue } from '@rayvin-flow/flow-json-cadence-decoder'

const decodedValue = decodeCadenceValue({
      type: 'Optional',
      value: {
        type: 'UInt8',
        value: '123',
      },
    })

// decoded will equal
// 123

Readme

Keywords

Package Sidebar

Install

npm i @rayvin-flow/flow-json-cadence-decoder

Weekly Downloads

1

Version

1.0.1

License

Apache-2.0

Unpacked Size

16 kB

Total Files

5

Last publish

Collaborators

  • chriswayoub