Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
linked-list
Advanced tools
linked-list provides minimalistic linked lists in JavaScript. No dependencies. NodeJS, AMD, browser. Lots of tests (70+). 653 Bytes minified and gzipped.
var item = new LinkedList.Item(),
item_ = new LinkedList.Item(),
item__ = new LinkedList.Item(),
list = new LinkedList(item, item_, item__);
list.head // => item
list.head.next // => item_
list.head.next.next // => item__
list.head.next.prev // => item
list.tail // => item__
list.tail.next // => `null`
var extend = require( 'some-extending-method...' ), // e.g. assimilate.
List = require( 'linked-list' ),
Item = List.Item;
function Tokens() {
List.apply(this, arguments);
};
function Token(value) {
this.value = value;
};
extend(Tokens.prototype, List.prototype, {
'join' : function(delimeter){
return this.toArray().join(delimeter);
}
});
extend(Token.prototype, Item.prototype, {
'toString' : function(){
return this.value;
}
});
var dogs = new Token('dogs'),
and = new Token('&'),
cats = new Token('cats'),
tokens = new Tokens(dogs, and, cats);
tokens.join(' '); // "dogs & cats"
and.prepend(cats);
and.append(dogs);
tokens.join(' ') + '!'; // "cats & dogs!"
$ npm install linked-list
git clone https://github.com/wooorm/linked-list.git
cd linked-list
npm install
make && make build
component install wooorm/linked-list
bower install linked-list
Download the latest minified CommonJS release and add it to your project.
Learn more about CommonJS modules.
Download the latest minified AMD release and add it to your project.
Download the latest minified standalone release and add it to your project.
<script src="/your/js/path/linked-list.globals.js"></script>
This makes the LinkedList
module available in the global namespace (window
in the browser).
var list = new LinkedList();
Creates a new Linked List.
var list = LinkedList.from(),
list_ = LinkedList.from([]),
list__ = LinkedList.from([new LinkedList.Item()]);
Creates a new Linked List* from the given array of items. Ignores null
or undefined
values. Throws an error when a given item has no detach
, append
, or prepend
methods.
Token
(Token.from
), it would create a new instance of Token.var list = LinkedList.of(),
list_ = LinkedList.of(new LinkedList.Item());
Creates a new Linked List from the given arguments. Defers to LinkedList.from
(see above). As in:
List.of = function (/*items...*/) {
return List.from.call(this, arguments);
};
var list = new LinkedList(),
item = new LinkedList.Item();
list.head === null // true
item.list === null // true
list.append(item);
list.head === item // true
item.list === list // true
Appends an item to a list. Throws an error when the given item has no detach
, append
, or prepend
methods. Returns the given item.
var list = new LinkedList(),
item = new LinkedList.Item();
list.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.
var item = new LinkedList.Item(),
item_ = new LinkedList.Item(),
list = new LinkedList(item, item_),
array = list.toArray();
array[0] === item // true
array[1] === item_ // true
array[0].next === item_ // true
array[1].prev === item // true
Returns the items in the list in an array.
var item = new LinkedList.Item(),
list = new LinkedList(item);
list.head === item; // true
The first item in a list, and null
otherwise.
var list = new LinkedList(),
item = new LinkedList.Item(),
item_ = new LinkedList.Item();
list.tail === null; // true
list.append(item);
list.tail === null; // true, see note.
list.append(item_);
list.tail === item_; // true
The last item in a list, and null
otherwise. Note that a list with only one item has no tail, only a head.
var item = new LinkedList.Item();
Creates a new Linked List Item.
var item = new LinkedList.Item(),
item_ = new LinkedList.Item();
(new LinkedList()).append(item);
item.next === null // true
item.append(item_);
item.next === item_ // true
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.
var item = new LinkedList.Item(),
item_ = new LinkedList.Item();
(new LinkedList()).append(item);
item.prev === null // true
item.prepend(item_);
item.prev === item_ // true
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 the given item.
var item = new LinkedList.Item(),
list = new LinkedList(item);
item.list === list // true
item.detach();
item.list === null // true
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.
var item = new LinkedList.Item(),
item_ = new LinkedList.Item();
new LinkedList(item);
item.next === null // true
item_.next === null // true
item.append(item_);
item.next === item_ // true
item.detach();
item.next === null // true
The items succeeding item, and null
otherwise.
var item = new LinkedList.Item(),
item_ = new LinkedList.Item();
new LinkedList(item);
item.prev === null // true
item_.prev === null // true
item.append(item_);
item_.prev === item // true
item_.detach();
item_.prev === null // true
The items preceding item, and null
otherwise.
var item = new LinkedList.Item(),
list = new LinkedList();
item.list === null // true
list.append(item);
item.list === list // true
item.detach();
item.list === null // true
The items parent list, and null
otherwise.
Run Mocha tests and JSHint
$ make
Build files (AMD, globals, and CommonJS)
$ make build
(The MIT License)
Copyright (c) 2014 Titus Wormer tituswormer@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Minimalistic linked lists
The npm package linked-list receives a total of 35,644 weekly downloads. As such, linked-list popularity was classified as popular.
We found that linked-list demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.