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/history

v1.0.3

Published

A simple data structure to manage history through circular stack.

Readme

A simple data structure to manage history through circular stack.

Install

  • npm

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

    pnpm add @algorithm.ts/history

Usage

History

History is a fixed size stack structure, the main purpose of its design is to reuse space as much as possible on the basis of ordinary historys. Historys usually need to specify a capacity, if the number of elements in the history exceeds the capacity, only the most recent capacity elements are preserved in the history. Other operations are the same as ordinary historys.

  • IHistory: History implements the IHistory interface.

    | Signature | Description | | :------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------- | | readonly capacity: number | The capacity of the history, which also means the maximum elements of the history. | | readonly size: number | The count of the elements in the history. | | readonly name: string | The name of the history. | | readonly equals: IEquals | Used to check if two element in the history are same. | | backward(step?: number): [element: T \| undefined, isBot: boolean] | Backward step steps and return the present element of the history. | | clear(): void | Clear the history. | | count(filter: (element: T, index: number) => boolean): number | Count the elements in the history which matched the filter. | | fork(name: string): IHistory<T> | Create a new history from the current one. | | forward(step?: number): [element: T \| undefined, isTop: boolean] | Forward step steps and return the present from the history. | | go(index?: number): T \| undefined | Set the present index to the given index and return the elements at the index of the history. | | isBot(): boolean | Check if the present index is at the bottom of the history. | | isTop(): boolean | Check if the present index is at the top of the history. | | present(): [element: T \| undefined, index: number] | Return the present element and present index of the history. | | push(element: T): this | Push the element to the history. | | rearrange(filter: (element: T, index: number) => boolean): void | Rearrange the history and only keep the elements matched the given filter. | | updateTop(element: T): void | Change the top element of the history. |

  • IHistoryProps

    export interface IHistoryProps<T> {
      /**
      * The history name.
      */
      readonly name: string
      /**
      * Initial capacity of the circular history.
      */
      readonly capacity: number
      /**
      * Used to check if two element in the history are same.
      */
      readonly equals?: IEquals<T>
    }

Example

  • Basic -- CircularHistory

    import { History } from '@algorithm.ts/history'
    
    const history = new History<{ name: string }>({ name: 'profile', capacity: 100 })
    
    // Append a element to the end of the history.
    history.push({ name: 'alice' }) // => 0
    history.push({ name: 'bob' }) // => 1
    history.size          // => 2
    
    // Get the front element of the history.
    history.present()     // => [{ name: 'bob' }, 1]
    history.backward()    // => [{ name: 'alice' }, 0]
    history.backward()    // => [{ name: 'alice' }, 0]
    history.forward()     // => [{ name: 'bob' }, 1]
    history.forward()     // => [{ name: 'bob' }, 1]

Related