{"id":15657399,"url":"https://github.com/gustavohenke/toposort","last_synced_at":"2025-10-28T17:06:10.854Z","repository":{"id":6185084,"uuid":"7415438","full_name":"gustavohenke/toposort","owner":"gustavohenke","description":"Topologically sort directed acyclic graphs (such as dependency lists) in node.js","archived":false,"fork":false,"pushed_at":"2025-02-17T18:55:34.000Z","size":413,"stargazers_count":23,"open_issues_count":5,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T06:09:02.061Z","etag":null,"topics":["javascript","toposort"],"latest_commit_sha":null,"homepage":"https://npmjs.org/package/toposort-class","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gustavohenke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-01-03T00:03:25.000Z","updated_at":"2024-08-01T21:48:50.000Z","dependencies_parsed_at":"2023-12-13T00:34:34.997Z","dependency_job_id":"7fe132fe-880c-474c-9799-c0c3bec0f5c3","html_url":"https://github.com/gustavohenke/toposort","commit_stats":{"total_commits":147,"total_committers":7,"mean_commits":21.0,"dds":0.5374149659863945,"last_synced_commit":"183e3f4ec6094f6c961738c54e7e1f375fa7862e"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavohenke%2Ftoposort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavohenke%2Ftoposort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavohenke%2Ftoposort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavohenke%2Ftoposort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gustavohenke","download_url":"https://codeload.github.com/gustavohenke/toposort/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135144,"owners_count":20889421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","toposort"],"created_at":"2024-10-03T13:06:42.866Z","updated_at":"2025-10-28T17:06:05.814Z","avatar_url":"https://github.com/gustavohenke.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Toposort\n[![CI](https://github.com/gustavohenke/toposort/actions/workflows/ci.yml/badge.svg)](https://github.com/gustavohenke/toposort/actions/workflows/ci.yml)\n\n__Sorting directed acyclic graphs, for Node.js, io.js and the browser__\n_This was originally done by Marcel Klehr. [Why not checkout his original repo?](https://github.com/marcelklehr/toposort)_\n\n## Installation\nThere are a few ways for installing Toposort. Here are them:\n\n* Via NPM: `npm install toposort-class`\n* Via Bower: `bower install toposort`\n* Via Git: `git clone git://github.com/gustavohenke/toposort.git`\n* [Direct download](https://raw.githubusercontent.com/gustavohenke/toposort/master/build/toposort.js) ([Minified](https://raw.githubusercontent.com/gustavohenke/toposort/master/build/toposort.min.js)) for use in the browser\n\n## Example\nLet's say you have the following dependency graph:\n\n* Plugin depends on Backbone and jQuery UI Button;\n* Backbone depends on jQuery and Underscore;\n* jQuery UI Button depends on jQuery UI Core and jQuery UI Widget;\n* jQuery UI Widget and jQuery UI Core depend on jQuery;\n* jQuery and Underscore don't depend on anyone.\n\nNow, how would you sort this in a way that each asset will be correctly placed? You'll probably need the following sorting:\n\n* `jQuery`, `jQuery UI Core`, `jQuery UI Widget`, `jQuery UI Button`, `Underscore`, `Backbone`, `Plugin`\n\nYou can achieve it with the following code, using `toposort-class`:\n```javascript\nvar Toposort = require('toposort-class'),\n\tt = new Toposort();\n\nt.add(\"jquery-ui-core\", \"jquery\")\n .add(\"jquery-ui-widget\", \"jquery\")\n .add(\"jquery-ui-button\", [\"jquery-ui-core\", \"jquery-ui-widget\"])\n .add(\"plugin\", [\"backbone\", \"jquery-ui-button\"])\n .add(\"backbone\", [\"underscore\", \"jquery\"]);\n\nconsole.log(t.sort().reverse());\n\n/* Will output:\n * ['jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-button', 'underscore', 'backbone', 'plugin']\n *\n * And you're done.\n */\n```\n\n## Usage\nCommonJS (Node.js and io.js):\n```javascript\nvar Toposort = require('toposort-class'),\n\tt = new Toposort();\n```\n\nBrowser with AMD:\n```javascript\ndefine(\"myModule\", [\"Toposort\"], function(Toposort) {\n    var t = new Toposort();\n});\n```\n\nBrowser without AMD:\n```javascript\nvar t = new window.Toposort();\n```\n\nor whatever global object there is instead of `window`.\n\n## API\n\n#### `.add(item, deps)`\n* _{String}_ `item` - The name of the dependent item that is being added\n* _{Array|String}_ `deps` - A dependency or list of dependencies of `item`\n\n__Returns:__ _{Toposort}_ The Toposort instance, for chaining.\n\n#### `.sort()`\n__Returns:__ _{Array}_ The list of dependencies topologically sorted.\n\nThis method will check for cyclic dependencies, like \"A is dependent of A\".\n\n#### `.clear()`\n__Returns:__ _{Toposort}_ The Toposort instance, for chaining.\n\nClears all edges, effectively resetting the instance.\n\n#### `.Toposort`\n\nReference to the Toposort constructor.\n\n## Legal\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgustavohenke%2Ftoposort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgustavohenke%2Ftoposort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgustavohenke%2Ftoposort/lists"}