Skip to content

Commit

Permalink
feat: export encode/decode -Options
Browse files Browse the repository at this point in the history
These options are being exported so they can be used with
cborg's API, specifically the `decodeFirst` and `encodedLength` functions.
  • Loading branch information
tabcat committed Jan 26, 2024
1 parent fa09fe4 commit 5bb52b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function numberEncoder (num) {
return null
}

const encodeOptions = {
export const encodeOptions = {
float64: true,
typeEncoders: {
Object: cidEncoder,
Expand All @@ -84,7 +84,7 @@ function cidDecoder (bytes) {
return CID.decode(bytes.subarray(1)) // ignore leading 0x00
}

const decodeOptions = {
export const decodeOptions = {
allowIndefinite: false,
coerceUndefinedToNull: true,
allowNaN: false,
Expand Down
7 changes: 7 additions & 0 deletions test/test-basics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,11 @@ describe('dag-cbor', () => {
const encoded = bytes.fromHex('a3636261720363666f6f0163666f6f02')
assert.throws(() => decode(encoded), /CBOR decode error: found repeat map key "foo"/)
})

test('exports encode and decode options', () => {
const { encodeOptions, decodeOptions } = dagcbor

assert.isDefined(encodeOptions)
assert.isDefined(decodeOptions)
})
})

0 comments on commit 5bb52b7

Please sign in to comment.