{"name":"linked-list","version":"2.1.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","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"}],"dependencies":{},"devDependencies":{"browserify":"^16.0.0","nyc":"^14.0.0","prettier":"^1.0.0","remark-cli":"^6.0.0","remark-preset-wooorm":"^5.0.0","tape":"^4.0.0","tinyify":"^2.0.0","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-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":"55479165cb1cfc54c67ad115555905d1bccf5b79","homepage":"https://github.com/wooorm/linked-list#readme","_id":"linked-list@2.1.0","_nodeVersion":"12.2.0","_npmVersion":"6.10.1","dist":{"integrity":"sha512-0GK/ylO6e5cv1PCOIdTRHxOaCgQ+0jKwHt+cHzkiCAZlx0KM5Id1bBAPad6g2mkvBNp1pNdmG0cohFGfqjkv9A==","shasum":"fa7b63a6caf4b17862a1eb90d14ead4ee57649f2","tarball":"http://registry-npm.ywwl.com/linked-list/download/linked-list-2.1.0.tgz","fileCount":5,"unpackedSize":17632,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdL0pyCRA9TVsSAnZWagAATn0QAJofS+MvFV4LveDJazvi\nbLcH1Q9IJZOb/9QCNYv3LA+9b+6Ri5u0728SYrjTl+0DPrWuGf5ZQhj0jHHY\nsYwloyuFapBY77pqWSayJA+WhiGWt3v5FLWAkTFddv6e4Td5pNOCFg7I66EB\nJSCRZWkQLne4BHrU/UOXN3EpX+QlDsLwZ+Q7yeTpw/pjGKKBAh7+wlQAGNew\nBaHwmgOJq9auUgLYU1ddzHKeI/C8VTAShVxqU4ZtYBZRtntNswdKH+FUtrhE\n5qnizVmarZQVMwDhhg+u+cnvQdofa7S/QzHH8/uIXKdcVwSYh4FnxH6eqdd3\nvLfTh8O+KAzTI4CSvopifpkLhZsM4dDbDtq63iwNHsV00iuenmq9p89VWMAq\nAr8Ho/m3kP3qkPeCbODy64Q2Dfz2jdbM7yLhPgnWijOguIY50PwEEGSDKskk\nqd8HqNYxFDhmV2SwIHZTEaeLFkWjvPakI/wK6/ZI7SJ2pP/lpQboPctg5lgI\nVmTYGb7uREdJb89WadZg4uDFYycIUb+AFzAIybTNgnEsfixsw15aSvB5Qcgx\noVauOPls0CV8FSrgj1wURgO9p6PjgxvDGH7cCM1a1JQYlrr+yxN+RMP2T0+p\nEhaWGVjVME8F8zxKNeYbyvV/lR8V0/QgABZdeTNaHtU1O+U0m3fw+4uhfvER\n5t38\r\n=ZdGx\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDpeCxSm5yg+a6FdSL15xFHBo4uwBzESbxn7aUOhaN6lQIhANUPgil0+Ro1MvK8BKTdurlwQG9iRLJpIi7jvCjC1Web"}],"size":5258,"noattachment":false,"key":"/linked-list/-/linked-list-2.1.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.1.0_1563380337917_0.5600503608853025"},"_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":1563380338086,"_cnpm_publish_time":1563380338086,"dist-tags":{"latest":"3.1.0"}}