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

@toolbuilder/dynamic-ring-buffer

v0.1.6

Published

A ring buffer that manages memory in chunks to support large capacity for data bursts with low overhead when small.

Downloads

17

Readme

DynamicRingBuffer

DynamicRingBuffer implements classic fixed length ring buffer, or circular queue. Memory is dynamically allocated and deallocated in chunks as the buffer grows and shrinks. This allows the buffer to have a large capacity to handle data bursts, while minimizing memory use during normal operation.

When the buffer length reaches capacity, the oldest values are quietly thrown away. The methods match the Array signature for push, pop, unshift, and shift. For buffer operation either use push/shift together, or unshift/pop together.

DynamicRingBuffer is a minimal implementation developed for use with Await-For-It iterable queues.

There are two related buffers:

  • RingBuffer ring buffer with fixed maximum size - faster than Array as a buffer.
  • PriorityBuffer that uses your comparator to buffer items in priority order.

There are lots of ring buffer implementations on NPM. This implementation:

  • Dynamically allocates and deallocates in chunks to reduce memory use when not needed.
  • Drop in replacement for Array to convert a buffer to a ring buffer.
  • Defines exports and module properties in package.json pointing to the ES source for bundlers.
  • Dual module that provides both ES and CommonJS entry points.
  • Provides Symbol.iterator generator.

Installation

npm install --save @toolbuilder/dynamic-ring-buffer

Getting Started

The API documentation is here. This is a quick example to get you started.

import { DynamicRingBuffer } from '@toolbuilder/dynamic-ring-buffer'
const log = console.log

const ringBuffer = new DynamicRingBuffer(100, 10000) // max length 10000 in chunks of 100
log(ringBuffer.length) // prints 0

['A', 'B', 'C'].forEach(x => ringBuffer.push(x))
log(ringBuffer.length) // prints 3
log(ringBuffer.front()) // prints 'A'
log(ringBuffer.back()) // prints 'C'
log(ringBuffer.shift()) // pulls 'A' off front and prints 'A'
log(ringBuffer.length) // prints 2
log([...ringBuffer]) // prints ['B', 'C']
log(ringBuffer.length) // prints 2

Alternatives

There are lots of alternatives on npm.

Contributing

Contributions are welcome. Please create a pull request.

  • I use pnpm instead of npm.
  • Run the unit tests with pnpm test
  • Package verification requires pnpm to be installed globally.
    • npm install -g pnpm
    • pnpm install
    • pnpm test to run unit tests
    • pnpm run check:packfile to test the pack file against Node ES and CommonJS projects, as well as Electron.
    • pnpm run check to validate the package is ready for commit

Issues

This project uses Github issues.

License

MIT