@rayvin-flow/flow-json-cadence-decoder
v1.0.1
Published
JavaScript decoder for Cadence JSON values
Downloads
7
Readme
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