{"name":"linkedlist-js","version":"1.1.0","description":"A Doubly Linked List Implementation in Javascript","main":"index.js","scripts":{"test":"mocha tests"},"repository":{"type":"git","url":"git+https://github.com/Hedronium/LinkedList.js.git"},"keywords":["doubly","linked","list","data","structure"],"author":{"name":"Omran Jamal","email":"o.jamal97@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/Hedronium/LinkedList.js/issues"},"homepage":"https://github.com/Hedronium/LinkedList.js#readme","devDependencies":{"chai":"^3.4.1","mocha":"^2.3.4"},"gitHead":"a1c9195e1f3067ae95e71453fcddbc88053e8f9b","_id":"linkedlist-js@1.1.0","_shasum":"34126d60bc92c037015b7c24e0631dd4f5229000","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"omranjamal","email":"o.jamal97@gmail.com"},"dist":{"shasum":"34126d60bc92c037015b7c24e0631dd4f5229000","tarball":"http://registry-npm.ywwl.com/linkedlist-js/download/linkedlist-js-1.1.0.tgz","integrity":"sha512-zgkYkRfwOLGRWdq/wGoiQgGVkqMjsYxDzyiBvmONEAzuwZSu9u1a01VfJifPbdZ/HHJe8UyE4KnayssLxBUKEQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAp1DezY8FTxH07QNv4g7qkvJmwSetlJ+MDD3JuMKhrGAiA0nXTyZalVsPlp2rT83EHE1GmbajKWCvMSYNaazp4x+A=="}],"size":2685,"noattachment":false,"key":"/linkedlist-js/-/linkedlist-js-1.1.0.tgz"},"maintainers":[{"name":"omranjamal","email":"o.jamal97@gmail.com"}],"directories":{},"readme":"#LinkedList.js\r\nA simple doubly linked list implementation in Javascript.\r\n\r\n## Installation\r\n```\r\nnpm install linkedlist-js\r\n```\r\n\r\n## Usage\r\nrequire the module...\r\n\r\n```javascript\r\nvar List = require('linkedlist-js').List;\r\n```\r\n\r\ninstantiate a List object...\r\n```javascript\r\nvar list = new List();\r\n\r\n// PUSH!\r\nlist.push('HUEHUE');\r\n```\r\n\r\n### Traversing the List\r\n#### with each(callback)\r\n```javascript\r\nlist.each(function (index, node) {\r\n    console.log(index + ': ' + node.value());\r\n});\r\n```\r\n\r\n#### like a badass\r\n```javascript\r\nvar node = list.head();\r\n\r\nwhile (node != null) {\r\n    console.log(node.value());\r\n    node = node.next();\r\n}\r\n```\r\n\r\n\r\n## `List` API\r\n### Adding Nodes\r\n#### push(value)\r\nCreates a node with the value specified, adds it to the end of the list and returns the `Node` object.\r\n\r\n```javascript\r\nvar a = list.push('A');\r\na.value(); //'A'\r\n```\r\n\r\n#### unshift(value)\r\nCreates a node with the value specified, adds it to the beginning of the list and returns the `Node` object.\r\n\r\n```javascript\r\nvar b = list.unshift('B');\r\nb.value(); //'B'\r\n```\r\n\r\n### Accessing Nodes\r\n#### pop\r\nReturns the tail `Node` and removes it from the list.\r\n```\r\nvar list = new List();\r\nlist.push('A');\r\nlist.push('B');\r\n\r\nlist.pop().value(); //'B'\r\n```\r\n\r\n#### shift\r\nReturns the head `Node` and removes it from the list.\r\n```\r\nvar list = new List();\r\nlist.push('A');\r\nlist.push('B');\r\n\r\nlist.shift().value(); //'A'\r\n```\r\n\r\n#### get(index)\r\nReturns the `Node` at the specified index. _(Linear Lookup, not very performant)_\r\n```javascript\r\nvar list = new List();\r\nlist.push('A');\r\nlist.push('B');\r\nlist.push('C');\r\n\r\nlist.get(1).value(); //'B'\r\n```\r\n\r\n### Peeking\r\n#### head()\r\nReturns the head `Node` or `null` in list is empty\r\n```javascript\r\nvar list = new List();\r\nvar node_a = list.push('A');\r\nvar node_b = list.push('B');\r\n\r\nlist.head() === node_a; // true\r\n```\r\n\r\n#### tail()\r\nReturns the tail `Node` or `null` in list is empty\r\n```javascript\r\nvar list = new List();\r\nvar node_a = list.push('A');\r\nvar node_b = list.push('B');\r\n\r\nlist.tail() === node_b; // true\r\n```\r\n\r\n### Searching\r\n#### find(value)\r\nFind the node with the specified value and returns it. _(Linear search, not very performant)_\r\n```javascript\r\nvar list = new List();\r\nlist.push('A');\r\nvar node_b = list.push('B');\r\n\r\nlist.find('B') === node_b; // true\r\n```\r\n\r\n### Misc\r\n#### set(index, value)\r\nSets the value of the `Node` at the specifiec index.\r\n```javascript\r\nvar list = new List();\r\nlist.push('A');\r\n\r\nlist.set(0, 'B');\r\nlist.head().value(); // 'B'\r\n```\r\n\r\n#### count()\r\nReturns the number of `Node`s in the list.\r\n```javascript\r\nvar list = new List();\r\nlist.push('A');\r\nlist.push('B');\r\n\r\nlist.count(); // 2\r\n```\r\n\r\n#### isEmpty()\r\nReturns `true` if list has no `Node`s and `false` if otherwise.\r\n```javascript\r\nvar list = new List();\r\nlist.isEmpty(); // true\r\n\r\nlist.push('A');\r\nlist.isEmpty(); // false\r\n```\r\n\r\n#### truncateTo(length)\r\nTruncates the list to the specified size.\r\n```\r\nvar list = new List();\r\nlist.push('A');\r\nlist.push('B');\r\n\r\nlist.truncateTo(1);\r\nlist.count(); // 1\r\n```\r\n\r\n#### empty()\r\nSame as calling `truncateTo(0)`. Empties the list.\r\n```\r\nvar list = new List();\r\nlist.push('A');\r\nlist.push('B');\r\n\r\nlist.empty();\r\n\r\nlist.count();   // 0\r\nlist.isEmpty(); // true\r\n```\r\n\r\n\r\n### asArray()\r\nReturns the list as an Array.\r\n```javascript\r\nvar list = new List();\r\nlist.push('A');\r\nlist.push('B');\r\n\r\nlist.asArray(); // ['A', 'B']\r\n```\r\n\r\n\r\n## `Node` API\r\n### Getters\r\n#### value()\r\nReturns the value of the `Node`\r\n\r\n#### previous()\r\nReturns the previous `Node` in the list of `null` if the node is the forst `Node`.\r\n\r\n#### next()\r\nReturns the next `Node` in the list of `null` if the node is the last `Node`.\r\n\r\n### Setters\r\n#### set(value)\r\nSets the value of the node\r\n```\r\nvar node = new Node();\r\nnode.set('A');\r\n\r\nnode.value(); // 'A'\r\n```\r\n\r\n#### setPrevious(`Node` node)\r\nSets the previous pointer of the `Node`\r\n```\r\nvar node_a = new Node();\r\nvar node_b = new Node();\r\nnode_b.setPrevious(node_a);\r\n\r\nnode_b.previous() === node_a; // true\r\n```\r\n\r\n#### setNext(`Node` node)\r\nSets the next pointer of the `Node`\r\n```\r\nvar node_a = new Node();\r\nvar node_b = new Node();\r\nnode_a.setNext(node_b);\r\n\r\nnode_a.next() === node_b; // true\r\n```\r\n\r\n### Misc\r\n#### isHead()\r\nRetunrs true if the node is the first node in the list.\r\n```javascript\r\nvar list = new List();\r\nlist.push('A');\r\nlist.push('B');\r\n\r\nlist.head().isHead(); // true\r\n```\r\n\r\n#### isTail()\r\nRetunrs true if the node is the last node in the list.\r\n```javascript\r\nvar list = new List();\r\nlist.push('A');\r\nlist.push('B');\r\n\r\nlist.tail().isTail(); // true\r\n```\r\n\r\n## Running Tests\r\n```\r\nnpm test\r\n```\r\n\r\nif you have mocha installed, you may also run\r\n```\r\nmocha tests\r\n```","publish_time":1452107494153,"_cnpm_publish_time":1452107494153,"dist-tags":{"latest":"1.3.0"}}