{"name":"linked-list","version":"3.0.2","description":"Minimalistic linked lists","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"},"funding":{"type":"github","url":"https://github.com/sponsors/wooorm"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},{"name":"Blake Embrey","email":"hello@blakeembrey.com"},{"name":"Regev Brody","email":"regevbr@gmail.com"}],"sideEffects":false,"type":"module","main":"index.js","types":"index.d.ts","devDependencies":{"@types/tape":"^4.0.0","c8":"^7.0.0","prettier":"^2.0.0","remark-cli":"^10.0.0","remark-preset-wooorm":"^9.0.0","tape":"^5.0.0","xo":"^0.47.0"},"scripts":{"format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node test.js","test-coverage":"c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js","test":"npm run format && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true,"rules":{"no-var":"off","prefer-arrow-callback":"off","no-multi-assign":"off"},"ignores":["*.ts","linked-list.js"]},"remarkConfig":{"plugins":["preset-wooorm"]},"gitHead":"4cdb18e03a9744d20a23434eff5b1f387b25a48f","homepage":"https://github.com/wooorm/linked-list#readme","_id":"linked-list@3.0.2","_nodeVersion":"17.4.0","_npmVersion":"8.3.1","dist":{"integrity":"sha512-iNPWgv6vL8tCTZtnlYfGAQbw08Q/QWfSocUj9LAaOdz9gn7mYMp/5iFEnHsKu6kUUMhCqykenwDaSaAbIBBMtA==","shasum":"a71c4b6e068a41ba2d3fe85ef13aaddbd882d199","tarball":"http://registry-npm.ywwl.com/linked-list/download/linked-list-3.0.2.tgz","fileCount":5,"unpackedSize":18297,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh/QDLCRA9TVsSAnZWagAAg68QAI3Jt6JyE87yxaxVl5wd\ncKCPnTjpImweAeefhxDDVsY/0p0hg7CgjKsnmdZp44u3ayIzR1BmeEQKPLjB\nR4Lc1QKd/Iia5Nls+MMdOgiHqoM+bwyBHJmx7WW5IlvZuUwiqEhm4qYs0iGH\nJj/Y5WiHH2j4pGmeX6oNQzFPXEJMvDTvvSU7ZcXz47E2gSznrQ1g+UzCRBcg\n/P7jkNPJQu3TIlpa8cN2lLilCuaOLDYcPBa/eHsGDr30HvMQwSTC2Sn0WmJ+\nulR7RfTCluuuXbyu3TC6+kAE5V3PXjKandLGlILv1+bhE0R77yBUuD4+y+xS\nKn7ueSvuSFo5OG1Cr3ivkLgdOQAOj7yOvd5ZK4eb3016OUs8llWuDBmp5L4m\nGqlSVviJ/+bW1ccX2y3VybA4sdizBieHUWR7IVqI1XGgM/8I7LxPJGIlE5lu\ne/KdOe+AueQg3m4YyKqKqaIyBEosA4LhYHGpc1oH7GUgBsoC4Ip+iSuB8k/N\n/dKAHX3VXQpSx5OqwgOz1u6AV3+d4wb+qmpdsFsahgWYsqFzr/aLgyiK1vie\nhxp/UidAyDE72pfjiZLRBKOLN6VrkyUaQHGHDogauBh3IU3iaKESKu2WJHgB\nbO5eH7oJRjigSk5tWEVNawT6fC2DVVrEGq7WSFJVuNNQc+o6Tzx39Y9qG69Y\nddDV\r\n=Yl6e\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID+tXrOpR6+tYXt5VnR4pJ5SSXlmIc7dBPIvDtsd2YY4AiB/3Wtx0UL/PuYkERYesG56mKOKDkfqSa4L29pi0v9Cmw=="}],"size":5638,"noattachment":false,"key":"/linked-list/-/linked-list-3.0.2.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/linked-list_3.0.2_1643970763132_0.7136530928027924"},"_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":1643970763269,"_cnpm_publish_time":1643970763269,"dist-tags":{"latest":"3.1.0"}}