{"_id":"@000alen/toposort","_rev":"1-05290a9b391e932c134e84fa09149cb5","name":"@000alen/toposort","dist-tags":{"latest":"2.0.4"},"versions":{"2.0.3":{"name":"@000alen/toposort","version":"2.0.3","keywords":["topological","sort","sorting","graphs","graph","dependency","list","dependencies","acyclic"],"author":{"name":"Alen Rubilar","email":"lclc.alen@gmail.com"},"license":"MIT","_id":"@000alen/toposort@2.0.3","maintainers":[{"name":"000alen","email":"lclc.alen@gmail.com"}],"homepage":"https://github.com/000alen/toposort#readme","bugs":{"url":"https://github.com/000alen/toposort/issues"},"dist":{"shasum":"35547dc287d3ded32dbc60ab908138645fb7bb33","tarball":"https://registry.npmjs.org/@000alen/toposort/-/toposort-2.0.3.tgz","fileCount":11,"integrity":"sha512-PsiGxRxGgIC8radT/zCl9w6N0vtJdZlONNROHY9s4Sx45IzSvRnPPOlzuzTKCK71BCeyaQ39zmwELVgpvLG7pg==","signatures":[{"sig":"MEUCIEi5mRruZZGgB0YomkBYZ9TBxNzj4v1u/OlczfqF4nBJAiEAwHTSL8QtUNpKAL1RtboT2xcCVOXUrVTBbnmkj3gcSo0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19834},"main":"index.js","types":"index.d.ts","gitHead":"764116343f43c71dcc16aca1f77ea21a764d3962","scripts":{"test":"node test.js"},"_npmUser":{"name":"000alen","email":"lclc.alen@gmail.com"},"repository":{"url":"git+https://github.com/000alen/toposort.git","type":"git"},"_npmVersion":"10.9.0","description":"Topological sort of directed acyclic graphs (like dependency lists)","directories":{},"_nodeVersion":"20.12.2","_hasShrinkwrap":false,"packageManager":"yarn@4.5.1","devDependencies":{"vows":"0.7.x"},"_npmOperationalInternal":{"tmp":"tmp/toposort_2.0.3_1729395065553_0.30449537352315104","host":"s3://npm-registry-packages"}},"2.0.4":{"name":"@000alen/toposort","version":"2.0.4","description":"Topological sort of directed acyclic graphs (like dependency lists)","main":"index.js","types":"index.d.ts","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"git+https://github.com/000alen/toposort.git"},"devDependencies":{"vows":"0.7.x"},"keywords":["topological","sort","sorting","graphs","graph","dependency","list","dependencies","acyclic"],"author":{"name":"Alen Rubilar","email":"lclc.alen@gmail.com"},"license":"MIT","packageManager":"yarn@4.5.1","_id":"@000alen/toposort@2.0.4","gitHead":"8da657ba172d6b3ecfea6ebcd1250d467781769c","bugs":{"url":"https://github.com/000alen/toposort/issues"},"homepage":"https://github.com/000alen/toposort#readme","_nodeVersion":"20.12.2","_npmVersion":"10.9.0","dist":{"integrity":"sha512-1SZs2C6mRX86Y/djy9AulPZslXnSvVfX+ZVeQQ/M69c65jFRCJ5lHlGwPFI7/udDwLCi05MOXohEoOAcPu2/XA==","shasum":"da5657c847357a17dd59720c97408566d417f45a","tarball":"https://registry.npmjs.org/@000alen/toposort/-/toposort-2.0.4.tgz","fileCount":11,"unpackedSize":19834,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC/goy03jqI/L4iMtu09d3y0GQc1BbnCybOKSxxn3l2wAiEAkdzjOTiryBFoTIlqUnrMF2o+YfjWDUUiCXDwH2QieCw="}]},"_npmUser":{"name":"000alen","email":"lclc.alen@gmail.com"},"directories":{},"maintainers":[{"name":"000alen","email":"lclc.alen@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/toposort_2.0.4_1729395170906_0.5553627818268101"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-20T03:31:05.447Z","modified":"2024-10-20T03:32:51.310Z","2.0.3":"2024-10-20T03:31:05.767Z","2.0.4":"2024-10-20T03:32:51.122Z"},"bugs":{"url":"https://github.com/000alen/toposort/issues"},"author":{"name":"Alen Rubilar","email":"lclc.alen@gmail.com"},"license":"MIT","homepage":"https://github.com/000alen/toposort#readme","keywords":["topological","sort","sorting","graphs","graph","dependency","list","dependencies","acyclic"],"repository":{"type":"git","url":"git+https://github.com/000alen/toposort.git"},"description":"Topological sort of directed acyclic graphs (like dependency lists)","maintainers":[{"name":"000alen","email":"lclc.alen@gmail.com"}],"readme":"# Toposort\n\nSort directed acyclic graphs\n\n[![Build Status](https://travis-ci.org/marcelklehr/toposort.png)](https://travis-ci.org/marcelklehr/toposort)\n\n## Installation\n\n`npm install toposort` or `component install marcelklehr/toposort`  \n\nthen in your code:\n\n```js\ntoposort = require('toposort')\n```\n\n## Usage\nWe want to sort the following graph.\n\n![graph](https://cdn.rawgit.com/marcelklehr/toposort/8b14e9fd/graph.svg)\n\n```js\n// First, we define our edges.\nvar graph = [\n  ['put on your shoes', 'tie your shoes']\n, ['put on your shirt', 'put on your jacket']\n, ['put on your shorts', 'put on your jacket']\n, ['put on your shorts', 'put on your shoes']\n]\n\n\n// Now, sort the vertices topologically, to reveal a legal execution order.\ntoposort(graph)\n// [ 'put on your shirt'\n// , 'put on your shorts'\n// , 'put on your jacket'\n// , 'put on your shoes'\n// , 'tie your shoes' ]\n```\n\n(Note that there is no defined order for graph parts that are not connected\n -- you could also put on your jacket after having tied your shoes...)\n\n### Sorting dependencies\nIt is usually more convenient to specify *dependencies* instead of \"sequences\".\n```js\n// This time, edges represent dependencies.\nvar graph = [\n  ['tie your shoes', 'put on your shoes']\n, ['put on your jacket', 'put on your shirt']\n, ['put on your shoes', 'put on your shorts']\n, ['put on your jacket', 'put on your shorts']\n]\n\ntoposort(graph) \n// [ 'tie your shoes'\n// , 'put on your shoes'\n// , 'put on your jacket'\n// , 'put on your shirt'\n// , 'put on your shorts' ]\n\n// Now, reversing the list will reveal a legal execution order.\ntoposort(graph).reverse() \n// [ 'put on your shorts'\n// , 'put on your shirt'\n// , 'put on your jacket'\n// , 'put on your shoes'\n// , 'tie your shoes' ]\n```\n\n## API\n\n### toposort(edges)\n\n+ edges {Array} An array of directed edges describing a graph. An edge looks like this: `[node1, node2]` (vertices needn't be strings but can be of any type).\n\nReturns: {Array} a list of vertices, sorted from \"start\" to \"end\"\n\nThrows an error if there are any cycles in the graph.\n\n### toposort.array(nodes, edges)\n\n+ nodes {Array} An array of nodes\n+ edges {Array} An array of directed edges. You don't need to mention all `nodes` here.\n\nThis is a convenience method that allows you to define nodes that may or may not be connected to any other nodes. The ordering of unconnected nodes is not defined.\n\nReturns: {Array} a list of vertices, sorted from \"start\" to \"end\"\n\nThrows an error if there are any cycles in the graph.\n\n## Tests\n\nRun the tests with `node test.js`.\n\n## Legal\n\nMIT License\n","readmeFilename":"README.md"}