1.2.0 • Published 10 months ago

lnset v1.2.0

Weekly downloads
-
License
Apache-2.0 OR MIT
Repository
github
Last release
10 months ago

lnset

Build JavaScript Style Guide

Typed Set of IPLD links (CIDs).

Install

npm i lnset

Usage

import { Set } from 'lnset'
import { sha256 } from 'multiformats/hashes/sha2'
import * as raw from 'multiformats/codecs/raw'
import { CID } from 'multiformats/cid'

const key0 = CID.create(1, raw.code, sha256.digest(new Uint8Array()))
const key1 = CID.create(1, raw.code, sha256.digest(new Uint8Array()))

const set = new Set()
set.add(key0)

console.log(set.has(key1)) // true

// Create a CID for this CID set:
console.log(set.link()) // CID(bahkygaysecoonrhfkgujdciwaluh2k42cxjka4rltqrxn6wdvrnnn4s54imj2)

Okay, I know that's how sets work normally. How about this instead:

$ node
Welcome to Node.js v20.0.0.
Type ".help" for more information.
> const sha2 = await import('multiformats/hashes/sha2')
undefined
> const raw = await import('multiformats/codecs/raw')
undefined
> const { CID } = await import('multiformats/cid')
undefined
> const key1 = CID.create(1, raw.code, sha2.sha256.digest(new Uint8Array()))
undefined
> const key2 = CID.create(1, raw.code, sha2.sha256.digest(new Uint8Array()))
undefined
> key1 === key2
false
> const { Set: LinkSet } = await import('./index.js')
undefined
> const set = new LinkSet()
undefined
> set.add(key1)
LinkSet(0) [Set] {}
> set.size
1
> set.has(key2)
true

Contributing

Feel free to join in. All welcome. Please open an issue!

License

Dual-licensed under MIT + Apache 2.0

1.2.0

10 months ago

1.1.0

10 months ago

1.0.1

11 months ago

1.0.0

11 months ago