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

stl-javascript

v3.2.0

Published

I try to create easy way to use stack, queue and some data structure in Javascript

Readme

stl-javascript NPM npm npm

stl-javascript is a concise, well-tested library of core data structures and algorithms for JavaScript — stacks, queues, priority queues, circular queues, segment trees, and binary search trees. It is designed for learning, teaching, and lightweight production use, with clear examples and comprehensive tests.

Common use cases include binary number conversion and postfix expression evaluation.

Installation

Use the package manager npm to install STL-JAVASCRIPT.

npm install stl-javascript

or you can use yarn

yarn add stl-javascript

Usage

Stack

A stack is a conceptual structure that combines a set of similarities and is based on the principle of end-to-end (LIFO). It is a type of invisible, commonly used data with two main functions, push and pop. Push and pop are made on the very top, which has just been added to the stack. The push function adds an object to the stack while the pop function removes the element from the surface. The stack concept is used to organize and organize memory on computers.

const {stack} = require('stl-javascript')

const stack_example = new stack();

console.log(stack_example.isEmpty())
//it will return true because in the starting stack will be empty
console.log(stack_example.pop())
// it will return underflow 
stack_example.push(10); // This pushes the number to the top of the stack
stack_example.push(20);
stack_example.push(30);

console.log(stack_example.pop()) // this will return 30 , because 30 is at the top of the stack
console.log(stack_example.peek()); // this will return 30, because 30 is at the top of the stack 
// this function is for getting top of the stack
console.log(stack_example.printStack())// this will return "10 20"
// This function is used for printing stack

Queue

A line is a sequential structure that follows the way certain tasks are performed. The order is First In First Out (FIFO). A good example of a line is any line of customer service where the first-time customer is provided first. The difference between the stacks and the line is minus. In the stem we take out something that has just been added; in line, we delete a newly added item.

const {queue}= require('stl-javascript')
const queue_example = new queue();

console.log(queue_example.isEmpty()) //this will true because queue is empty at starting
console.log(queue_example.dequeue()) // this will return underflow because queue is empty at starting

queue_example.enqueue(10)
// this will be used to insert element in queue
queue_example.enqueue(20)
queue_example.enqueue(30)

console.log(queue_example.dequeue()) // this will return 10 because 10 is at the front of the queue
console.log(queue_example.front()) //this will return 20 because 20 is at the front of the queue
console.log(queue_example.printQueue()) // this will return "20 30 ". 
// this function is used for printing the queue

Non-Linear Data Structures

This library also includes several non-linear data structures located under the nonLinear folder. These modules are not exported from the package root, so require them with the full path shown below.

Priority Queue

A priority queue stores elements along with a priority value; lower numeric priority means higher urgency in this implementation.

const { PriorityQueue } = require('stl-javascript/nonLinear/priorityQueue')
const pq = new PriorityQueue()

pq.enqueue('Ram', 1)
pq.enqueue('Mohit', 2)
pq.enqueue('Rohit', 3)
console.log(pq.printPQueue()) // -> "Ram Mohit Rohit "
console.log(pq.dequeue()) // -> { element: 'Ram', priority: 1 }

Notes:

  • Enqueue keeps elements ordered by priority (smaller number = higher priority).
  • Equal priorities preserve insertion order (FIFO among equals).

Binary Search Tree

A binary search tree (BST) stores values so that left < node < right. The implementation supports insert, remove, search and traversals.

const { BinarySearchTree } = require('stl-javascript/nonLinear/binarySearchTree')
const bst = new BinarySearchTree()
bst.insert(15)
bst.insert(10)
bst.insert(20)

const root = bst.getRootNode()
console.log(bst.inorder(root))   // -> [10, 15, 20]
console.log(bst.preorder(root))  // -> [15, 10, 20]
console.log(bst.postorder(root)) // -> [10, 20, 15]

// Level-order and view helpers
console.log(bst.levelOrder())    // -> [15, 10, 20]
console.log(bst.leftView())      // -> [15, 10]
console.log(bst.rightView())     // -> [15, 20]
console.log(bst.topView())       // -> [10, 15, 20]  // leftmost -> rightmost horizontal distance

Notes:

  • Duplicate values are not inserted.
  • remove handles leaf nodes, single-child nodes and two-child nodes using the in-order successor.

Segment Tree

A segment tree supports range-sum queries and point updates in O(log n).

const { SegmentTree } = require('stl-javascript/nonLinear/segmentTree')
const arr = [15, 25, 10, 8, 22]
const st = new SegmentTree(arr)

console.log(st.query(1, 3)) // -> 43 (25 + 10 + 8)
st.update(1, 52)
console.log(st.query(1, 3)) // -> 70 (52 + 10 + 8)

Notes:

  • The constructor clones the input array internally; mutating the original array after construction will not affect the tree.
  • Queries outside the requested range return 0 for out-of-range segments.

Application

PostFix Conversion

use the following code to get the answer of postfix expression

const {postFixConversion} = require('stl-javascript/uses/postfixConversion')
console.log(postFixConversion("235*+8-")) // -> 9
console.log(postFixConversion("23*+")) // -> "Can't perform postfix evaluation"

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT