{"name":"sort-route-addresses","version":"0.0.1","description":"Sort Sails/Express-style route addresses by inclusivity","main":"index.js","scripts":{"test":"mocha"},"author":{"name":"sgress454"},"license":"MIT","devDependencies":{"mocha":"^3.1.2"},"dependencies":{"lodash":"^3.10.1"},"gitHead":"017a33bcda7bbe8fbeb151dbcc314c94d9acd330","_id":"sort-route-addresses@0.0.1","_shasum":"23a87d283113b12ee1fedb4cf43af212bb56dabb","_from":".","_npmVersion":"2.15.8","_nodeVersion":"4.4.7","_npmUser":{"name":"sgress454","email":"sgress454@treeline.io"},"dist":{"shasum":"23a87d283113b12ee1fedb4cf43af212bb56dabb","tarball":"http://registry-npm.ywwl.com/sort-route-addresses/download/sort-route-addresses-0.0.1.tgz","integrity":"sha512-Xom1KyYfSVDCvP6r/XW1YLYyStDvx7zpiboPeeSsLr75su1391ECNHkAHiJBEth0sYqiyPyhFRnyUDpm+x+AVw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDBYmsO1ii4p2ImhsswTIcAzDjCPhlGNrzqlCCob2TKLQIhAPux+g256bK5fCM9d8qGmP/IKdChOfFO8gg8hbTohOE5"}],"size":5892,"noattachment":false,"key":"/sort-route-addresses/-/sort-route-addresses-0.0.1.tgz"},"maintainers":[{"name":"sgress454","email":"sgress454@treeline.io"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/sort-route-addresses-0.0.1.tgz_1476983869983_0.9263561312109232"},"directories":{},"readme":"# An algorithm for ordering route addresses\n\n### Definition of a \"route address\"\n\nFor the purposes of this algorithm, a route address is a string containing:\n\n* An optional HTTP verb (or `ALL`) prefix, followed by a space, followed by:\n* 1 or more path components, where each path component is:\n  * A forward slash `/`, followed by:\n  * A colon `:` followed by any combination of letters and numbers (a \"param\"), OR\n  * A star `*` (a \"wildcard\"), OR \n  * Any combination of letters and numbers (a \"static path component\")\n\nIn other words, any Sails-compatible route path.\n\n### Algorithm\n\nGiven an unordered list of route addresses:\n\n1. Find the maximum number of parts (`maxParts`) in any address, by ignoring the optional verb prefix and initial forward slash and splitting each address on the remaining `/` characters.\n2. For each address, construct a string (`rank`) by examining each part in the address from left to right and:\n   * Adding a `1` to the string for each static path component\n   * Adding a `2` to the string for each param component\n   * Adding a `3` to the string for each wildcard component\n   * If the address being examined has fewer than `maxParts` parts, pad the string with `0`s if no wildcards were encountered, or `4`s if wildcards were encountered.\n   * Add a `0` to the end of the string if the address has a specific verb prefix (i.e. not `ALL`), and a `1` if it has a `ALL` prefix or no prefix.\n   * Finally, prefix a `5` at the beginning of the string if the path has _no_ static components<sup>[1](#footnote1)</sup>.\n\n3. Sort the addresses by their `rank`, with lesser ranks coming before greater ones.\n\n### Example\n\n```\nRANK  ADDRESS\n----  -----\n1000  GET /foo\n1001  /foo\n1101  /foo/bar\n1111  /foo/bar/baz\n1120  GET /foo/bar/:baz\n1121  /foo/bar/:baz\n1130  GET /foo/bar/*\n1131  /foo/bar/*\n1201  /foo/:bar\n1211  /foo/:bar/baz\n1221  /foo/:bar/:baz\n1311  /foo/*/baz\n1341  /foo/*\n2101  /:foo/bar\n2111  /:foo/bar/baz\n2121  /:foo/bar/:baz\n2211  /:foo/:bar/baz\n3111  /*/bar/baz\n3131  /*/baz/*\n3141  /*/baz\n52001 /:foo\n52201 /:foo/:bar\n52221 /:foo/:bar/:baz\n52231 /:foo/:bar/*\n52341 /:foo/*\n53440 GET /*\n53441 /*\n```\n\n<hr/>\n\n<a name=\"footnote1\"><sup>1</sup></a>: This ensures that addresses like `/*/baz/*` are ranked above ones like `/:foo/:bar/:baz` -- the static `baz` component implies that the author intends for `*/baz/*` to handle request URLs of at least three components, one of which is `baz`; if `/:foo/:bar/:baz/` were ranked higher in the list, it would swallow the subset of those URLs with _exactly_ three components.\n\n\n## Help\n\nIf you have a question, need professional support, or just want to talk Sails/Node.js with other folks in the community, click [here](https://sailsjs.com/support).\n\n\n## Bugs &nbsp; [![NPM version](https://badge.fury.io/js/sort-route-addresses.svg)](http://npmjs.com/package/sort-route-addresses)\n\nTo report a bug, [click here](https://sailsjs.com/bugs).\n\n\n## Contributing\n\nPlease observe the guidelines and conventions laid out in the [Sails project contribution guide](https://sailsjs.com/documentation/contributing) when opening issues or submitting pull requests.\n\n[![NPM](https://nodei.co/npm/sort-route-addresses.png?downloads=true)](http://npmjs.com/package/sort-route-addresses)\n\n## License\n\nLike the [Sails framework](https://sailsjs.com), this package is free and open-source under the [MIT License](https://sailsjs.com/license).\n","publish_time":1476983870573,"_cnpm_publish_time":1476983870573,"dist-tags":{"latest":"0.0.4"}}