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

@ch1nm4y-8/simple-stack-js

v1.0.0

Published

A lightweight Stack for JavaScript and TypeScript

Readme

@ch1nm4y-8/simple-stack-js

A lightweight LIFO stack for JavaScript and TypeScript.

Features

  • Zero runtime dependencies
  • LIFO (Last In, First Out)
  • Method chaining support
  • Full TypeScript support with type declarations
  • Supports ESM (import)
  • Supports CommonJS (require)
  • Iterable (for...of, Array.from, spread operator)
  • Clone support
  • Array conversion support

Install

npm install @ch1nm4y-8/simple-stack-js

TypeScript

import { Stack } from "@ch1nm4y-8/simple-stack-js";

const stack = new Stack<number>();

stack.push(1);
stack.push(2);
stack.push(3);

console.log(stack.pop()); // 3
console.log(stack.peek()); // 2
console.log(stack.size()); // 2

Constructor

const stack1 = new Stack([1, 2, 3]);
const stack2 = new Stack(new Set([1, 2, 3]));

console.log(stack1.peek()); // 3
console.log(stack2.peek()); // 3

Iteration

const stack = new Stack([1, 2, 3]);

for (const item of stack) {
  console.log(item);
}

Iteration follows insertion order (bottom → top).

Output:

1
2
3

Type Safety

const stack = new Stack<number>();

stack.push(1);

// Type Error
stack.push("hello");

ECMAScript Modules (ESM)

import { Stack } from "@ch1nm4y-8/simple-stack-js";

const stack = new Stack();

stack.push("A");
stack.push("B");

console.log(stack.pop()); // B

CommonJS

const { Stack } = require("@ch1nm4y-8/simple-stack-js");

const stack = new Stack();

stack.push("A");
stack.push("B");

console.log(stack.pop()); // B

API

| Method | Time Complexity | Description | | ------------- | --------------- | ---------------------------------------- | | push(value) | O(1) | Adds an item to the top of the stack | | pop() | O(1) | Removes and returns the top item | | peek() | O(1) | Returns the top item without removing it | | clear() | O(1) | Removes all items | | size() | O(1) | Returns the number of items | | isEmpty() | O(1) | Returns whether the stack is empty | | toArray() | O(n) | Converts the stack to an array | | clone() | O(n) | Returns a shallow copy of the stack |


push(value)

Adds an item to the top of the stack.

stack.push(1);

Method chaining is supported:

stack.push(1).push(2).push(3);

Returns:

this;

pop()

Removes and returns the top item.

const value = stack.pop();

Returns:

T | undefined;

peek()

Returns the top item without removing it.

const value = stack.peek();

Returns:

T | undefined;

clear()

Removes all items from the stack.

stack.clear();

Returns:

void

size()

Returns the number of items in the stack.

console.log(stack.size());

Returns:

number;

isEmpty()

Returns whether the stack is empty.

console.log(stack.isEmpty());

Returns:

boolean;

toArray()

Returns the stack contents in insertion order (bottom → top).

const stack = new Stack([1, 2, 3]);

console.log(stack.toArray());

Output:

[1, 2, 3];

clone()

const s1 = new Stack([1, 2, 3]);
const s2 = s1.clone();

s1.pop();

console.log(s1.toArray()); // [1, 2]
console.log(s2.toArray()); // [1, 2, 3]

Example

import { Stack } from "@ch1nm4y-8/simple-stack-js";

const history = new Stack<string>();

history.push("Home");
history.push("Profile");
history.push("Settings");

console.log(history.pop()); // Settings
console.log(history.pop()); // Profile

Output:

Settings
Profile

License

MIT