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

buff-commonjs

v1.1.12

Published

Cross-platform utility library for working with byte-arrays and moving between formats.

Downloads

2

Readme

Bytes Utils

Cross-platform utility library for working with byte-arrays and moving between formats.

Installation

<script src="https://unpkg.com/@cmdcode/bytes-utils">
yarn add @cmdcode/bytes-utils | npm install @cmdcode/bytes-utils

How to Use

/* Buff class extends Uint8Array object
 * and provides simple format conversion. 
 */
import { Buff } from '@cmdcode/bytes-utils'

Buff
  .str(strData)    => Buff<Uint8Array>
  .hex(hexData)    => Buff<Uint8Array>
  .num(numData)    => Buff<Uint8Array>
  .big(bigData)    => Buff<Uint8Array>
  .buff(buffer)    => Buff<Uint8Array>
  .json(jsonData)  => Buff<Uint8Array>
  .bech32(strData) => Buff<Uint8Array>
  .base58(strData) => Buff<Uint8Array>
  .base64(strData) => Buff<Uint8Array>

new Buff(data: ArrayBufferLike, size: number)
  .toStr()    => string
  .toHex()    => hexstring
  .toNum()    => number
  .toBig()    => bigint
  .toBytes()  => Uint8Array
  .toJson()   => object
  .toBech32() => b32string
  .toBase58() => b58string
  .toBase64() => b64string
/* Bytes class extends the Buff object
 * even further, adds byte manipualtion. 
 */
import { Bytes } from '@cmdcode/bytes-utils'

Bytes
  .varint(num: number)     => bytes // Returns a byte array of the varint.
  .join(arr: Uint8Array[]) => bytes // Returns a concatenated byte array.    

new Bytes(data: ArrayBufferLike, size: number)
  .prepend(bytes: Uint8Array) => bytes // Returns prepended byte array.
  .append(bytes: Uint8Array)  => bytes // Returns appended byte array.
  .varint(num: number)        => bytes // Returns appended byte array.
/* Stream class reads from a Uint8Array,
 * and consumes the data on each read.
 */
import { Stream } from '@cmdcode/bytes-utils'

new Stream(data: ArrayBufferLike)
  .peek(len: number) => bytes // Reads the array, does not consume.
  .read(len: number) => bytes // Reads the array, shrinks the array.
  .varint() => number // Reads the next byte as varint, returns number.
/* Type class is an extention of 'typeof',
 * tries to determine a 'type' to any data.
 */
import { Type } from '@cmdcode/bytes-utils'

Type.of(data: any) => string [
  'undefined'
  'infinity'
  'null'
  'hex'
  'string'
  'bigint'
  'number'
  'array'
  'uint8'
  'uint16'
  'uint32'
  'buffer'
  'object'
  'unknown'
]

Issues

Please feel free to post any questions or bug reports on the issues page!

This library is currently in heavy development. Watch out for dragons!

Testing

This project uses tape for writing unit tests. I have a script that scans the API of each library and tries to import tests dynamically. The benefit of this is I can run the same tests on any bundle of the source code, so all bundle targets are tested (except cjs, gotta figure out one out).

There's also a test/index.html that will launch testing for the browser bundle, and test within the browser. Pretty neat!

Development

This project uses the following development tools:

  • ESLint : For linting and catching linter errors.
  • Prettier : For enforcing standard code formatting.
  • Nyc : For test code coverage and reports.
  • Rollup : Bundling/optimizing code for different platforms.
  • Tape : A simple, easy to use testing library.
  • Typescript : Type-checking and generating declaration files.

It should be straight-forward to setup a development environment:

yarn install | npm install

Contributions

All contributions are welcome!