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

bigint-codec

v0.1.1

Published

BigInt codec for NodeJS and the Web

Downloads

7

Readme

BigInt Codec

BigInt serialization codec using Uint8Arrays for NodeJS and the Web with no dependencies.

Packaged as both ECMAScript Modules and CommonJS thanks to Rollup.

Compatability Testing Status:

  • [x] Bit-compatabile with u8/i8/u16/i16/u32/i32/u64/i64 encodings via DataView for both Little Endian (LE) and network order Big Ending (BE) encodings.
  • [ ] TODO: Test compatibility with ASN-1 Big-Int encodings.
  • [ ] TODO: Identify and test compatibility with other Big-Int encodings.

Example

import {encodeBigInt, decodeBigInt} from 'bigint-codec'
import {encodeBigUint, decodeBigUint} from 'bigint-codec'

const n_curve25519 = 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn

const u8_BE = encodeBigInt(n_curve25519)
console.log(u8_BE)
// Uint8Array(32) [
//    16,   0,   0,   0,   0,   0,  0,  0,   0,
//     0,   0,   0,   0,   0,   0,  0, 20, 222,
//   249, 222, 162, 247, 156, 214, 88, 18,  99,
//    26,  92, 245, 211, 237
// ]

const n_rt = decodeBigInt(u8_BE)

console.log(n_rt === n_curve25519)
// true


const u8_LE = encodeBigInt(n_curve25519, true)
console.log(u8_LE)
// Uint8Array(32) [
//     237, 211, 245,  92,  26,  99, 18, 88, 214,
//     156, 247, 162, 222, 249, 222, 20,  0,   0,
//       0,   0,   0,   0,   0,   0,  0,  0,   0,
//       0,   0,   0,   0,  16
// ]


const n_rt_LE = decodeBigInt(u8_LE, true)
console.log(n_rt_LE === n_curve25519)
// true

Use

CDN
<script src="https://cdn.jsdelivr.net/npm/bigint-codec@VERSION/umd/index.min.js"></script>
<!-- or -->
<script src="https://cdn.jsdelivr.net/npm/bigint-codec/umd/index.min.js"></script>
<script>window.bigint_codec.encodeBigInt(23n)</script>

<!-- or individually -->

<script src="https://cdn.jsdelivr.net/npm/bigint-codec@VERSION/umd/bigint_decode.min.js"></script>
<script>window.bigint_decode.decodeBigInt</script>

<script src="https://cdn.jsdelivr.net/npm/bigint-codec@VERSION/umd/bigint_encode.min.js"></script>
<script>window.bigint_encode.encodeBigInt</script>

<script src="https://cdn.jsdelivr.net/npm/bigint-codec@VERSION/umd/bigint_encode_into.min.js"></script>
<script>window.bigint_encode_into.encodeIntoBigInt</script>
NodeJS import
import {decodeBigInt, decodeBigUint} from 'bigint-codec'
import {encodeBigInt, encodeBigUint} from 'bigint-codec'

// or individually
import {decodeBigInt, decodeBigUint} from 'bigint-codec/esm/bigint_decode.mjs'
import {encodeBigInt, encodeBigUint} from 'bigint-codec/esm/bigint_encode.mjs'
import {encodeIntoBigInt, encodeIntoBigUint} from 'bigint-codec/esm/bigint_encode_into.mjs'
NodeJS require()
const { decodeBigUint, encodeBigUint } = require('bigint-codec')

// or individually
const {decodeBigUint} = require('bigint-codec/cjs/bigint_decode.cjs')
const {encodeBigUint} require('bigint-codec/cjs/bigint_encode.cjs')

API

Encode Signed BigInt
{
  encodeBigInt(value : BigInt, littleEndian: Boolean) : Uint8Array {},
  encodeBigIntLE(value : BigInt) : Uint8Array {},
  encodeBigIntBE(value : BigInt) : Uint8Array {},
  encodeIntoBigIntLE(value : BigInt, u8buf? : Uint8Array) : Uint8Array {},
  encodeIntoBigIntBE(value : BigInt, u8buf? : Uint8Array) : Uint8Array {},
}
Encode Unsigned BigInt
{
  encodeBigUint(value : BigInt, littleEndian: Boolean) : Uint8Array {},
  encodeBigUintBE(value : BigInt) : Uint8Array {},
  encodeBigUintLE(value : BigInt) : Uint8Array {},
  encodeIntoBigUintLE(value : BigInt, u8buf? : Uint8Array) : Uint8Array {},
  encodeIntoBigUintBE(value : BigInt, u8buf? : Uint8Array) : Uint8Array {},
}
Decode Signed BigInt
{
  decodeBigInt(u8buf: ArrayBuffer | Uint8Array, littleEndian: Boolean) : BigInt {},
  decodeBigIntLE(u8buf: ArrayBuffer | Uint8Array) : BigInt {},
  decodeBigIntBE(u8buf: ArrayBuffer | Uint8Array) : BigInt {},
}
Decode Unsigned BigInt
{
  decodeBigUint(u8buf: ArrayBuffer | Uint8Array, littleEndian: Boolean) : BigInt {},
  decodeBigUintBE(u8buf: ArrayBuffer | Uint8Array) : BigInt {},
  decodeBigUintLE(u8buf: ArrayBuffer | Uint8Array) : BigInt {},
}

License

BSD 2-clause