@vocdoni/common
@vocdoni/common contains shared helpers, models and type definitions for the dvote-js library
Installation
Use npm to install @vocdoni/common.
npm install @vocdoni/common
Usage
Encoding
import { hexStringToBuffer, uintArrayToHex, bigIntToBuffer, bufferToBigInt } from "@vocdoni/common"
hexStringToBuffer("AABBCC12")
const buffer = new Uint8Array([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 250, 255])
uintArrayToHex(buffer)
uintArrayToHex(buffer, true)
const bigint = BigInt("123")
bigIntToBuffer(bigint)
bufferToBigInt(Buffer.from("64", "hex"))
Random
import { Random } from "@vocdoni/common"
const bytes = Random.getBytes(8)
const hex = Random.getHex()
const bigint = Random.getBigInt(256n)
const shuffle = Random.shuffle([1, 2, 3, 4])
Testing
To execute library tests just run
npm run test