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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@algorithm.ts/stack

v1.0.3

Published

Typescript implementation of stacks. (circular stack and etc)

Readme

A typescript implementation of Circular Stack.

Install

  • npm

    npm install --save @algorithm.ts/stack
  • pnpm

    pnpm add @algorithm.ts/stack

Usage

CircularStack

Circular stack is a stack structure, the main purpose of its design is to reuse space as much as possible on the basis of ordinary stacks. Circular stacks usually need to specify a capacity, if the number of elements in the stack exceeds the capacity, only the most recent capacity elements are kept in the stack. Other operations are the same as ordinary stacks.

  • ICircularStack: CircularStack implements the ICircularStack interface.

    | Signature | Description | | :---------------------------------------------------------------- | :------------------------------------------------------------------------------- | | readonly capacity: number | The capacity of stack, which also means the max elements of the stack. | | readonly size: number | The count of the elements in the stack. | | at(index: number): T \| undefined | Get the element at the given index. | | clear(): void | Clear the stack. | | consuming(): IterableIterator<T> | Popup the elements from the stack one by one. | | count(filter: (element: T, index: number) => boolean): number | Count the elements in the stack which matched by the filter. | | pop(newElement?: T): T \| undefined | Popup the top element, and push the given newElement if it is not undefined. | | push(element: T): this | Push a element into the stack. | | rearrange(filter: (element: T, index: number) => boolean): void | Only preserve the elements matched the filter. | | resize(capacity: number): void | Resize the capacity of stack with the given size. | | top(): T\|undefined | Get the top element from the stack. | | update(index: number, element: T): void | Change the element at the given index. |

  • ICircularStackProps

    export interface ICircularStackProps {
      /**
      * Initial capacity of the circular stack.
      */
      capacity?: number
    }

Example

  • Basic -- CircularStack

    import { CircularStack } from '@algorithm.ts/stack'
    
    const stack = new CircularStack<{ name: string }>({ capacity: 100 })
    
    // Append a element to the end of the stack.
    stack.push({ name: 'alice' }) // => 0
    stack.push({ name: 'bob' }) // => 1
    stack.size          // => 2
    
    // Get the front element of the stack.
    stack.top()         // => { name: 'bob' }
    
    // Take off the first element of the stack.
    stack.pop()         // => { name: 'bob' }
    stack.size          // => 1

Related