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

abstract-data

v0.1.6

Published

A library of abstract data types for JavaScript and Node.js. Currently supports stacks and linked lists

Downloads

15

Readme

#Basic abstract data types for JavaScript Built by Audun Bjornerud Mo. @audun, audun.io

npm install abstract-data var abs = require('abstract-data'); or clone the repo and put abstract.js with your project and import with: <script src="abstract.js"></script>

Current types:

Planned types:

  • Binary trees
  • Queues
  • Dequeues
  • Heaps

Stacks have five attributes: .length, .push(), .pop(), .pushAll(), .popAll(), and are instantiated as empty by:

Client-side

var abs = new AbstractJS();
    myStack = new abs.Stack();

Node

var abs = require('abstract-data');
    myStack = news abs.Stack();

###Basics

  • Stack.push(item) pushes item onto the stack.
  • Stack.pop() retrieves the last item to pushed, and removes it from the the stack.
  • Stack.length holds the length of the stack as a number

###Advanced

####Stack.pushAll(Object || Array input, string modifier, bool reverse) Stack.pushAll() takes a parameter input that is either an array or a generic JS-object, and an optionalmodifier given as a string. modifier changes the manner in which input is pushed onto the stack, if input is an object. It is entirely optional.

#####Arrays The default behavior for Stack.pushAll(array) is to push from left to right, that is array[0] to array[array.length - 1]. However, if the last parameter is true, then this order is turned around. Example:

var abs = new AbstractJS(),
    myStack = new abs.Stack(),
    myArray = [1,2, 'three', function(){return '4'}];

myStack.pushAll(myArray);
//results in a stack with order: 1,2, 'three', function(){return '4'}

myStack.popAll() //Empties the stack

myStack.pushAll(myArray, '', true)
//results in a stack with order: function(){return '4'}, 'three', 1,2

######Objects The default behavior for Stack.pushAll(object) is to push key-value pairs of the form {key : value}. The modifier can here be used to only record keys, or only record values Example:

var abs = new AbstractJS();
    myStack = new abs.Stack(),
    myObj = {
    key_one : val_one,
    key_two : vale_two,
    key_three : val_three
    };

myStack.pushAll(myObj);
//results in a stack like: {key_one : value_one}, {key_two : value_two}, {key_three : value_three}

myStack.popAll(); //Empties the stack

myStack.pushAll(myObj, 'keys');
//results in a stack like: key_one, key_two, key_three

myStack.popAll();

myStack.pushall(myObj, 'values');
//results in a stack like: value_one, value_two, value_three

####Stack.popAll(callback(popped)) Stack.popAll() takes an optional callback. This callback is given the popped item as a parameter. The callback executes, and then repeats with the next object on the stack until the stack is empty. If no callback is specified, the stack will be emptied.

For example:

var abs = new AbstractJS();
    executionStack = new abs.Stack(),
    numbersToDouble = [1,2,3,4,5,6],
    results = [];

executionStack.pushAll(numbersToDouble);
executionStack.popAll(function(popped){
    results.append(popped * 2);
});

LLNodes can be added to a linked list manually by LinkedList.addNode(LLNode) but there are also two other ways of adding LLNodes:

######LinkedList.addAllNodes(startingNode) This starts at the given node, then recursively adds startingNode.next, continuing until it hits a node where node.next is undefined

######LinkedList.makeFromArray(array) This loops over the given array, adding the elements as it goes. The elements do not have to be LLNodes. Suppose array[i] is not undefined. If array[i+1] is also not undefined, an LLNode is created with myLLNode.value = array[i] and myLLNode.next = array[i+1], otherwise myLLNode.next = undefined and the loop stops. This LLNode is then added to the Linked List.

Properties:

  • LinkedList.length is a number, containing the length of the Linked List.

Built-in methods

  • LinkedList.iterateOver(callback(node)) iterates over all the nodes in the list, and executes a callback on them