Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Commit 14ab8e4

Browse files
Alan Shawvmx
Alan Shaw
authored andcommitted
fix: toV0 and toV1 create instances that cause isCID be false
The `toV0` and `toV1` functions were returning instances of the unwrapped CID class not the wrapped one with the class-is smarts. License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent ebc21a2 commit 14ab8e4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const withIs = require('class-is')
2121
* , as defined in [ipld/cid](https://github.com/ipld/cid).
2222
* @class CID
2323
*/
24-
class CID {
24+
const CID = withIs(class {
2525
/**
2626
* Create a new CID.
2727
*
@@ -229,11 +229,11 @@ class CID {
229229
throw new Error(errorMsg)
230230
}
231231
}
232-
}
233-
234-
CID.codecs = codecs
235-
236-
module.exports = withIs(CID, {
232+
}, {
237233
className: 'CID',
238234
symbolName: '@ipld/js-cid/CID'
239235
})
236+
237+
CID.codecs = codecs
238+
239+
module.exports = CID

test/index.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ describe('CID', () => {
198198
expect(
199199
CID.isCID(Buffer.from('hello world'))
200200
).to.equal(false)
201+
202+
expect(
203+
CID.isCID(new CID(h1).toV0())
204+
).to.equal(true)
205+
206+
expect(
207+
CID.isCID(new CID(h1).toV1())
208+
).to.equal(true)
201209
})
202210

203211
it('.toString() outputs default base encoded CID', () => {

0 commit comments

Comments
 (0)