linked-list
Advanced tools
Comparing version 1.0.3 to 1.0.4
180
index.js
@@ -1,29 +0,29 @@ | ||
'use strict'; | ||
'use strict' | ||
/* Expose. */ | ||
module.exports = List; | ||
module.exports = List | ||
List.Item = ListItem; | ||
List.Item = ListItem | ||
var ListPrototype = List.prototype; | ||
var ListItemPrototype = ListItem.prototype; | ||
var ListPrototype = List.prototype | ||
var ListItemPrototype = ListItem.prototype | ||
ListPrototype.tail = ListPrototype.head = null; | ||
ListPrototype.tail = ListPrototype.head = null | ||
List.of = of; | ||
List.from = from; | ||
List.of = of | ||
List.from = from | ||
ListPrototype.toArray = toArray; | ||
ListPrototype.prepend = prepend; | ||
ListPrototype.append = append; | ||
ListPrototype.toArray = toArray | ||
ListPrototype.prepend = prepend | ||
ListPrototype.append = append | ||
ListItemPrototype.next = ListItemPrototype.prev = ListItemPrototype.list = null; | ||
ListItemPrototype.next = ListItemPrototype.prev = ListItemPrototype.list = null | ||
ListItemPrototype.prepend = prependItem; | ||
ListItemPrototype.append = appendItem; | ||
ListItemPrototype.detach = detach; | ||
ListItemPrototype.prepend = prependItem | ||
ListItemPrototype.append = appendItem | ||
ListItemPrototype.detach = detach | ||
/* Constants. */ | ||
var errorMessage = 'An argument without append, prepend, ' + | ||
'or detach methods was given to `List'; | ||
var errorMessage = | ||
'An argument without append, prepend, or detach methods was given to `List' | ||
@@ -38,3 +38,3 @@ /* Creates a new List: A linked list is a bit like an Array, | ||
if (arguments.length !== 0) { | ||
appendAll(this, arguments); | ||
appendAll(this, arguments) | ||
} | ||
@@ -46,15 +46,15 @@ } | ||
function appendAll(list, items) { | ||
var length = items && items.length; | ||
var index = -1; | ||
var item; | ||
var length = items && items.length | ||
var index = -1 | ||
var item | ||
while (++index < length) { | ||
item = items[index]; | ||
item = items[index] | ||
if (item !== null && item !== undefined) { | ||
list.append(item); | ||
list.append(item) | ||
} | ||
} | ||
return list; | ||
return list | ||
} | ||
@@ -65,3 +65,3 @@ | ||
function of(/* items... */) { | ||
return appendAll(new this(), arguments); | ||
return appendAll(new this(), arguments) | ||
} | ||
@@ -72,3 +72,3 @@ | ||
function from(items) { | ||
return appendAll(new this(), items); | ||
return appendAll(new this(), items) | ||
} | ||
@@ -78,11 +78,11 @@ | ||
function toArray() { | ||
var item = this.head; | ||
var result = []; | ||
var item = this.head | ||
var result = [] | ||
while (item) { | ||
result.push(item); | ||
item = item.next; | ||
result.push(item) | ||
item = item.next | ||
} | ||
return result; | ||
return result | ||
} | ||
@@ -93,23 +93,23 @@ | ||
function prepend(item) { | ||
var self = this; | ||
var head = self.head; | ||
var self = this | ||
var head = self.head | ||
if (!item) { | ||
return false; | ||
return false | ||
} | ||
if (!item.append || !item.prepend || !item.detach) { | ||
throw new Error(errorMessage + '#prepend`.'); | ||
throw new Error(errorMessage + '#prepend`.') | ||
} | ||
if (head) { | ||
return head.prepend(item); | ||
return head.prepend(item) | ||
} | ||
item.detach(); | ||
item.detach() | ||
item.list = self; | ||
self.head = item; | ||
item.list = self | ||
self.head = item | ||
return item; | ||
return item | ||
} | ||
@@ -122,12 +122,12 @@ | ||
if (!item) { | ||
return false; | ||
return false | ||
} | ||
if (!item.append || !item.prepend || !item.detach) { | ||
throw new Error(errorMessage + '#append`.'); | ||
throw new Error(errorMessage + '#append`.') | ||
} | ||
var self = this; | ||
var head = self.head; | ||
var tail = self.tail; | ||
var self = this | ||
var head = self.head | ||
var tail = self.tail | ||
@@ -137,3 +137,3 @@ /* If self has a last item, defer appending to the last items append | ||
if (tail) { | ||
return tail.append(item); | ||
return tail.append(item) | ||
} | ||
@@ -144,3 +144,3 @@ | ||
if (head) { | ||
return head.append(item); | ||
return head.append(item) | ||
} | ||
@@ -150,8 +150,8 @@ | ||
item.detach(); | ||
item.detach() | ||
item.list = self; | ||
self.head = item; | ||
item.list = self | ||
self.head = item | ||
return item; | ||
return item | ||
} | ||
@@ -166,9 +166,9 @@ | ||
function detach() { | ||
var self = this; | ||
var list = self.list; | ||
var prev = self.prev; | ||
var next = self.next; | ||
var self = this | ||
var list = self.list | ||
var prev = self.prev | ||
var next = self.next | ||
if (!list) { | ||
return self; | ||
return self | ||
} | ||
@@ -179,3 +179,3 @@ | ||
if (list.tail === self) { | ||
list.tail = prev; | ||
list.tail = prev | ||
} | ||
@@ -186,3 +186,3 @@ | ||
if (list.head === self) { | ||
list.head = next; | ||
list.head = next | ||
} | ||
@@ -193,3 +193,3 @@ | ||
if (list.tail === list.head) { | ||
list.tail = null; | ||
list.tail = null | ||
} | ||
@@ -200,3 +200,3 @@ | ||
if (prev) { | ||
prev.next = next; | ||
prev.next = next | ||
} | ||
@@ -207,3 +207,3 @@ | ||
if (next) { | ||
next.prev = prev; | ||
next.prev = prev | ||
} | ||
@@ -213,5 +213,5 @@ | ||
* items, and to the parent list. */ | ||
self.prev = self.next = self.list = null; | ||
self.prev = self.next = self.list = null | ||
return self; | ||
return self | ||
} | ||
@@ -222,29 +222,29 @@ | ||
if (!item || !item.append || !item.prepend || !item.detach) { | ||
throw new Error(errorMessage + 'Item#prepend`.'); | ||
throw new Error(errorMessage + 'Item#prepend`.') | ||
} | ||
var self = this; | ||
var list = self.list; | ||
var prev = self.prev; | ||
var self = this | ||
var list = self.list | ||
var prev = self.prev | ||
/* If self is detached, return false. */ | ||
if (!list) { | ||
return false; | ||
return false | ||
} | ||
/* Detach the prependee. */ | ||
item.detach(); | ||
item.detach() | ||
/* If self has a previous item... */ | ||
if (prev) { | ||
item.prev = prev; | ||
prev.next = item; | ||
item.prev = prev | ||
prev.next = item | ||
} | ||
/* Connect the prependee. */ | ||
item.next = self; | ||
item.list = list; | ||
item.next = self | ||
item.list = list | ||
/* Set the previous item of self to the prependee. */ | ||
self.prev = item; | ||
self.prev = item | ||
@@ -254,3 +254,3 @@ /* If self is the first item in the parent list, link the | ||
if (self === list.head) { | ||
list.head = item; | ||
list.head = item | ||
} | ||
@@ -261,6 +261,6 @@ | ||
if (!list.tail) { | ||
list.tail = self; | ||
list.tail = self | ||
} | ||
return item; | ||
return item | ||
} | ||
@@ -271,28 +271,28 @@ | ||
if (!item || !item.append || !item.prepend || !item.detach) { | ||
throw new Error(errorMessage + 'Item#append`.'); | ||
throw new Error(errorMessage + 'Item#append`.') | ||
} | ||
var self = this; | ||
var list = self.list; | ||
var next = self.next; | ||
var self = this | ||
var list = self.list | ||
var next = self.next | ||
if (!list) { | ||
return false; | ||
return false | ||
} | ||
/* Detach the appendee. */ | ||
item.detach(); | ||
item.detach() | ||
/* If self has a next item... */ | ||
if (next) { | ||
item.next = next; | ||
next.prev = item; | ||
item.next = next | ||
next.prev = item | ||
} | ||
/* Connect the appendee. */ | ||
item.prev = self; | ||
item.list = list; | ||
item.prev = self | ||
item.list = list | ||
/* Set the next item of self to the appendee. */ | ||
self.next = item; | ||
self.next = item | ||
@@ -303,6 +303,6 @@ /* If the the parent list has no last item or if self is | ||
if (self === list.tail || !list.tail) { | ||
list.tail = item; | ||
list.tail = item | ||
} | ||
return item; | ||
return item | ||
} |
{ | ||
"name": "linked-list", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Minimalistic linked lists", | ||
@@ -18,25 +18,34 @@ "license": "MIT", | ||
"devDependencies": { | ||
"browserify": "^14.0.0", | ||
"browserify": "^16.0.0", | ||
"esmangle": "^1.0.1", | ||
"has": "^1.0.1", | ||
"nyc": "^11.0.0", | ||
"remark-cli": "^3.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"prettier": "^1.12.1", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.6.2", | ||
"xo": "^0.18.0" | ||
"xo": "^0.20.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . -qfo", | ||
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", | ||
"build-bundle": "browserify index.js --bare -s LinkedList > linked-list.js", | ||
"build-mangle": "esmangle < linked-list.js > linked-list.min.js", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint": "xo", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"prettier": true, | ||
"esnext": false, | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off", | ||
"no-multi-assign": "off" | ||
@@ -48,2 +57,7 @@ }, | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
] | ||
}, | ||
"nyc": { | ||
@@ -54,8 +68,3 @@ "check-coverage": true, | ||
"branches": 100 | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
] | ||
} | ||
} |
218
readme.md
@@ -16,15 +16,15 @@ # linked-list [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
```javascript | ||
var LinkedList = require('linked-list'); | ||
var LinkedList = require('linked-list') | ||
var item1 = new LinkedList.Item(); | ||
var item2 = new LinkedList.Item(); | ||
var item3 = new LinkedList.Item(); | ||
var list = new LinkedList(item1, item2, item3); | ||
var item1 = new LinkedList.Item() | ||
var item2 = new LinkedList.Item() | ||
var item3 = new LinkedList.Item() | ||
var list = new LinkedList(item1, item2, item3) | ||
list.head; //=> item1 | ||
list.head.next; //=> item2 | ||
list.head.next.next; //=> item3 | ||
list.head.next.prev; //=> item1 | ||
list.tail; //=> item3 | ||
list.tail.next; //=> `null` | ||
list.head // => item1 | ||
list.head.next // => item2 | ||
list.head.next.next // => item3 | ||
list.head.next.prev // => item1 | ||
list.tail // => item3 | ||
list.tail.next // => `null` | ||
``` | ||
@@ -35,38 +35,38 @@ | ||
```javascript | ||
var inherits = require('inherits'); | ||
var List = require('linked-list'); | ||
var inherits = require('inherits') | ||
var List = require('linked-list') | ||
Tokens.prototype.join = join; | ||
Token.prototype.toString = toString; | ||
Tokens.prototype.join = join | ||
Token.prototype.toString = toString | ||
inherits(Tokens, List); | ||
inherits(Token, List.Item); | ||
inherits(Tokens, List) | ||
inherits(Token, List.Item) | ||
var dogs = new Token('dogs'); | ||
var and = new Token('&'); | ||
var cats = new Token('cats'); | ||
var tokens = new Tokens(dogs, and, cats); | ||
var dogs = new Token('dogs') | ||
var and = new Token('&') | ||
var cats = new Token('cats') | ||
var tokens = new Tokens(dogs, and, cats) | ||
tokens.join(' '); //=> 'dogs & cats' | ||
tokens.join(' ') // => 'dogs & cats' | ||
and.prepend(cats); | ||
and.append(dogs); | ||
and.prepend(cats) | ||
and.append(dogs) | ||
tokens.join(' ') + '!'; //=> 'cats & dogs!' | ||
tokens.join(' ') + '!' // => 'cats & dogs!' | ||
function Tokens() { | ||
List.apply(this, arguments); | ||
List.apply(this, arguments) | ||
} | ||
function Token(value) { | ||
this.value = value; | ||
List.Item.apply(this, arguments); | ||
this.value = value | ||
List.Item.apply(this, arguments) | ||
} | ||
function join(delimeter) { | ||
return this.toArray().join(delimeter); | ||
function join(delimiter) { | ||
return this.toArray().join(delimiter) | ||
} | ||
function toString() { | ||
return this.value; | ||
return this.value | ||
} | ||
@@ -80,4 +80,4 @@ ``` | ||
```javascript | ||
new LinkedList(); | ||
new LinkedList(new LinkedList.Item(), new LinkedList.Item()); | ||
new LinkedList() | ||
new LinkedList(new LinkedList.Item(), new LinkedList.Item()) | ||
``` | ||
@@ -90,5 +90,5 @@ | ||
```javascript | ||
LinkedList.from(); | ||
LinkedList.from([]), | ||
LinkedList.from([new LinkedList.Item(), new LinkedList.Item()]); | ||
LinkedList.from() | ||
LinkedList.from([]) | ||
LinkedList.from([new LinkedList.Item(), new LinkedList.Item()]) | ||
``` | ||
@@ -103,4 +103,4 @@ | ||
```javascript | ||
LinkedList.of(), | ||
LinkedList.of(new LinkedList.Item(), new LinkedList.Item()); | ||
LinkedList.of() | ||
LinkedList.of(new LinkedList.Item(), new LinkedList.Item()) | ||
``` | ||
@@ -115,11 +115,11 @@ | ||
var list = new LinkedList() | ||
var item = new LinkedList.Item(); | ||
var item = new LinkedList.Item() | ||
list.head === null //=> true | ||
item.list === null //=> true | ||
list.head === null // => true | ||
item.list === null // => true | ||
list.append(item); | ||
list.append(item) | ||
list.head === item //=> true | ||
item.list === list //=> true | ||
list.head === item // => true | ||
item.list === list // => true | ||
``` | ||
@@ -133,6 +133,6 @@ | ||
```javascript | ||
var list = new LinkedList(), | ||
var item = new LinkedList.Item(); | ||
var list = new LinkedList() | ||
var item = new LinkedList.Item() | ||
list.prepend(item); | ||
list.prepend(item) | ||
``` | ||
@@ -146,11 +146,11 @@ | ||
```javascript | ||
var item1 = new LinkedList.Item(); | ||
var item2 = new LinkedList.Item(), | ||
var list = new LinkedList(item1, item2), | ||
var array = list.toArray(); | ||
var item1 = new LinkedList.Item() | ||
var item2 = new LinkedList.Item() | ||
var list = new LinkedList(item1, item2) | ||
var array = list.toArray() | ||
array[0] === item1; //=> true | ||
array[1] === item2; //=> true | ||
array[0].next === item2; //=> true | ||
array[1].prev === item1; //=> true | ||
array[0] === item1 // => true | ||
array[1] === item2 // => true | ||
array[0].next === item2 // => true | ||
array[1].prev === item1 // => true | ||
``` | ||
@@ -163,6 +163,6 @@ | ||
```javascript | ||
var item = new LinkedList.Item(); | ||
var list = new LinkedList(item); | ||
var item = new LinkedList.Item() | ||
var list = new LinkedList(item) | ||
list.head === item; //=> true | ||
list.head === item // => true | ||
``` | ||
@@ -175,13 +175,13 @@ | ||
```javascript | ||
var list = new LinkedList(); | ||
var item1 = new LinkedList.Item(); | ||
var item2 = new LinkedList.Item(); | ||
var list = new LinkedList() | ||
var item1 = new LinkedList.Item() | ||
var item2 = new LinkedList.Item() | ||
list.tail === null; //=> true | ||
list.tail === null // => true | ||
list.append(item1); | ||
list.tail === null; //=> true, see note. | ||
list.append(item1) | ||
list.tail === null // => true, see note. | ||
list.append(item2); | ||
list.tail === item2; //=> true | ||
list.append(item2) | ||
list.tail === item2 // => true | ||
``` | ||
@@ -195,3 +195,3 @@ | ||
```javascript | ||
var item = new LinkedList.Item(); | ||
var item = new LinkedList.Item() | ||
``` | ||
@@ -204,11 +204,11 @@ | ||
```javascript | ||
var item1 = new LinkedList.Item(); | ||
var item2 = new LinkedList.Item(); | ||
var item1 = new LinkedList.Item() | ||
var item2 = new LinkedList.Item() | ||
(new LinkedList()).append(item1); | ||
new LinkedList().append(item1) | ||
item1.next === null; //=> true | ||
item1.next === null // => true | ||
item1.append(item2); | ||
item1.next === item2; //=> true | ||
item1.append(item2) | ||
item1.next === item2 // => true | ||
``` | ||
@@ -224,11 +224,11 @@ | ||
```javascript | ||
var item1 = new LinkedList.Item(); | ||
var item2 = new LinkedList.Item(); | ||
var item1 = new LinkedList.Item() | ||
var item2 = new LinkedList.Item() | ||
(new LinkedList()).append(item1); | ||
new LinkedList().append(item1) | ||
item1.prev === null; //=> true | ||
item1.prev === null // => true | ||
item1.prepend(item2); | ||
item1.prev === item2; //=> true | ||
item1.prepend(item2) | ||
item1.prev === item2 // => true | ||
``` | ||
@@ -244,9 +244,9 @@ | ||
```javascript | ||
var item = new LinkedList.Item(); | ||
var list = new LinkedList(item); | ||
var item = new LinkedList.Item() | ||
var list = new LinkedList(item) | ||
item.list === list; //=> true | ||
item.list === list // => true | ||
item.detach(); | ||
item.list === null; //=> true | ||
item.detach() | ||
item.list === null // => true | ||
``` | ||
@@ -261,17 +261,17 @@ | ||
```javascript | ||
var item1 = new LinkedList.Item(); | ||
var item2 = new LinkedList.Item(); | ||
var item1 = new LinkedList.Item() | ||
var item2 = new LinkedList.Item() | ||
new LinkedList(item1); | ||
new LinkedList(item1) | ||
item1.next === null; //=> true | ||
item2.next === null; //=> true | ||
item1.next === null // => true | ||
item2.next === null // => true | ||
item1.append(item2); | ||
item1.append(item2) | ||
item1.next === item2; //=> true | ||
item1.next === item2 // => true | ||
item1.detach(); | ||
item1.detach() | ||
item1.next === null; //=> true | ||
item1.next === null // => true | ||
``` | ||
@@ -284,17 +284,17 @@ | ||
```javascript | ||
var item1 = new LinkedList.Item(); | ||
var item2 = new LinkedList.Item(); | ||
var item1 = new LinkedList.Item() | ||
var item2 = new LinkedList.Item() | ||
new LinkedList(item); | ||
new LinkedList(item) | ||
item1.prev === null; //=> true | ||
item2.prev === null; //=> true | ||
item1.prev === null // => true | ||
item2.prev === null // => true | ||
item1.append(item2); | ||
item1.append(item2) | ||
item1.prev === item1; //=> true | ||
item1.prev === item1 // => true | ||
item2.detach(); | ||
item2.detach() | ||
item2.prev === null; //=> true | ||
item2.prev === null // => true | ||
``` | ||
@@ -307,14 +307,14 @@ | ||
```javascript | ||
var item = new LinkedList.Item(); | ||
var list = new LinkedList(); | ||
var item = new LinkedList.Item() | ||
var list = new LinkedList() | ||
item.list === null; //=> true | ||
item.list === null // => true | ||
list.append(item); | ||
list.append(item) | ||
item.list === list; //=> true | ||
item.list === list // => true | ||
item.detach(); | ||
item.detach() | ||
item.list === null; //=> true | ||
item.list === null // => true | ||
``` | ||
@@ -321,0 +321,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15524
0