# dll

> a lightweight, fast & flexible doubly linked list

Latest version **0.2.0** (published 2014-09-29) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install dll
pnpm add dll
yarn add dll
bun add dll
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2014-09-29 |
| First published | 2014-09-22 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Louis Acresti |
| Maintainers | namuol |
| Keywords | doubly, linked, list |

## Links

- npm: https://www.npmjs.com/package/dll
- Repository: https://github.com/namuol/dll
- Issues: https://github.com/namuol/dll/issues
- npm.io page: https://npm.io/package/dll

## Recent versions

- 0.2.0 (latest) — 2014-09-29
- 0.1.0 — 2014-09-22
- 0.0.0 — 2014-09-22

## README

# dll [![Build Status](https://drone.io/github.com/namuol/dll/status.png)](https://drone.io/github.com/namuol/dll/latest) [![devDependency Status](https://david-dm.org/namuol/dll/dev-status.svg?style=flat-square)](https://david-dm.org/namuol/dll#info=devDependencies)

A lightweight, fast & flexible doubly linked list for JavaScript.

```js
var currentID = 0;

function Food (name) {
  this.name = name;

  // a unique id field is required:
  this._id = currentID;
  currentID += 1;
}

var entityA = new Food('Bacon'),
    entityB = new Food('Brocolli'),
    entityC = new Food('Sausage'),
    entityD = new Food('Steak');

var LinkedList = require('dll');
var list = new LinkedList();

list.add(entityA);
list.add(entityB);
list.add(entityC);
list.add(entityD);

console.log(list.length); // "4"

// Iterating is easy:
var itr = list.first;
while (itr) {
  console.log(itr.obj.name);
  itr = itr.next;
}
// Output:
//   Bacon
//   Brocolli
//   Sausage
//   Steak

// Or even easier:
list.each(function (obj) {
  console.log (itr.obj.name);
});

assert( list.contains(entityC) === true );

list.remove(entityC);

assert( list.contains(entityC) === false );

// Iterating backwards is easy:
itr = list.last;
while (itr) {
  console.log(itr.obj.name);
  itr = itr.prev;
}
// Output:
//   Steak
//   Sausage
//   Bacon

list.clear();
console.log(list.length); // "0"
```

### Caveats

- Only objects are supported. No primitives.
- Objects must have a unique ID property (default is `_id`, but it can be changed with [`dll.config.idPropertyName`](#api-config-idPropertyName)).
- Duplicate items are not supported.

### API

```js
var LinkedList = require('dll');
```

<a name='api-config-idPropertyName'></a>
#### LinkedList.config.idPropertyName

*Type:* **String** *Default: `"_id"`*

The name of the property used to uniquely identify objects.

You are required to have a unique ID property on any objects that
are added to a linked list, but you can call it whatever you want by
changing the string value of this property.

<a name='api-new'></a>
#### new LinkedList()

Create a new linked list.

<a name='api-first'></a>
#### list.first

*Type:* [**Node**](#api-node)

The first node in the list.

If the list is empty, `list.first` will be `null`.

<a name='api-last'></a>
#### list.last

*Type:* [**Node**](#api-node)

The last node in the list.

If the list is empty, `list.last` will be `null`.

<a name='api-length'></a>
#### list.length

The number of objects in the list.

<a name='api-add'></a>
#### list.add(obj)

Add an object to a list. If a list already contains the object,
this will have no effect on the list.

**Always returns `obj`**

<a name='api-remove'></a>
#### list.remove(obj)

Remove an object from the list.

**Returns `obj` if the object was removed, `false` if it was not part of the list**

<a name='api-clear'></a>
#### list.clear(obj)

Removes all objects from the list and sets its length to zero.

<a name='api-each'></a>
#### list.each(function (obj) {/* ... */})

Call a function for every object in the list.

<a name='api-node'></a>
#### Node

A container representing a location within the list.

<a name='api-node-obj'></a>
#### Node.obj

*Type:* **Object**

The object that is at this location in the list.

<a name='api-node-next'></a>
#### Node.next

*Type:* [**Node**](#api-node)

The node that follows this node.

If this is the last node in the list, `next` will be `null`.

<a name='api-node-prev'></a>
#### Node.prev

*Type:* [**Node**](#api-node)

The node that precedes this node.

If this is the first node in the list, `prev` will be `null`.

## License

Apache 2.0

## Install

```bash
npm install dll --save
```

----

[![Analytics](https://ga-beacon.appspot.com/UA-33247419-2/dll/README.md)](https://github.com/igrigorik/ga-beacon)

---
_Source: https://npm.io/package/dll · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
