{"_id":"sort-route-addresses","_rev":"2400624","name":"sort-route-addresses","description":"Sort Sails/Express-style route addresses by inclusivity","dist-tags":{"latest":"0.0.4"},"maintainers":[{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"},{"name":"sgress454","email":"scott@balderdash.co"}],"time":{"modified":"2022-01-14T21:11:19.000Z","created":"2016-10-20T17:17:50.573Z","0.0.4":"2022-01-14T20:58:10.120Z","0.0.3":"2019-04-29T16:40:01.710Z","0.0.2":"2016-10-20T18:30:06.948Z","0.0.1":"2016-10-20T17:17:50.573Z"},"users":{},"author":{"name":"sgress454"},"repository":{"type":"git","url":"git+ssh://git@github.com/sailshq/sort-route-addresses.git"},"versions":{"0.0.4":{"name":"sort-route-addresses","version":"0.0.4","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":{"@sailshq/lodash":"^3.10.2"},"repository":{"type":"git","url":"git+ssh://git@github.com/sailshq/sort-route-addresses.git"},"gitHead":"ecf38104b1356eacbf09c270a01184226a596d69","bugs":{"url":"https://github.com/sailshq/sort-route-addresses/issues"},"homepage":"https://github.com/sailshq/sort-route-addresses#readme","_id":"sort-route-addresses@0.0.4","_nodeVersion":"14.17.0","_npmVersion":"7.20.0","dist":{"shasum":"91c257e7dcc1d919fb2a19ccdfef628babef548b","size":6588,"noattachment":false,"key":"/sort-route-addresses/-/sort-route-addresses-0.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/sort-route-addresses/download/sort-route-addresses-0.0.4.tgz"},"_npmUser":{"name":"eashaw","email":"eashaw@sailsjs.com"},"directories":{},"maintainers":[{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"},{"name":"sgress454","email":"scott@balderdash.co"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sort-route-addresses_0.0.4_1642193889946_0.9283150370510636"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-01-14T21:08:20.288Z","publish_time":1642193890120,"_cnpm_publish_time":1642193890120},"0.0.3":{"name":"sort-route-addresses","version":"0.0.3","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":{"@sailshq/lodash":"^3.10.2"},"repository":{"type":"git","url":"git+ssh://git@github.com/sailshq/sort-route-addresses.git"},"gitHead":"3c462798c2446fbfc657ec908f2b5e04a8571673","bugs":{"url":"https://github.com/sailshq/sort-route-addresses/issues"},"homepage":"https://github.com/sailshq/sort-route-addresses#readme","_id":"sort-route-addresses@0.0.3","_npmVersion":"6.5.0","_nodeVersion":"8.11.3","_npmUser":{"name":"mikermcneil","email":"npm@sailsjs.com"},"dist":{"shasum":"6e821f5bb8e7e195f5713f82b8b24674d004ea97","size":6584,"noattachment":false,"key":"/sort-route-addresses/-/sort-route-addresses-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/sort-route-addresses/download/sort-route-addresses-0.0.3.tgz"},"maintainers":[{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"},{"name":"sgress454","email":"scott@balderdash.co"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sort-route-addresses_0.0.3_1556556001552_0.4896381410196853"},"_hasShrinkwrap":false,"publish_time":1556556001710,"_cnpm_publish_time":1556556001710},"0.0.2":{"name":"sort-route-addresses","version":"0.0.2","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":"aed9e26a81ba10c73eb4f6f92c1beb1fd11ca5ab","_id":"sort-route-addresses@0.0.2","_shasum":"5274447d05c3d579842e2f9fc0ca3c99edfb197b","_from":".","_npmVersion":"2.15.8","_nodeVersion":"4.4.7","_npmUser":{"name":"sgress454","email":"sgress454@treeline.io"},"dist":{"shasum":"5274447d05c3d579842e2f9fc0ca3c99edfb197b","size":6234,"noattachment":false,"key":"/sort-route-addresses/-/sort-route-addresses-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/sort-route-addresses/download/sort-route-addresses-0.0.2.tgz"},"maintainers":[{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"},{"name":"sgress454","email":"scott@balderdash.co"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/sort-route-addresses-0.0.2.tgz_1476988206377_0.6112023242749274"},"directories":{},"publish_time":1476988206948,"_cnpm_publish_time":1476988206948,"_hasShrinkwrap":false},"0.0.1":{"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","size":5892,"noattachment":false,"key":"/sort-route-addresses/-/sort-route-addresses-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/sort-route-addresses/download/sort-route-addresses-0.0.1.tgz"},"maintainers":[{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"rachaelshaw","email":"rachael@balderdash.co"},{"name":"sgress454","email":"scott@balderdash.co"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/sort-route-addresses-0.0.1.tgz_1476983869983_0.9263561312109232"},"directories":{},"publish_time":1476983870573,"_cnpm_publish_time":1476983870573,"_hasShrinkwrap":false}},"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","_attachments":{},"homepage":"https://github.com/sailshq/sort-route-addresses#readme","bugs":{"url":"https://github.com/sailshq/sort-route-addresses/issues"},"license":"MIT"}