npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@adraffy/cid

v0.0.6

Published

Multiformat CID

Downloads

80

Readme

cid.js

0-dependancy Multiformat CID with related bases and coders.

Demo

import {CID} from '@adraffy/cid'; // or require()
// npm i @adraffy/cid
// browser: https://cdn.jsdelivr.net/npm/@adraffy/cid@latest/dist/index.min.js

let cid = CID.from('QmQ7D7QqcAhFdrFfquiz7B5RWZiJ6e9Ast1LzpXZEdZWF5');
// CID {
//   version: number,
//   codec: number,
//   hash: Multihash { ... },
//   base?: Multibase { ... }
// }
cid.version; // 0
cid.codec;   // 0x70 (since version = 0)
cid.base;    // remembers source base if possible
cid.hash;
// Multihash {
//   codec: number,
//   data: Uint8Array() [ ... ]
// }
cid.bytes; // encoded bytes => Uint8Array(34) [ ... ]
cid.toString();
// "QmQ7D7QqcAhFdrFfquiz7B5RWZiJ6e9Ast1LzpXZEdZWF5"

let cid1 = cid.upgrade(); // copy with version >= 1
cid1.toString(); // default base is "k" => base36
// "k2jmtxs0omsxbtzexbx41py6k7akdtllisuuumrorlmyo2tixbx59rj8"
cid1.toString('z'); // use different base, by prefix (base58btc)
// "zdj7WXCTUquTeArWZZbaegbyYuz8mujpBZJkCQsfcvE458QR1" 
cid1.toString(Multibase.for('b')); // provide Multibase, by prefix (base32)
// "bafybeia2ixqr5fda7cw5vem65xtirm6puhde3vrehkv4zqxxicwc6gbmuq" 
cid2.toString(Multibase.for('base32upper')); // by name
// "BAFYBEIA2IXQR5FDA7CW5VEM65XTIRM6PUHDE3VREHKV4ZQXXICWC6GBMUQ" 

Available bases:

import {Multibase} from '@adraffy/cid';

// auto-registers during Multibase() constructor
[...Multibase].map(x => `${x.prefix}:${name}`); // Iterable<Multibase>
// [
//   0:base2,             7:base8,             9:base10,           
//   f:base16,            F:base16upper,       v:base32hex,        
//   V:base32hexupper,    t:base32hexpad,      T:base32hexpadupper,
//   b:base32,            B:base32upper,       c:base32pad,        
//   C:base32padupper,    h:base32z,           k:base36,           
//   K:base36upper,       z:base58btc,         Z:base58flickr,     
//   m:base64,            M:base64pad,         u:base64url,        
//   U:base64urlpad,     
// ]

Available coders:

import {
  Base2, Base8, Base16, Base32, Base32Hex, Base32Z, Base64, Base64URL, // RFC4648
  Base10, Base36, Base58BTC, Base58Flickr, // Prefix0
  Bech32,
} from '@adraffy/cid';

Base2.encode([128+1]);    // "10000001"
Base2.decode('10000001'); // 129

Base58BTC.encode([1, 2, 255]); // "LiA"
Base58BTC.decode('LiA');       // [1, 2, 255]

let bech = Bech32.decode('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');
bech.hrp;  // string, human-readable part, eg. "bc"
bech.type; // number: 1, Bech32.M, etc. (note: this is the checksum)
bech.v32;  // array of base32 numbers

Arbitrary-precision uvarint:

import {uvarint} from '@adraffy/cid'; // also: dist/uvarint.min.js

let v = []; // output buffer (Array or Uint8Array)
let p = 0;  // write position
p = uvarint.write(v, 69, p);       // Number
p = uvarint.write(v, '0x420', p);  // HexString
p = uvarint.write(v, 1337n, p);    // BigInt
let u;
[u, p] = uvarint.readHex(v, 0);    // "0x45" => 69
[u, p] = uvarint.readBigInt(v, p); //  1056n => 0x420
[u, p] = uvarint.read(v, p);       //  1337
let [u0, u1, u2] = uvarint.read(v, 0, 3); // at position 0, read 3x
// [69, 1056, 1337]

Build

  • git clone this repo, then npm install
  • npm run test
  • npm run build — create /dist/