Package Exports
- cids
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cids) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
js-cid
CID implementation in JavaScript.
Table of Contents
Install
In Node.js through npm
$ npm install --save cids
Browser: Browserify, Webpack, other bundlers
The code published to npm that gets loaded on require is in fact an ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
const CID = require('cids')
In the Browser through <script>
tag
Loading this module through a script tag will make the multihash
obj available in the global namespace.
<script src="https://unpkg.com/cids/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/cids/dist/index.js"></script>
Gotchas
You will need to use Node.js Buffer
API compatible, if you are running inside the browser, you can access it by multihash.Buffer
or you can install Feross's Buffer.
Usage
const CID = require('cids')
// V1 CID
const cid = new CID(1, 'dag-pb', multihash)
// V0 CID
const cid = new CID(base58Multihash)
API
Constructor
new CID(<version>, <codec>, <multihash>)
new CID(<cidStr>)
new CID(<cid.buffer>)
new CID(<multihash>)
new CID(<bs58 encoded multihash>)
.codec
.version
.hash
.buffer
.toV0()
.toV1()
.toBaseEncodedString(base)
Defaults to 'base58btc'
.toJSON()
.prefix()
returns a buffer with CID version + multicodec + hashAlg + hashLen
CID.isCID(other)
CID.codecs
Contribute
Contributions welcome. Please check out the issues.
Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.
Small note: If editing the Readme, please conform to the standard-readme specification.
License
MIT