linked-list
Advanced tools
Comparing version 2.0.0 to 2.0.1
118
index.js
'use strict' | ||
/* Expose. */ | ||
// Expose. | ||
module.exports = List | ||
@@ -37,12 +37,11 @@ | ||
/* Constants. */ | ||
// Constants. | ||
var errorMessage = | ||
'An argument without append, prepend, or detach methods was given to `List' | ||
/* Creates a new List: A linked list is a bit like an Array, | ||
* but knows nothing about how many items are in it, and | ||
* knows only about its first (`head`) and last (`tail`) | ||
* items. Each item (e.g. `head`, `tail`, &c.) knows which | ||
* item comes before or after it (its more like the | ||
* implementation of the DOM in JavaScript). */ | ||
// Creates a new List: A linked list is a bit like an Array, but knows nothing | ||
// about how many items are in it, and knows only about its first (`head`) and | ||
// last (`tail`) items. | ||
// Each item (e.g. `head`, `tail`, &c.) knows which item comes before or after | ||
// it (its more like the implementation of the DOM in JavaScript). | ||
function List(/* items... */) { | ||
@@ -54,4 +53,3 @@ if (arguments.length !== 0) { | ||
/* Creates a new list from the arguments (each a list item) | ||
* passed in. */ | ||
// Creates a new list from the arguments (each a list item) passed in. | ||
function appendAll(list, items) { | ||
@@ -87,4 +85,3 @@ var length | ||
/* Creates a new list from the arguments (each a list item) | ||
* passed in. */ | ||
// Creates a new list from the arguments (each a list item) passed in. | ||
function of(/* items... */) { | ||
@@ -94,4 +91,4 @@ return appendAll(new this(), arguments) | ||
/* Creates a new list from the given array-like object | ||
* (each a list item) passed in. */ | ||
// Creates a new list from the given array-like object (each a list item) passed | ||
// in. | ||
function from(items) { | ||
@@ -101,3 +98,4 @@ return appendAll(new this(), items) | ||
/* Returns the list’s items as an array. This does *not* detach the items. */ | ||
// Returns the list’s items as an array. | ||
// This does *not* detach the items. | ||
function toArray() { | ||
@@ -115,4 +113,4 @@ var item = this.head | ||
/* Prepends the given item to the list: Item will be the | ||
* new first item (`head`). */ | ||
// Prepends the given item to the list. | ||
// `item` will be the new first item (`head`). | ||
function prepend(item) { | ||
@@ -142,5 +140,5 @@ var self = this | ||
/* Appends the given item to the list: Item will be the new | ||
* last item (`tail`) if the list had a first item, and its | ||
* first item (`head`) otherwise. */ | ||
// Appends the given item to the list. | ||
// `item` will be the new last item (`tail`) if the list had a first item, and | ||
// its first item (`head`) otherwise. | ||
function append(item) { | ||
@@ -159,4 +157,4 @@ if (!item) { | ||
/* If self has a last item, defer appending to the last items append | ||
* method, and return the result. */ | ||
// If self has a last item, defer appending to the last items append method, | ||
// and return the result. | ||
if (tail) { | ||
@@ -166,4 +164,4 @@ return tail.append(item) | ||
/* If self has a first item, defer appending to the first items append | ||
* method, and return the result. */ | ||
// If self has a first item, defer appending to the first items append method, | ||
// and return the result. | ||
if (head) { | ||
@@ -173,3 +171,3 @@ return head.append(item) | ||
/* ...otherwise, there is no `tail` or `head` item yet. */ | ||
// …otherwise, there is no `tail` or `head` item yet. | ||
@@ -184,3 +182,3 @@ item.detach() | ||
/* Creates an iterator from the list. */ | ||
// Creates an iterator from the list. | ||
function iterator() { | ||
@@ -190,8 +188,8 @@ return new Iter(this.head) | ||
/* Creates a new ListItem: A linked list item is a bit like | ||
* DOM node: It knows only about its "parent" (`list`), the | ||
* item before it (`prev`), and the item after it (`next`). */ | ||
// Creates a new ListItem: | ||
// An item is a bit like DOM node: It knows only about its "parent" (`list`), | ||
// the item before it (`prev`), and the item after it (`next`). | ||
function ListItem() {} | ||
/* Detaches the item operated on from its parent list. */ | ||
// Detaches the item operated on from its parent list. | ||
function detach() { | ||
@@ -207,4 +205,4 @@ var self = this | ||
/* If self is the last item in the parent list, link the | ||
* lists last item to the previous item. */ | ||
// If self is the last item in the parent list, link the lists last item to | ||
// the previous item. | ||
if (list.tail === self) { | ||
@@ -214,4 +212,4 @@ list.tail = prev | ||
/* If self is the first item in the parent list, link | ||
* the lists first item to the next item. */ | ||
// If self is the first item in the parent list, link the lists first item to | ||
// the next item. | ||
if (list.head === self) { | ||
@@ -221,4 +219,4 @@ list.head = next | ||
/* If both the last and first items in the parent list | ||
* are the same, remove the link to the last item. */ | ||
// If both the last and first items in the parent list are the same, remove | ||
// the link to the last item. | ||
if (list.tail === list.head) { | ||
@@ -228,4 +226,3 @@ list.tail = null | ||
/* If a previous item exists, link its next item to selfs | ||
* next item. */ | ||
// If a previous item exists, link its next item to selfs next item. | ||
if (prev) { | ||
@@ -235,4 +232,3 @@ prev.next = next | ||
/* If a next item exists, link its previous item to selfs | ||
* previous item. */ | ||
// If a next item exists, link its previous item to selfs previous item. | ||
if (next) { | ||
@@ -242,4 +238,4 @@ next.prev = prev | ||
/* Remove links from self to both the next and previous | ||
* items, and to the parent list. */ | ||
// Remove links from self to both the next and previous items, and to the | ||
// parent list. | ||
self.prev = self.next = self.list = null | ||
@@ -250,3 +246,3 @@ | ||
/* Prepends the given item *before* the item operated on. */ | ||
// Prepends the given item *before* the item operated on. | ||
function prependItem(item) { | ||
@@ -261,3 +257,3 @@ if (!item || !item.append || !item.prepend || !item.detach) { | ||
/* If self is detached, return false. */ | ||
// If self is detached, return false. | ||
if (!list) { | ||
@@ -267,6 +263,6 @@ return false | ||
/* Detach the prependee. */ | ||
// Detach the prependee. | ||
item.detach() | ||
/* If self has a previous item... */ | ||
// If self has a previous item... | ||
if (prev) { | ||
@@ -277,11 +273,11 @@ item.prev = prev | ||
/* Connect the prependee. */ | ||
// Connect the prependee. | ||
item.next = self | ||
item.list = list | ||
/* Set the previous item of self to the prependee. */ | ||
// Set the previous item of self to the prependee. | ||
self.prev = item | ||
/* If self is the first item in the parent list, link the | ||
* lists first item to the prependee. */ | ||
// If self is the first item in the parent list, link the lists first item to | ||
// the prependee. | ||
if (self === list.head) { | ||
@@ -291,4 +287,3 @@ list.head = item | ||
/* If the the parent list has no last item, link the lists | ||
* last item to self. */ | ||
// If the the parent list has no last item, link the lists last item to self. | ||
if (!list.tail) { | ||
@@ -301,3 +296,3 @@ list.tail = self | ||
/* Appends the given item *after* the item operated on. */ | ||
// Appends the given item *after* the item operated on. | ||
function appendItem(item) { | ||
@@ -316,6 +311,6 @@ if (!item || !item.append || !item.prepend || !item.detach) { | ||
/* Detach the appendee. */ | ||
// Detach the appendee. | ||
item.detach() | ||
/* If self has a next item... */ | ||
// If self has a next item… | ||
if (next) { | ||
@@ -326,12 +321,11 @@ item.next = next | ||
/* Connect the appendee. */ | ||
// Connect the appendee. | ||
item.prev = self | ||
item.list = list | ||
/* Set the next item of self to the appendee. */ | ||
// Set the next item of self to the appendee. | ||
self.next = item | ||
/* If the the parent list has no last item or if self is | ||
* the parent lists last item, link the lists last item | ||
* to the appendee. */ | ||
// If the the parent list has no last item or if self is the parent lists last | ||
// item, link the lists last item to the appendee. | ||
if (self === list.tail || !list.tail) { | ||
@@ -344,3 +338,3 @@ list.tail = item | ||
/* Creates a new `Iter` for looping over the `LinkedList`. */ | ||
// Creates a new `Iter` for looping over the `LinkedList`. | ||
function Iter(item) { | ||
@@ -350,3 +344,3 @@ this.item = item | ||
/* Move the `Iter` to the next item. */ | ||
// Move the `Iter` to the next item. | ||
function next() { | ||
@@ -353,0 +347,0 @@ var current = this.item |
{ | ||
"name": "linked-list", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Minimalistic linked lists", | ||
@@ -14,6 +14,7 @@ "types": "index.d.ts", | ||
"bugs": "https://github.com/wooorm/linked-list/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com>", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
"contributors": [ | ||
"Titus Wormer <tituswormer@gmail.com> (wooorm.com)", | ||
"Blake Embrey <hello@blakeembrey.com>" | ||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
"Blake Embrey <hello@blakeembrey.com>", | ||
"Regev Brody <regevbr@gmail.com>" | ||
], | ||
@@ -27,3 +28,3 @@ "files": [ | ||
"browserify": "^16.0.0", | ||
"nyc": "^13.0.0", | ||
"nyc": "^14.0.0", | ||
"prettier": "^1.12.1", | ||
@@ -57,4 +58,2 @@ "remark-cli": "^6.0.0", | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off", | ||
"no-multi-assign": "off", | ||
@@ -61,0 +60,0 @@ "unicorn/prefer-spread": "off" |
@@ -1,3 +0,8 @@ | ||
# linked-list [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
# linked-list | ||
[![Build][build-badge]][build] | ||
[![Coverage][coverage-badge]][coverage] | ||
[![Downloads][downloads-badge]][downloads] | ||
[![Size][size-badge]][size] | ||
Small double [linked list][wiki]. | ||
@@ -92,5 +97,6 @@ | ||
Create a new `this` and adds the given array of items. Ignores `null` | ||
or `undefined` values. Throws an error when a given item has no `detach`, | ||
`append`, or `prepend` methods. | ||
Create a new `this` and adds the given array of items. | ||
Ignores `null` or `undefined` values. | ||
Throws an error when a given item has no `detach`, `append`, or `prepend` | ||
methods. | ||
@@ -104,4 +110,4 @@ #### `LinkedList.of([items…])` | ||
Creates a new Linked List from the given arguments. Defers to | ||
`LinkedList.from`. | ||
Creates a new Linked List from the given arguments. | ||
Defers to `LinkedList.from`. | ||
@@ -123,4 +129,6 @@ #### `LinkedList#append(item)` | ||
Appends an item to a list. Throws an error when the given item has no | ||
`detach`, `append`, or `prepend` methods. Returns the given item. | ||
Appends an item to a list. | ||
Throws an error when the given item has no `detach`, `append`, or `prepend` | ||
methods. | ||
Returns the given item. | ||
@@ -136,4 +144,6 @@ #### `LinkedList#prepend(item)` | ||
Prepends an item to a list. Throws an error when the given item has | ||
no `detach`, `append`, or `prepend` methods. Returns the given item. | ||
Prepends an item to a list. | ||
Throws an error when the given item has no `detach`, `append`, or `prepend` | ||
methods. | ||
Returns the given item. | ||
@@ -183,4 +193,4 @@ #### `LinkedList#toArray()` | ||
The last item in a list, and `null` otherwise. Note that a list with only | ||
one item has **no tail**, only a head. | ||
The last item in a list, and `null` otherwise. | ||
Note that a list with only one item has **no tail**, only a head. | ||
@@ -209,6 +219,7 @@ ## `LinkedList.Item()` | ||
Adds the given item **after** the operated on item in a list. Throws | ||
an error when the given item has no `detach`, `append`, or `prepend` | ||
methods. Returns false when the operated on item is not attached to | ||
a list, otherwise the given item. | ||
Adds the given item **after** the operated on item in a list. | ||
Throws an error when the given item has no `detach`, `append`, or `prepend` | ||
methods. | ||
Returns false when the operated on item is not attached to a list, otherwise the | ||
given item. | ||
@@ -229,4 +240,5 @@ #### `LinkedList.Item#prepend(item)` | ||
Adds the given item **before** the operated on item in a list. Throws an | ||
error when the given item has no `detach`, `append`, or `prepend` methods. | ||
Adds the given item **before** the operated on item in a list. | ||
Throws an error when the given item has no `detach`, `append`, or `prepend` | ||
methods. | ||
Returns false when the operated on item is not attached to a list, otherwise | ||
@@ -247,5 +259,7 @@ the given item. | ||
Removes the operated on item from its parent list. Removes references to | ||
it on its parent `list`, and `prev` and `next` items; relinking them when | ||
possible. Returns the operated on item. Even when it was already detached. | ||
Removes the operated on item from its parent list. | ||
Removes references to it on its parent `list`, and `prev` and `next` items; | ||
relinking them when possible. | ||
Returns the operated on item. | ||
Even when it was already detached. | ||
@@ -321,10 +335,18 @@ #### `LinkedList.Item#next` | ||
[travis-badge]: https://img.shields.io/travis/wooorm/linked-list.svg | ||
[build-badge]: https://img.shields.io/travis/wooorm/linked-list.svg | ||
[travis]: https://travis-ci.org/wooorm/linked-list | ||
[build]: https://travis-ci.org/wooorm/linked-list | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/linked-list.svg | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/linked-list.svg | ||
[codecov]: https://codecov.io/github/wooorm/linked-list | ||
[coverage]: https://codecov.io/github/wooorm/linked-list | ||
[downloads-badge]: https://img.shields.io/npm/dm/linked-list.svg | ||
[downloads]: https://www.npmjs.com/package/linked-list | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/linked-list.svg | ||
[size]: https://bundlephobia.com/result?p=linked-list | ||
[npm]: https://docs.npmjs.com/cli/install | ||
@@ -334,4 +356,4 @@ | ||
[author]: http://wooorm.com | ||
[author]: https://wooorm.com | ||
[wiki]: http://wikipedia.org/wiki/Linked_list | ||
[wiki]: https://wikipedia.org/wiki/Linked_list |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17386
350
274