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

@grainlogic/stack

v1.2.0

Published

Implementation of stack data structure

Downloads

47

Readme

Stack Build Status Coverage License JavaScript Style Guide Type Definitions Npm Version

An array based stack implementation. Allocation of memory for the stack is lazy during the first call to modifying methods. If necessary, you can replace the internal implementation with a more suitable one for your tasks.

Support for...of and Array.from()

API

Class Stack<T>

Type parameters:

  • T - stack element type

Constructor(deep: number): Stack<T>

Creates a stack instance at the specified depth. The default implementation creates an array of length deep.

Exceptions:

  • ArgumentNullError - an exception thrown if you do not pass the deep parameter;
  • StackDepthNegativeError - an exception thrown if value of the deep parameter is less than zero.

Note. If you pass deep +Infinity as the parameter value, then an array will be created with no explicit length limit.

Methods

push (item: T): void

Add item to the top of the stack.

Exceptions:

  • StackOverflowError - an exception thrown when trying to add an item to the full stack.

pop (): T

Remove item from the top of the stack and return it.

Exceptions:

  • StackUnderflowError - an exception thrown when an attempt to pop an element from empty stack.

clear (): void

Clear all elements from the stack.

Exceptions:

  • StackUnderflowError - an exception thrown when trying to clear an empty stack.

Properties

readonly size: number

Current number of items on the stack.

readonly isFull: boolean

Stack full indicator.

readonly isEmpty: boolean

Stack empty indicator.

view: StackView<T>

Internal stack representation.

This property is initialized lazily the first time it is accessed. After initialization, you cannot change the property value. Implements the Method Injection pattern with the default Array dependency.

If necessary, you can replace the default implementation with your own, for example a linked list or a typed array.

Exceptions:

  • ArgumentNullError - an exception thrown when trying to set the property to null or undefined;
  • PropertyAlreadyDefineError - an exception thrown when trying to reinitialize a property.