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

@fictivekin/growable-uint8-array

v1.2.0

Published

A wrapper around Uint8Array that simplifies buffer management when appending data (growing the array)

Downloads

4

Readme

growable-uint8-array

GrowableUint8Array is simple wrapper around Uint8Array that manages resizing the buffer when appending new data.

Adds a new method extend which can be used to append data to an array. GrowableUint8Array will manage the underlying buffer, automatically allocating a larger Uint8Array when necessary using a simple exponential growth algorithm.

getElement(n) and setElement(n, value) can be used to get and set the value, respectively, at a specific index. When setting, index values less than zero or greater than the length of the array are silently ignored.

All TypedArray prototype methods are delegated to the underlying Uint8Array. If the prototype method returns an instance of Uint8Array it will be wrapped in a GrowableUint8Array.

Use growableUint8Array.unwrap() to return a Uint8Array view of the underlying data, with proper bounds. By default this will not copy the data, for performance reasons. Pass true as the first argument to unwrap to return a copy of the data.

Usage

import GrowableUint8Array from '@fictivekin/growable-uint8-array';

const arr = new GrowableUint8Array(new Uint8Array([1, 2, 3]));
console.log(arr.length); // 3
arr.extend([4, 5, 6]);   // GrowableUint8Array [ 1, 2, 3, 4, 5, 6 ]
console.log(arr.length); // 6
arr.map((x) => x * 2);   // GrowableUint8Array [ 2, 4, 6, 8, 10, 12 ]
console.log(arr);        // GrowableUint8Array [ 1, 2, 3, 4, 5, 6 ]
arr.unwrap()             // Uint8Array [ 1, 2, 3, 4, 5, 6 ]

Array-like access

If your environment supports ES6 proxies, you can use arr.accessProxy() to get a proxy object which allows for Array-like attribute access.

import GrowableUint8Array from '@fictivekin/growable-uint8-array';

const proxy = new GrowableUint8Array(new Uint8Array([1, 2, 42])).accessProxy();
proxy[2];          // 42
proxy[0] = 7;      // 7
proxy.extend([3, 2, 1]);

proxy.unwrap()    // Uint8Array [ 7, 2, 42, 3, 2, 1 ]

Install

npm install @fictivekin/growable-uint8-array

Contribute

Clone repo, then install dev dependencies: npm install --only=dev

Run tests

npm run test

Build

npm run build