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

@resolverworks/enson

v0.0.11

Published

ENS Object Notation

Downloads

201

Readme

enson.js

⚠️ This repo is under active development!

npm i @resolverworks/enson

Coin

import {Coin} from '@resolverworks/enson';

// memozied coin formats
Coin.fromName('eth') === Coin.from({name: 'eth'}) === Coin.from('eth')
Coin.fromType(60)    === Coin.from({type: 60})    === Coin.from(60)
Coin.fromChain(1)    === Coin.from({chain: 1})

console.log(Coin.from('btc'));
// Coin { type: 0n, name: 'btc', title: 'Bitcoin' }
console.log(Coin.fromChain(2));
// UnnamedEVMCoin { type: 2147483650n }
console.log(Coin.from(69420));
// UnknownCoin { type: 69420n }

Address

import {Address} from '@resolverworks/enson';

Address.from('0x51050ec063d393217B436747617aD1C2285Aeeee');
Address.from('btc', 'bc1q9ejpfyp7fvjdq5fjx5hhrd6uzevn9gupxd98aq');
Address.from(0, '0x00142e6414903e4b24d05132352f71b75c165932a381');

Chash

import {Chash} from '@resolverworks/enson';

let ipfs = Chash.from('0xe301017012201687de19f1516b9e560ab8655faa678e3a023ebff43494ac06a36581aafc957e');
ipfs.bytes; // Uint8Array
ipfs.spec; // {codec: 0xE3, name: 'IPFS'}
ipfs.toHash(); // "k2jmtxrxbr58aa3716vvr99qallufj3qae595op83p37jod4exujup32"
ipfs.toURL(); // "ipfs://k2jmtxrxbr58aa3716vvr99qallufj3qae595op83p37jod4exujup32"
ipfs.toGatewayURL(); // "https://cloudflare-ipfs.com/ipfs/k2jmtxrxbr58aa3716vvr99qallufj3qae595op83p37jod4exujup32/"
ipfs.toObject() // { protocol: {codec: 227, name: 'IPFS'}, cid: {version: 1, codec: 112, hash: {codec: 18, data: [Uint8Array]}}}

let onion = Chash.fromOnion('2gzyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclen53wid');
onion.toObject(); // {protocol: {codec: 445, name: 'Onion'}, pubkey: [Uint8Array], checksum: [Uint8Array], version: 3}
onion.toURL(); // "http://2gzyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclenq.onion"

let json = Chash.from({nice: 'chonk'}, 'json'); // hint
json.toObject(); // {protocol: {codec: 74565, name: 'DataURL'}, mime: 'application/json', data: [Uint8Array], abbr: 'json', value: {nice: 'chonk'}}
json.toURL(); // "data:application/json;base64,eyJuaWNlIjoiY2hvbmsifQ=="

let file = Chash.from(readFileSync('chonk.mp4'), 'video/mp4');

Record

import {Record} from '@resolverworks/enson';

// construct KV records in human-readable notation
// minimal memory footprint, everything is string/Uint8Array 
let vitalik = Record.from({
    name: 'Vitalik',
    $eth: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
    $btc: 'bc1pcm5cz7zqmc23ml65m628vrln0fja6hnhewmncya3x6n6rq7t7rdqhgqlvc',
    avatar: 'eip155:1/erc1155:0xb32979486938aa9694bfc898f35dbed459f44424/10063',
    '#ipfs': 'k2jmtxrxbr58aa3716vvr99qallufj3qae595op83p37jod4exujup32',
    '#pubkey': {x: 1, y: 2},
    '#name': 'vitalik.eth',
});

// supports all standard resolver functions
let name = vitalik.text('name'); // "Vitalik"
let addr60 = vitalik.addr(60); // Uint8Array(20)
let hash = vitalik.contenthash(); // Uint8Array(38)
let pubkey = vitalik.pubkey(); // UintArray(64)
let name = vitalik.name(); // "vitalik.eth"

vitalik.getAddress(60); // Address()
vitalik.getChash(); // Chash()
vitalik.getPubkey(); // Pubkey()

Profile

import {Record} from '@resolverworks/enson';

let profile0 = Profile.ENS(); // default ENS profile

let profile = Profile.from(vitalik);
// Profile {
//   texts: Set(2) { 'name', 'avatar' },
//   addrs: Set(2) { 60n, 0n },
//   chash: true,
//   pubkey: true,
//   name: true,
//   addr0: false
// }
let calls = profile.makeCalls('nick.eth'); // calldata 
let answers = ...; // do the calls using ethers or whatever 
let nick = new Record();
nick.parseCalls(calls, answers);

Node

import {Node} from '@resolverworks/enson';

// create a registry
let node = Node.root();

// create some subdomains, store a Record in a Node (eg. a Resolver)
node.create('vitalik.eth').record = vitalik;

// import record from JSON at an existing node
// (same as .record = Record.from({...})
node.find('raffy.eth').import({
    name: 'Raffy',
    $eth: '0x51050ec063d393217B436747617aD1C2285Aeeee'
});

// import some subdomains
// "." is the parent node record and indicates that keys are subdomains
root.find('eth').import({
    '.':    { name: 'Ether',  $eth: '0x0000000000000000000000000000000000000000' }, // eth
    slobo:  { name: 'Alex',   $eth: '0x0000000000000000000000000000000000000001' }, // slobo.eth
    darian: { name: 'Darian', $eth: '0x0000000000000000000000000000000000000002' }  // darian.eth
});

root.flat() // list of nodes

// create reverse nodes
let rev = root.create('addr.reverse');
root.scan(node => {
    let eth = node.record?.getAddress(60);
    if (eth) {
        rev.create(eth.toPhex().slice(2)).record = Record.from({
            [Record.NAME]: node.name
        });	
    }
});