Intro
Installable via npm install --save cids, it can also be used directly in the browser.
Download
The source is available for download from GitHub. Alternatively, you can install using npm:
$ npm install --save cids
You can then require() cids as normal:
const cids = require('cids')
In the Browser
Cids should work in any ES2015 environment out of the box.
Usage:
<script type="text/javascript" src="index.js"></script>
The portable versions of cids, including index.js and index.min.js, are included in the /dist folder. Cids can also be found on unkpkg.com under
CID
Class representing a CID <mbase><version><mcodec><mhash>
, as defined in ipld/cid.
static
instance
constructor
constructor(version: (string | Buffer), codec: [string], multihash: [Buffer])Create a new CID.
The algorithm for argument input is roughly:
if (str)
if (1st char is on multibase table) -> CID String
else -> bs58 encoded multihash
else if (Buffer)
if (0 or 1) -> CID
else -> multihash
else if (Number)
-> construct CID by parts
..if only JS had traits..
Example
new CID(<version>, <codec>, <multihash>)
new CID(<cidStr>)
new CID(<cid.buffer>)
new CID(<multihash>)
new CID(<bs58 encoded multihash>)CID.prototype.codec
codec: stringCID.prototype.version
version: numberCID.prototype.multihash
multihash: Buffer