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

stack-adt

v0.2.3

Published

Stack ADT for browser and nodejs

Downloads

135

Readme

stack-adt Build Status

Stack ADT for browser and nodejs

The Stack class represents a last-in-first-out (LIFO) stack of generic items. It supports the usual push and pop operations, along with methods for peeking at the top item, testing if the stack is empty, and iterating through the items in LIFO order.

All stack operations except iteration and empty are constant time.

Install

Download the production version or the development version.

$ npm install --save stack-adt
$ bower install --save stack-adt

Usage

var Stack = require('stack-adt');
var stack = new Stack();

stack.push(10);
stack.peek();
stack.isEmpty();
stack.push("foo");
stack.push({hello: "world"});
stack.peek().hello; // Outputs "world"
stack.push(function(){ console.log("hello") });
stack.peek()(); // Outputs "world"
stack.size();
stack.pop();
stack.size();

var itr = stack.iterator

while(itr.hasNext()) {
  console.log(itr.next());
}

stack.empty();
<script type="text/javascript" src="https://raw.githubusercontent.com/pasangsherpa/stack-adt/master/dist/stack-adt.min.js"></script>
<script type="text/javascript"> 
  var stack = new Stack();

  stack.push(10);
  stack.peek();
  stack.isEmpty();
  stack.push("foo");
  stack.push({hello: "world"});
  stack.peek().hello; // Outputs "world"
  stack.push(function(){ console.log("hello") });
  stack.peek()(); // Outputs "world"
  stack.size();
  stack.pop();
  stack.size();

  var itr = stack.iterator

  while(itr.hasNext()) {
    console.log(itr.next());
  }

  stack.empty();
</script>

Documentation

Stack()

Creates an empty stack with infinite capacity.

Stack(initialCapacity)

Creates an empty stack using the specified capacity.

initialCapacity

Type: int

initialCapacity represents the specified capacity.

Methods

.push(element) throws "Stack is full" error

Adds one element to the top of the stack and returns the new size of the stack.

element

Type: object

the element to be pushed onto stack.

.pop() throws "Stack is empty" error

Removes and returns the top element from the stack.

Type: object

the element removed from the top of the stack.

.peek() throws "Stack is empty" error

Returns without removing the top element of the stack.

Type: object

the element on top of the stack.

.isEmpty()

Returns true if this stack contains no elements.

Type: boolean

whether or not the stack is empty.

.size()

Returns the number of elements in the stack.

Type: int

the number of element in the stack.

.empty()

Removes all element from the the queue and returns the new size of the queue.

.iterator

Returns an iterator to the stack that iterates through the items in LIFO order.

Type: object

the iterator object of the stack

.iterator.next() throws "No such element" error

Returns the next item in LIFO order.

.iterator.hasNext()

Returns whether the stack has next item in LIFO order.

License

MIT © Pasang Sherpa