{"name":"linked-list","version":"0.1.0","description":"Minimalistic linked lists","license":"MIT","keywords":["linked","list"],"repository":{"type":"git","url":"https://github.com/wooorm/linked-list.git"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com"},"devDependencies":{"eslint":"^0.9.0","istanbul":"^0.3.0","jscs":"^1.0.0","jshint":"^2.0.0","mocha":"^2.0.0","uglify-js":"^2.0.0"},"scripts":{"test":"_mocha --reporter spec --check-leaks -u exports test.js","test-travis":"istanbul cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --check-leaks -u exports test.js","coverage":"istanbul cover node_modules/.bin/_mocha -- -- test.js","lint-api":"eslint index.js _source/linked-list.js","lint-test":"eslint test.js --env mocha","lint-style":"jscs index.js _source/linked-list.js test.js --reporter=inline","lint":"npm run lint-api && npm run lint-test && npm run lint-style"},"gitHead":"6a25ce442a34f06c9df2b671e601a4d6855840d2","bugs":{"url":"https://github.com/wooorm/linked-list/issues"},"homepage":"https://github.com/wooorm/linked-list","_id":"linked-list@0.1.0","_shasum":"798b0ff97d1b92a4fd08480f55aea4e9d49d37bf","_from":".","_npmVersion":"2.0.0","_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"dist":{"shasum":"798b0ff97d1b92a4fd08480f55aea4e9d49d37bf","tarball":"http://registry-npm.ywwl.com/linked-list/download/linked-list-0.1.0.tgz","integrity":"sha512-Zr4ovrd0ODzF3ut2TWZMdHIxb8iFdJc/P3QM4iCJdlxxGHXo69c9hGIHzLo8/FtuR9E6WUZc5irKhtPUgOKMAg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFRhktrDQgHTGOHuo0U2sjSZ0/IkMMiGYZJahXz1b6zqAiBQ9BEdduyaFOtOEzeWyxGWO4hFE2AS4kZ2goxMuSghxQ=="}],"size":5468,"noattachment":false,"key":"/linked-list/-/linked-list-0.1.0.tgz"},"directories":{},"readme":"# linked-list\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n\nSmall double [linked list][wiki].\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`List([items…])`](#listitems)\n    *   [`Item()`](#item)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a small double linked list.\nItems in linked lists know about their next sibling (the item after them).\nIn double linked lists, items also know about their previous sibling (the item\nbefore them).\n\n## When should I use this?\n\nYou can use this project as a reference for how to implement a linked list but\nit’s also definitely possible to use it, directly or by subclassing its lists\nand items.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 14.14+, 16.0+), install with [npm][]:\n\n```sh\nnpm install linked-list\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {List, Item} from 'https://esm.sh/linked-list@3'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {List, Item} from 'https://esm.sh/linked-list@3?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport {List, Item} from 'linked-list'\n\nconst item1 = new Item()\nconst item2 = new Item()\nconst item3 = new Item()\nconst list = new List(item1, item2, item3)\n\nlist.head // => item1\nlist.head.next // => item2\nlist.head.next.next // => item3\nlist.head.next.prev // => item1\nlist.tail // => item3\nlist.tail.next // => `null`\n```\n\nSubclassing:\n\n```js\nimport {List, Item} from 'linked-list'\n\nclass Tokens extends List {\n  /** @param {string} delimiter */\n  join(delimiter) {\n    return this.toArray().join(delimiter)\n  }\n}\n\nclass Token extends Item {\n  /** @param {string} value */\n  constructor(value) {\n    super()\n    this.value = value\n  }\n\n  toString() {\n    return this.value\n  }\n}\n\nconst dogs = new Token('dogs')\nconst and = new Token('&')\nconst cats = new Token('cats')\nconst tokens = new Tokens(dogs, and, cats)\n\nconsole.log(tokens.join(' ')) // => 'dogs & cats'\n\nand.prepend(cats)\nand.append(dogs)\n\nconsole.log(tokens.join(' ') + '!') // => 'cats & dogs!'\n```\n\n## API\n\nThis package exports the identifiers `List` and `Item`.\nThere is no default export.\n\n### `List([items…])`\n\n```js\nnew List()\nnew List(new Item(), new Item())\n```\n\nCreate a new list from the given items.\n\nIgnores `null` or `undefined` values.\nThrows an error when a given item has no `detach`, `append`, or `prepend`\nmethods.\n\n#### `List.from([items])`\n\n```js\nList.from()\nList.from([])\nList.from([new Item(), new Item()])\n```\n\nCreate a new `this` from the given array of items.\n\nIgnores `null` or `undefined` values.\nThrows an error when a given item has no `detach`, `append`, or `prepend`\nmethods.\n\n#### `List.of([items…])`\n\n```js\nList.of()\nList.of(new Item(), new Item())\n```\n\nCreate a new `this` from the given arguments.\n\nIgnores `null` or `undefined` values.\nThrows an error when a given item has no `detach`, `append`, or `prepend`\nmethods.\n\n#### `List#append(item)`\n\n```js\nconst list = new List()\nconst item = new Item()\n\nconsole.log(list.head === null) // => true\nconsole.log(item.list === null) // => true\n\nlist.append(item)\n\nconsole.log(list.head === item) // => true\nconsole.log(item.list === list) // => true\n```\n\nAppend an item to a list.\n\nThrows an error when the given item has no `detach`, `append`, or `prepend`\nmethods.\nReturns the given item.\n\n#### `List#prepend(item)`\n\n```js\nconst list = new List()\nconst item = new Item()\n\nlist.prepend(item)\n```\n\nPrepend an item to a list.\n\nThrows an error when the given item has no `detach`, `append`, or `prepend`\nmethods.\nReturns the given item.\n\n#### `List#toArray()`\n\n```js\nconst item1 = new Item()\nconst item2 = new Item()\nconst list = new List(item1, item2)\nconst array = list.toArray()\n\nconsole.log(array[0] === item1) // => true\nconsole.log(array[1] === item2) // => true\nconsole.log(array[0].next === item2) // => true\nconsole.log(array[1].prev === item1) // => true\n```\n\nReturns the items of the list as an array.\n\nThis does *not* detach the items.\n\n> **Note**: `List` also implements an iterator.\n> That means you can also do `[...list]` to get an array.\n\n#### `List#head`\n\n```js\nconst item = new Item()\nconst list = new List(item)\n\nconsole.log(list.head === item) // => true\n```\n\nThe first item in a list or `null` otherwise.\n\n#### `List#tail`\n\n```js\nconst list = new List()\nconst item1 = new Item()\nconst item2 = new Item()\n\nconsole.log(list.tail === null) // => true\n\nlist.append(item1)\nconsole.log(list.tail === null) // => true, see note.\n\nlist.append(item2)\nconsole.log(list.tail === item2) // => true\n```\n\nThe last item in a list and `null` otherwise.\n\n> 👉 **Note**: a list with only one item has **no tail**, only a head.\n\n#### `List#size`\n\n```js\nconst list = new List()\nconst item1 = new Item()\nconst item2 = new Item()\n\nconsole.log(list.size === 0) // => true\n\nlist.append(item1)\nconsole.log(list.size === 1) // => true\n\nlist.append(item2)\nconsole.log(list.size === 2) // => true\n```\n\nThe number of items in the list.\n\n### `Item()`\n\n```js\nconst item = new Item()\n```\n\nCreate a new linked list item.\n\n#### `Item#append(item)`\n\n```js\nconst item1 = new Item()\nconst item2 = new Item()\n\nnew List().append(item1)\n\nconsole.log(item1.next === null) // => true\n\nitem1.append(item2)\nconsole.log(item1.next === item2) // => true\n```\n\nAdd the given item **after** the operated on item in a list.\n\nThrows an error when the given item has no `detach`, `append`, or `prepend`\nmethods.\nReturns `false` when the operated on item is not attached to a list, otherwise\nthe given item.\n\n#### `Item#prepend(item)`\n\n```js\nconst item1 = new Item()\nconst item2 = new Item()\n\nnew List().append(item1)\n\nconsole.log(item1.prev === null) // => true\n\nitem1.prepend(item2)\nconsole.log(item1.prev === item2) // => true\n```\n\nAdd the given item **before** the operated on item in a list.\n\nThrows an error when the given item has no `detach`, `append`, or `prepend`\nmethods.\nReturns `false` when the operated on item is not attached to a list, otherwise\nthe given item.\n\n#### `Item#detach()`\n\n```js\nconst item = new Item()\nconst list = new List(item)\n\nconsole.log(item.list === list) // => true\n\nitem.detach()\nconsole.log(item.list === null) // => true\n```\n\nRemove the operated on item from its parent list.\n\nRemoves references to it on its parent `list`, and `prev` and `next` items.\nRelinks all references.\nReturns the operated on item.\nEven when it was already detached.\n\n#### `Item#next`\n\n```js\nconst item1 = new Item()\nconst item2 = new Item()\n\nconst list = new List(item1)\n\nconsole.log(item1.next === null) // => true\nconsole.log(item2.next === null) // => true\n\nitem1.append(item2)\n\nconsole.log(item1.next === item2) // => true\n\nitem1.detach()\n\nconsole.log(item1.next === null) // => true\n```\n\nThe following item or `null` otherwise.\n\n#### `Item#prev`\n\n```js\nconst item1 = new Item()\nconst item2 = new Item()\n\nconst list = new List(item1)\n\nconsole.log(item1.prev === null) // => true\nconsole.log(item2.prev === null) // => true\n\nitem1.append(item2)\n\nconsole.log(item2.prev === item1) // => true\n\nitem2.detach()\n\nconsole.log(item2.prev === null) // => true\n```\n\nThe preceding item or `null` otherwise.\n\n#### `Item#list`\n\n```js\nconst item = new Item()\nconst list = new List()\n\nconsole.log(item.list === null) // => true\n\nlist.append(item)\n\nconsole.log(item.list === list) // => true\n\nitem.detach()\n\nconsole.log(item.list === null) // => true\n```\n\nThe list this item belongs to or `null` otherwise.\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports no additional types.\n\n## Compatibility\n\nThis package is at least compatible with all maintained versions of Node.js.\nAs of now, that is Node.js 14.14+ and 16.0+.\nIt also works in Deno and modern browsers.\n\n## Security\n\nThis package is safe.\n\n## Contribute\n\nYes please!\nSee [How to Contribute to Open Source][contribute].\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/wooorm/linked-list/workflows/main/badge.svg\n\n[build]: https://github.com/wooorm/linked-list/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/linked-list.svg\n\n[coverage]: https://codecov.io/github/wooorm/linked-list\n\n[downloads-badge]: https://img.shields.io/npm/dm/linked-list.svg\n\n[downloads]: https://www.npmjs.com/package/linked-list\n\n[size-badge]: https://img.shields.io/bundlephobia/minzip/linked-list.svg\n\n[size]: https://bundlephobia.com/result?p=linked-list\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esmsh]: https://esm.sh\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[typescript]: https://www.typescriptlang.org\n\n[contribute]: https://opensource.guide/how-to-contribute/\n\n[wiki]: https://wikipedia.org/wiki/Linked_list\n","publish_time":1417039111049,"_cnpm_publish_time":1417039111049,"dist-tags":{"latest":"3.1.0"}}