multiformats / js-cid

CID implementation in JavaScript
MIT License
97 stars 39 forks source link

toString / toBaseEncodedString #54

Closed alanshaw closed 5 years ago

alanshaw commented 6 years ago

I'd like to propose adding a toString method to CID instances that calls or replaces toBaseEncodedString. It would make stringifying CIDs so much easier. I'd like to be able to:

$ node
> const CID = require('cids')
> const cid = new CID('z8mWaJHXieAVxxLagBpdaNWFEBKVWmMiE')
> console.log(`my cid: ${cid}`)
my cid: [object Object]
> 

...but get back my cid: z8mWaJHXieAVxxLagBpdaNWFEBKVWmMiE

It's basically a 3 line addition:

toString (base) {
  return this.toBaseEncodedString(base)
}