1.0.1 • Published 3 years ago

@rayvin-flow/flow-json-cadence-decoder v1.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

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