multiformats / multiformats/js-multiformats
Create a CID from a string or Uint8Array or CID-like object
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 268
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
This module has a number of ways of converting things into CID instances - CID.parse for strings, CID.decode for Uint8Arrays, CID.asCID for things CID-shaped.
.parse and .decode will throw, .asCID will not. We generally want to validate what we've been passed as a CID, so a common pattern seems to be forming as:
function toCID (hash) {
if (typeof hash === 'string') {
return CID.parse(hash)
} else if (hash instanceof Uint8Array) {
return CID.decode(hash)
}
const cid = CID.asCID(hash)
if (!cid) {
throw new Error('Invalid CID')
}
return cid
}
If this seems familiar it may be because this is quite similar to how the constructor from the js-cids class behaves.
It is quite useful though, any objections to making this a utility method on the CID class?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the CID class and its existing parse, decode, and asCID methods. Check how CID construction and validation are tested, then confirm that the proposed utility accepts strings, Uint8Arrays, and CID-like objects while rejecting invalid values consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100