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

@xobj/buffer

v1.0.8

Published

Buffer for Browser and NodeJS. Writing and reading basic types to binary data.

Downloads

27

Readme

@xobj/buffer

Build npm Downloads Coverage

Buffer for Browser and NodeJS. Writing and reading basic types to binary data.

Install

yarn add @xobj/buffer

Usage

// import reader and writer
import { BufferWriter, BufferReader } from '@xobj/buffer';

// create buffer writer
const writer = new BufferWriter();

// write values
writer.writeInt8(123);
writer.writeString('Test string');

// get result buffer for writing to file or sending to server
const buffer: ArrayBuffer = writer.buffer;

// create buffer reader
const reader = new BufferReader(buffer);

// read values
console.log(reader.readInt8());// 123
console.log(reader.readString()); // Test string

You can see more examples in tests.

Types

  • Number
    • uint8
    • uint16
    • uint32
    • uintVar
    • int8
    • int16
    • int32
    • intVar
    • float32
    • float64
  • BigInt
  • String
  • ArrayBuffer
  • Boolean
    • flags
    • bitset

uintVar / intVar

Variable length integer (1-5 bytes) with max value 2^53-1 (Number.MAX_SAFE_INTEGER). Big bit indicates about next byte. For signed integer first bit used for sign.

Examples:

const writer = new BufferWriter();
writer.writeUintVar(123456);
console.log(writer.buffer);
// ArrayBuffer { [Uint8Contents]: <c0 c4 07>, byteLength: 3 }

Other cases:

uint [01111011] = 123

int [11110111 00000001] = -123

uint [11000000 11000100 00000111] = 123456

int [10000001 10001001 00001111] = -123456

uint [10101100 11100001 10011011 00000011] = 6746284

uint [10111101 10010011 10011100 10101111 00000001] = 367462845

uint [11001011 11111001 11010111 11100100 11000000 11111110 11110000 00000110] = 3874627647831243

BigInt

BigInt consist of count and bytes array.

| count | values | |-----------|-----------| | uintVar | uint8[] |

const writer = new BufferWriter();
writer.writeBigInt(9007199326476237462784254740991n);
console.log(writer.buffer);
// ArrayBuffer { [Uint8Contents]: <1a ff 09 91 63 c8 ce 83 c6 00 a8 d4 af 71>, byteLength: 14 }

String

String consist of chars length and chars codes array.

| length | chars codes | |-----------|-------------| | uintVar | uintVar[] |

const writer = new BufferWriter();
writer.writeString('simple string, простая строка, 単純な文字列');
console.log(writer.buffer);
// ArrayBuffer {
//   [Uint8Contents]: 
//     <25 73 69 6d 70 6c 65 20 73 74 72 69 6e 67 2c 20 bf 08 c0 08 
//      be 08 c1 08 c2 08 b0 08 cf 08 20 c1 08 c2 08 c0 08 be 08 ba 
//      08 b0 08 2c 20 d8 a6 01 94 fa 01 ea 60 87 cb 01 d7 b6 01 97 
//      a4 01>,
//   byteLength: 62
// }

ArrayBuffer

ArrayBuffer consist of buffer size and data.

| size | data | |-----------|-----------| | uintVar | uint8[] |

Boolean

Flags is a boolean array. It is represented as bits writed as single uintVar value. Maximum array length is 53 (maximum uintVar value).

| flags | |-----------| | uintVar |

Examples:

const writer = new BufferWriter();
writer.writeFlags([true, true, true, false, true, false, false, false, true, true]);
console.log(writer.buffer);
// ArrayBuffer { [Uint8Contents]: <97 06>, byteLength: 2 } 

Bitset is a boolean array too. But represented as bits in flow of bytes.

| bitset | |-----------| | uint8[] |

Examples:

const writer = new BufferWriter();
writer.writeBitset([
	true, true, true, false, true, false, true, true,
	false, true, true, false, true, false, true, false,
]);
console.log(writer.buffer);
// ArrayBuffer { [Uint8Contents]: <d7 56>, byteLength: 2 }

Development

Install all dependencies

yarn

Build project

yarn build

Test project

yarn test

Generate coverage report

yarn coverage

Check code quality

yarn lint