{"name":"linked-list","version":"2.0.0","description":"Minimalistic linked lists","types":"index.d.ts","license":"MIT","keywords":["double","linked","list"],"repository":{"type":"git","url":"git+https://github.com/wooorm/linked-list.git"},"bugs":{"url":"https://github.com/wooorm/linked-list/issues"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"wooorm.com"},{"name":"Blake Embrey","email":"hello@blakeembrey.com"}],"dependencies":{},"devDependencies":{"browserify":"^16.0.0","nyc":"^13.0.0","prettier":"^1.12.1","remark-cli":"^6.0.0","remark-preset-wooorm":"^4.0.0","tape":"^4.6.2","tinyify":"^2.4.3","xo":"^0.24.0"},"scripts":{"format":"remark . -qfo && prettier --write \"**/*.js\" && xo --fix","build-bundle":"browserify . -s LinkedList -o linked-list.js","build-mangle":"browserify . -s LinkedList -p tinyify -o linked-list.min.js","build":"npm run build-bundle && npm run build-mangle","test-api":"node test","test-coverage":"nyc --reporter lcov tape test.js","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":{"prettier":true,"esnext":false,"rules":{"no-var":"off","prefer-arrow-callback":"off","no-multi-assign":"off","unicorn/prefer-spread":"off"},"ignores":["linked-list.js"]},"remarkConfig":{"plugins":["preset-wooorm"]},"nyc":{"check-coverage":true,"lines":100,"functions":100,"branches":100},"gitHead":"87d2ff0f2f730eede721010c4bca5ca825737be2","homepage":"https://github.com/wooorm/linked-list#readme","_id":"linked-list@2.0.0","_nodeVersion":"11.9.0","_npmVersion":"6.8.0","dist":{"integrity":"sha512-eri1JlEfnTF8CfRS37NO73Ri3NnBN9n2bTtDnYh//+sAy+JNxvTaC0RMvBkXEZtYOBeo3u5a7dPCysbaW/41Ug==","shasum":"eca5e87c46bf4a18db5bd2f4949c10659353833c","tarball":"http://registry-npm.ywwl.com/linked-list/download/linked-list-2.0.0.tgz","fileCount":5,"unpackedSize":17227,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcht2bCRA9TVsSAnZWagAAwM4P/01COUMnd25rrmeNau6r\n8GvPXz2OsbOjN1iMbFv/AuD9RAamxnemrYjLHVsQA1X17T0SOCpDfWK39Y9p\nhuB1QJskjz3fZG6l4324zMOVV9WbVs5o5Dtv0T2DlfFYYB+b/TlfLsa+jCGj\nDwDRRqyqGp0kBOP3CEtHpVVtUPeVdxlfa52pPUuHydWpsQvw+3V8RrIR/TcC\nM4JhxA3gMG8L6IptbRhWoCTShKkIr70/L+PcAaPu2gDmrWgF2A59VDWHXN1Q\nUCD/6QrKM6lBmnBnR+lTHmREIjBgk85X3VdV4dQW43rsJdtaGAlmpG/P/hzH\nVQN6ctJfeRH88EVbH/yguch/Djm1v6Osv5vtly4yzCOq1j0i4XCPnMA8zd8V\n/kpW4OENlmXgHEvd81LKQpfRk2ojDQorlaI12Yg6LJsiiZQqxo2fhhkZAFZN\nqz0nUS3wBzxxJ4/hAnbx9HY/Sc1REZ7SklxzmFpSCPQPYFCVlxXyGESiKnnA\nVCjuBZYlnow8eFF8fZWk3coNJMBKBgkEPgLO2NlrZUr2g4wuFZ7A2UIrZjM4\nsDNIcTEnixNCWVsllfty093SxP7mcBLnK5sWbfFeJ2ZK35D0xCwD6SVIPdf6\nJCfsl0YF3Y1GPKeitqEMcYef+F6c7CVrgRd5xNYKcTbhz49zxMoSOtkAmnyG\nNEMC\r\n=O82m\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCRi5xHIzCskQEiaxkSz2HdgrtQWjYl4Qj/tOx0wcbkngIgKgi3rdcHU3csWSK2NVm9Z8n2Ca3X40L9T4hn4//4X/c="}],"size":5174,"noattachment":false,"key":"/linked-list/-/linked-list-2.0.0.tgz"},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/linked-list_2.0.0_1552342427237_0.524758770198134"},"_hasShrinkwrap":false,"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":1552342427366,"_cnpm_publish_time":1552342427366,"dist-tags":{"latest":"3.1.0"}}