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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sized-stack

v1.0.1

Published

A stack data structure with a fixed optional maximum size

Readme

Sized Stack

A stack data structure with a fixed optional maximum size. It allows you to specify a maximum size for the stack. If the maximum size is reached, adding a new element to the stack will remove the oldest element from the stack. This can be useful in situations where you want to limit the memory usage of the stack.

Installation

npm install sized-stack

Use cases

In addition to supporting all use cases of the normal stack data structure, the sized-stack library can be used in the following situations:

  1. Caching in web applications: In web applications, caching can be used to improve performance by storing frequently accessed data in memory. However, it may be necessary to limit the size of the cache to avoid using too much memory. The sized-stack library can be used to implement a cache with a fixed maximum size, ensuring that the memory usage is bounded.

  2. Undo/redo functionality in text editors: Text editors often provide undo/redo functionality that allows the user to undo or redo previous actions. The sized-stack library can be used to implement a stack that stores the previous actions, with a fixed maximum size to limit the memory usage.

  3. Displaying the most recent items in a list: In some applications, it may be useful to display the most recent items in a list. Especially if the list describes a sequence of events, it may be desirable to only display the most recent events. The sized-stack library can be used to implement a stack that stores the most recent items, with a fixed maximum size to limit the memory usage.

and more...

Usage

import SizedStack from "sized-stack";

// Create a new stack with maximum size 3
const stack = new SizedStack<string>(3);

// Add some elements to the stack
stack.push("a");
stack.push("b");
stack.push("c");

// Check if the stack is full
console.log(stack.isFull()); // true

// Add another element to the stack
stack.push("d");

// Check the top element of the stack
console.log(stack.top()); // 'd'

// Remove the top element from the stack
stack.pop();

// Get the number of elements in the stack
console.log(stack.size); // 2

// Insert an element into the stack if it is not full
stack.pushIfAvailable("e");

// Try to insert another element into the stack, but fail because it is full
stack.pushIfAvailable("f");

// Get an array containing all the elements in the stack
console.log(stack.toList()); // ['b', 'c', 'e']

API

new SizedStack<T>(size?: number)

Creates a new sized-stack instance.

  • size (optional): The maximum number of elements the stack can hold. If not provided, the stack has infinite capacity.

push(...items: T[]): void

Adds one or more elements to the top of the stack.

  • items: The elements to add to the stack.

pushIfAvailable(...items: T[]): void

Adds one or more elements to the top of the stack, if the stack is not full.

  • items: The elements to add to the stack.

pop(): void

Removes the top element from the stack.

top(): T | undefined

Returns the top element of the stack without removing it.

isFull(): boolean

Returns whether the stack is full.

isEmpty(): boolean

Returns whether the stack is empty.

size: number

Returns the number of elements in the stack.

toList(): T[]

Returns an array containing all the elements in the stack, in the order they were added.

License

This library is licensed under the MIT License.