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

idati

v1.2.1

Published

A set of common used data structure.

Downloads

12

Readme

idati

A set of data structures and algorithms commonly used in front-end development.

version Build Status codecov

Install

npm install idati
# or
yarn add idati

What's in it?

Collection (Interface)

methods

  • clear() Removes all the elements from this collection.
  • contains(e: E): boolean Returns true if this collection contains the specified element.
  • isEmpty(): boolean Returns true if this collection contains no elements.
  • size(): number Returns the number of elements in this collection.
  • toArray(): T[] Returns an array containing all the elements in this collection.

Stack<E>

Order elements in a LIFO (last-in-first-out) manner.

Collection Symbol.iterator

Example

import {Stack} from 'idati';

const stack = new Stack();

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

stack.pop();  // 2
stack.pop();  // 1

Constructor

new Stack();
new Stack(['init', 'data']);

Methods

  • push(e: E) Pushes an item onto the top of this stack.
  • peek(): E Looks at the object at the top of this stack without removing it from the stack.
  • pop(): E Retrieves and removes the top of this stack.

Queue<E>

Order elements in a FIFO (first-in-first-out) manner.

Collection Symbol.iterator

Example

import {Queue} from 'idati';

const queue = new Queue();

queue.offer(1);
queue.offer(2);

queue.poll();  // 1
queue.poll();  // 2

Constructor

new Queue();
new Queue(['init', 'data']);

Methods

  • offer(e: E) Inserts the specified element into this queue.
  • peek(): E Retrieves, but does not remove, the head of this queue.
  • poll(): E Retrieves and removes the head of this queue.

PriorityQueue<E>

The elements of the priority queue are ordered according to the Comparator provided at queue construction time.

Collection Symbol.iterator

Example

import {PriorityQueue} from 'idati';

const queue = new PriorityQueue<{ value: number }>(
  (a, b) => b.value - a.value,
);

queue.offer({value: 3});
queue.offer({value: 5});
queue.offer({value: 1});

queue.poll();  // {value: 5}
queue.poll();  // {value: 3}
queue.poll();  // {value: 1}

Constructor

new PriorityQueue();
new PriorityQueue(initData);
new PriorityQueue(comparator);
new PriorityQueue(initData, comparator);

Methods

  • offer(e: E) Inserts the specified element into this priority queue.
  • peek(): E Retrieves, but does not remove, the head of this queue.
  • poll(): E Retrieves and removes the head of this queue.

LRUCache<V, K>

A cache that holds a limited number of values, When a value is added to a full cache, that will delete the "least-recently-used" items.

Symbol.iterator

Example

import {LRUCache} from 'idati';

const cache = new LRUCache<number>(2);  // max size 2
cache.set('a', 1);
cache.set('b', 2);
cache.set('c', 3); // deletes 'a'
cache.get('a'); // undefined
cache.get('b');
cache.set('d', 4); // deletes 'c'
console.log(cache.get('c')); // undefined

Constructor

new cache(maxSize);

Methods

  • set(key: K, value: V) Inserts entry into the cache and updates the " recently used".
  • peek(key: K): V Retrieves the value for key from this cache.
  • get(key: K): V Retrieves the value for key from this cache and updates the "recently used".
  • remove(key: K) Removes the entry for key if it exists.
  • clear() Removes all the entry in the cache.
  • size() Returns the number of entries in the cache.
  • toArray(): V[] Return an array of the values in the cache.