Skip to content

Commit 23f3e93

Browse files
authored
BREAKING: remove print, use getName instead (#72)
License: MIT Signed-off-by: Henrique Dias <[email protected]>
1 parent 4d81f9f commit 23f3e93

File tree

4 files changed

+14
-32
lines changed

4 files changed

+14
-32
lines changed

src/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function getCodec (prefixedData) {
6969
}
7070

7171
/**
72-
* Get the name of the codec.
72+
* Get the name of the codec (human friendly).
7373
*
7474
* @param {CodecNumber} codec
7575
* @returns {CodecName|undefined}
@@ -129,9 +129,6 @@ function getVarint (code) {
129129
// Make the constants top-level constants
130130
const constants = require('./constants')
131131

132-
// Human friendly names for printing, e.g. in error messages
133-
const print = require('./print')
134-
135132
module.exports = {
136133
addPrefix,
137134
rmPrefix,
@@ -141,6 +138,5 @@ module.exports = {
141138
getCode,
142139
getCodeVarint,
143140
getVarint,
144-
print,
145141
...constants
146142
}

src/int-table.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ const nameTable = new Map()
1212

1313
for (const encodingName in baseTable) {
1414
const code = baseTable[encodingName]
15-
nameTable.set(code, /** @type {CodecName} */(encodingName))
15+
if (!nameTable.has(code)) {
16+
nameTable.set(code, /** @type {CodecName} */(encodingName))
17+
}
1618
}
1719

1820
module.exports = Object.freeze(nameTable)

src/print.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

test/multicodec.spec.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,20 @@ describe('multicodec', () => {
7373
})
7474

7575
it('returns the name from codec number', () => {
76-
expect(multicodec.print[144]).to.eql('eth-block')
77-
expect(multicodec.print[112]).to.eql('dag-pb')
78-
expect(multicodec.print[0x0111]).to.eql('udp')
79-
expect(multicodec.print[0xb201]).to.eql('blake2b-8')
80-
81-
expect(multicodec.print[multicodec.ETH_BLOCK]).to.eql('eth-block')
82-
expect(multicodec.print[multicodec.DAG_PB]).to.eql('dag-pb')
83-
expect(multicodec.print[multicodec.UDP]).to.eql('udp')
84-
expect(multicodec.print[multicodec.BLAKE2B_8]).to.eql('blake2b-8')
76+
expect(multicodec.getName(144)).to.eql('eth-block')
77+
expect(multicodec.getName(112)).to.eql('dag-pb')
78+
expect(multicodec.getName(0x0111)).to.eql('udp')
79+
expect(multicodec.getName(0xb201)).to.eql('blake2b-8')
80+
81+
expect(multicodec.getName(multicodec.ETH_BLOCK)).to.eql('eth-block')
82+
expect(multicodec.getName(multicodec.DAG_PB)).to.eql('dag-pb')
83+
expect(multicodec.getName(multicodec.UDP)).to.eql('udp')
84+
expect(multicodec.getName(multicodec.BLAKE2B_8)).to.eql('blake2b-8')
8585
})
8686

8787
it('returns p2p when 0x01a5 is used', () => {
8888
// `ipfs` and `p2p` are assigned to `0x01a5`, `ipfs` is deprecated
89-
expect(multicodec.print[0x01a5]).to.eql('p2p')
89+
expect(multicodec.getName(0x01a5)).to.eql('p2p')
9090
})
9191

9292
it('throws error on unknown codec name when getting the code', () => {

0 commit comments

Comments
 (0)