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

@akashbabu/node-dll

v2.0.2

Published

DLL(doubly linked list) library for javascript projects

Downloads

3,885

Readme

node-dll Coverage Status Build Status Maintainability

DLL(Doubly linked list) implementation for javascript projects

Introduction

Doubly linked list(DLL) is inevitable in certain situation where performance is preferred while slicing an array (maybe there are more to it, but this is mostly my PoV). So this library was created with a simple, yet powerful interface for interacting with the underlying DLL schema.

This library is written in typescript for robust APIs and type support.

Every aspect was desgined and thought carefully to minimize introducing new bugs.

Documentation

API method name has been carefully chosen to nearly match Array methods, such that learning curve is least and adaptability is higher. But a few methods couldn't have had a different name and we had to convince ourselves with those method name.

Installation

npm i @akashbabu/node-dll -S

Sample usage

import {DLL, DLLItem} from '@akashbabu/node-dll';

const dll = new DLL<string>();

const dllItem: DLLItem<string> = dll.push('foo');
console.log(dllItem.data) // => foo

console.log(dll.length) // => 1

dll.remove(dllItem)
console.log(dll.length) // => 0

dll.push('foo')
dll.unshift('bar')

const headItem = dll.head
console.log(headItem.data) // => bar

const headData = dll.shift()
console.log(headData) // => bar

console.log(dll.head.data) // => foo

dll.clear()
console.log(dll.length) // => 0

const firstItem = dll.push('first')
dll.push('third')

dll.appendAfter(firstItem, 'second')

dll.forEach((item, i) => {
  console.log(`${i + 1}) ${item}`);
})
// => 1) first
// => 2) second
// => 3) third


console.log(dll.map((item, i) => `${i + 1}) ${item}`));
// => ["1) first", "2) second", "3) third"]

API - DLL

new DLL():

This creates a new instance of DLL.
T -> Denotes the type of data being saved in DLL

.head: DLLItem | null

Returns the first item in the list

.tail: DLLItem | null

Returns the last item in the list

.length: number

Returns the length of the list

.shift(): T | undefined

Removes and returns the first item in the list. Returns undefined if the list is empty

.unshift(data: T): void

Adds the given item to the head of DLL (same as Array.unshift logic)

.forEach(cb: (data: T, i: number) => void): void

Iterates through the entire DLL

.map(cb: (data: T, i: number) => U): U[]

Iterates through the entire DLL and returns the resultant array.
U -> Denotes the return type of cb(callback)

.push(data: T): DLLItem

Adds the given item to the tail of DLL and returns the added item

.appendAfter(dllItem: DLLItem, data: T): DLLItem

Adds the given data after the given dllItem in DLL and returns the added item

.remove(dllItem: DLLItem): boolean

Removes the given item from DLL and returns true if the removal was successful

.clear()

Removes all the items in the DLL

API - DLLItem

DLLItem has a readonly access to prev and next properties, this is to ensure that the users doesn't change them unintentionally (which can mess up with the entire DLL) and hence less surface for bugs.

.data

Set / get data value on the DLLItem via this property

.prev

Get prev value on the DLLItem via this property

.next

Get next value on the DLLItem via this property

Contribution

All contributions are welcome!!!

But before raising any issue, please check the issue-tracker in github if there is any matching issues already in the pipeline, if not then please go ahead and raise your own.

PR Guidelines:

  • Make sure to include corresponding test cases
  • Be generous on code comments
  • Write documentation if necessary
  • Wait for your approval 😜

Licence

MIT