{"name":"toposort-class","version":"0.1.3","description":"Topological sort of directed acyclic graphs (like dependecy lists)","main":"index.js","devDependencies":{"vows":"*"},"scripts":{"test":"vows --spec test.js"},"repository":{"type":"git","url":"https://github.com/gustavohenke/node-toposort.git"},"keywords":["topological","sort","sorting","graphs","graph","dependency","list","dependencies","acyclic"],"author":"","license":"MIT","_id":"toposort-class@0.1.3","dist":{"shasum":"b2437bbb3494485b92477e969248c7a5f2bdd733","tarball":"http://registry-npm.ywwl.com/toposort-class/download/toposort-class-0.1.3.tgz","integrity":"sha512-hBpZD+p6TP1plrz+ZeGpi3knvKFlaytJ2MynXcyXVbEpyj8HSWXOjEQX3kexyJA8ovepslj9TtH46qnFBdeDGA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDtXZBvqyH+4KVrvKpaoWxyPp6WxU/9Hw1E5DenSqEvKAIgetICL+fjzI3iTsO4U9gaAtLJkPwoN3R5ukpiguD1AAU="}],"size":2579,"noattachment":false,"key":"/toposort-class/-/toposort-class-0.1.3.tgz"},"_npmVersion":"1.1.65","_npmUser":{"name":"gustavohenke","email":"gustavo@injoin.com.br"},"maintainers":[{"name":"gustavohenke","email":"gustavo@injoin.com.br"}],"directories":{},"deprecated":"Items would not be added if empty dependencies array is passed. Use a newer version instead.","readme":"# Toposort\n[![Build Status](http://img.shields.io/travis/gustavohenke/toposort.svg?branch=master&style=flat)](https://travis-ci.org/gustavohenke/toposort)\n[![Dependency Status](http://img.shields.io/gemnasium/gustavohenke/toposort.png?style=flat)](https://gemnasium.com/gustavohenke/toposort)\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","publish_time":1360097315019,"_cnpm_publish_time":1360097315019,"dist-tags":{"beta":"1.0.0","latest":"1.0.1"}}