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

linkedlistpup

v1.0.4

Published

Double linked list implementation with a similar API to the Java LinkedList class.

Downloads

10

Readme

Build Status Coverage Status

linkedlistpup

Doubly linked list implementation with an extensive Java-like API. If you are used to the Java LinkedList collection, you should feel at home with linkedlistpup. Linked lists are best used as queues or stacks since random access is very inefficient.

Installation

Install with npm as expected.

npm install linkedlistpup --save

Usage

You will need to import linkedlistpup.

import LinkedList from 'linkedlistpup';

Or you will need to require it.

var LinkedList = require('linkedlistpup');

Then use linkedlistpup like any other class.

import LinkedList from 'linkedlistpup';

let list = new LinkedList();
list.add("Alpha");
list.add("Beta");
list.add("Charlie");

let firstValue = list.poll();

API

The API for linkedlistpup will feel familiar to Java users, but there are a few differences and additions to better fit into a Javascript paradigm. The list will hold any value aside from undefined.

LinkedList()

Creates an empty list.

add(item):boolean throws TypeError

Adds item to the end of the list. It will return true to indicate the item has been added. If the passed in value is undefined, then it will throw a TypeError.

addFirst(item):boolean throws TypeError

Adds item to the front of the list. It will return true to indicate the item has been added. If the passed in value is undefined, then it will throw a TypeError.

addLast(item):boolean throws TypeError

Adds item to the end of the list. It will return true to indicate the item has been added. If the passed in value is undefined, then it will throw a TypeError. This behavior is identical to add.

addAll(items):number throws TypeError

Adds all elements from items to the end of the list, returning the number of items added. The argument must be an array or another instance of linkedlistpup or it will throw a TypeError. Adding 4,5,6 to a list that already has 1,2,3 will result in 1, 2, 3, 4, 5, 6.

addAllFirst(items):number throws TypeError

Adds all elements from items to the front of the list, returning the number of items added. The argument must be an array or another instance of linkedlistpup or it will throw a TypeError. Adding 4,5,6 to a list that already has 1,2,3 will result in 4, 5, 6, 1, 2, 3.

size():number

Returns the number of items in the list.

clear()

Removes all items from the list, leaving it empty.

clone():likedlistpup

Performs a shallow copy of the list resulting in a new instance of linkedlistpup with the same contents as the original.

contains(item):boolean

Returns true if the list contains the specified item. If the item isn't in the list, then it will return false.

get(index):item throws RangeError

Returns the item, whatever type that might be, at the specified index. If the index isn't valid for the list, then a RangeError will be thrown.

getFirst():item throws RangeError

Returns the first item in the list. If the list is empty, then a RangeError will be thrown.

getLast():item throws RangeError

Returns the last item in the list. If the list is empty, then a RangeError will be thrown.

indexOf(item):number

Returns the index of the first occurence of the specified item in the list. If the item isn't in the list, then it will return -1.

lastIndexOf(item):number

Returns the index of the last occurence of the specified item in the list. If the item isn't in the list, then it will return -1.

isEmpty():boolean

Returns true if the list has no items and false if the list has one or more items.

isNotEmpty():boolean

Returns true if the list has one or more items and false if the list is empty.

peek():item

Returns the first item in the list while leaving the list unchanged. If the list is empty, then the returned value will be undefined.

peekFirst():item

Returns the first item in the list while leaving the list unchanged. If the list is empty, then the returned value will be undefined.

peekLast():item

Returns the last item in the list while leaving the list unchanged. If the list is empty, then the returned value will be undefined.

peekAt(index):item

Returns the item at the specified index in the list while leaving the list unchanged. If the index is invalid, then the returned value will be undefined.

poll():item

Removes and returns the first item in the list. If the list is empty, then it will return undefined.

pollFirst():item

Removes and returns the first item in the list. If the list is empty, then it will return undefined. Same as poll.

pollLast():item

Removes and returns the list item in the list. If the list is empty, then it will return undefined.

pop():item throws RangeError

Removes and returns the first item in the list. If the list is empty, then it will throw a RangeError.

remove():item throws RangeError

Removes and returns the first item in the list. If the list is empty, then it will throw a RangeError. Same as pop.

removeFirst():item throws RangeError

Removes and returns the first item in the list. If the list is empty, then it will throw a RangeError. Same as pop.

removeLast():item throws RangeError

Removes and returns the last item in the list. If the list is empty, then it will throw a RangeError.

removeAt(index):item throws RangeError

Removes and returns the item at the specified index. If the index is invalid, then it will throw a RangeError.

removeValue(item):boolean

Removes the first occurrence of the specified item in the list. If an item was removed, it will return true. If the item wasn't found, then it will return false.

removeFirstOccurrence(value):boolean

Removes the first occurrence of the specified item in the list. If an item was removed, it will return true. If the item wasn't found, then it will return false. Same as removeValue.

removeLastOccurrence(value):boolean

Removes the last occurrence of the specified item in the list. If an item was removed, it will return true. If the item wasn't found, then it will return false.

toArray():array

Returns the list as an array. If the list is empty, then an empty array will be returned.

toArrayReverse():array

Returns the list as an array in reverse order. If the list is empty, then an empty array will be returned.

forEach(function)

Invokes the passed-in function on each item in the list in order.

forEachReverse(function)

Invokes the passed-in function on each item in the list in reverse order.

insertBefore(index, item) throws RangeError, TypeError

Inserts an item in the list before the item at the specified index. If the list is empty and the index is zero, then it will add the item as the only item in the list. If the item passed in is undefined then a TypeError will be thrown. If the index is out of range (with the exception of an index of 0), then a RangeError will be thrown.

insertAfter(index, item) throws RangeError, TypeError

Inserts an item in the list after the item at the specified index. If the list is empty and the index is zero, then it will add the item as the only item in the list. If the item passed in is undefined then a TypeError will be thrown. If the index is out of range (with the exception of an index of 0), then a RangeError will be thrown.