{"_id":"sort-route-addresses","_rev":"750360","name":"sort-route-addresses","description":"Sort Sails/Express-style route addresses by inclusivity","dist-tags":{"latest":"0.0.4"},"maintainers":[{"name":"rachaelshaw","email":"rachaelshaw@treeline.io"},{"name":"sgress454","email":"scottmgress@gmail.com"},{"name":"mikermcneil","email":"npm@sailsjs.com"},{"name":"eashaw","email":"eashaw@sailsjs.com"}],"time":{"modified":"2024-06-27T03:19:41.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":{"integrity":"sha512-8NPmJNHcPIQvUpGQ4zj9Jn3hsp0TpnH4LhX3+mZrZB73N3TqI/RBo9avazhnPdv8jFH1iTsCTzHXYBiYfuWVyg==","shasum":"91c257e7dcc1d919fb2a19ccdfef628babef548b","tarball":"http://registry-npm.ywwl.com/sort-route-addresses/download/sort-route-addresses-0.0.4.tgz","fileCount":6,"unpackedSize":17440,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh4ePiCRA9TVsSAnZWagAAd3gQAJHJbecLdjRu75dsyxeL\nzAaG54X/BPle1S3dPE3R5G8oGU8MLlDGoJpVcPLvQPC98Njkl8kzb0Iw0TOh\n/4KeIwvdX/tUhj11EuVHMkgQuKaB2mp52Em8gbZk+pviqOPPhIftlV20QwbX\nJvcjgYNfTqw82YsYV3EERY3bPsyy+GUFNK+eqh3mzLtWiKceCnRE5KffNd5/\npngD2zQ9BVEvrD02TEY8hoJPm6JU5qQvuA+y/wVROrpqCY3znyeDp6bkhaZq\nDleAYsw5BGzZ8XzSWGsbdk5zplF5xsyZ/ZAwbf6UATTjoTbmuHi8T7WA5JWl\nCPxIe6q7iQ30feAWzVqsDOOcvEcDidMMWHuVqqjd2QlmMKAW4pp4kWLfIKYC\nnbtfEnylUsl/Mf+EhP9pkSWkG84KfbN8+ly5DO5EqFPlWvEZV2ds7LrAfd0e\nsTf3mZidk2R/z0NNwCzBgCKBhd7t/k/yd5suGpiFvq3K+nloY6Bnpa0JsG81\naoSYBaVgIssqTymJa3ldi3W7O3E58tZ2H/d+t342jZ+RX68Tesue3+MSMbH+\ndMCB+7Bqp/VylwY4SL2tc32suHNr2pb/VRkc2x0NuuGwoID+EX8t1fBweilP\nxwhnat8xB6damfuSO+Q1V3cN9bSjQ6HRrHxFLhVy5EaOr0U6lfTOxYZWk7dx\n/2T2\r\n=Ah4P\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCS2U6x9eZc4mp+KDM4aj2FTmHIPv+1KlIKiV0B2cpahQIgaLqfgyvK2IrQARHYynoXOA1B1o6w9DNVqhbUOjS5qEE="}],"size":6588,"noattachment":false,"key":"/sort-route-addresses/-/sort-route-addresses-0.0.4.tgz"},"_npmUser":{"name":"eashaw","email":"eashaw@sailsjs.com"},"directories":{},"maintainers":[{"name":"rachaelshaw","email":"rachaelshaw@treeline.io"},{"name":"sgress454","email":"scottmgress@gmail.com"},{"name":"mikermcneil","email":"npm@sailsjs.com"},{"name":"eashaw","email":"eashaw@sailsjs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sort-route-addresses_0.0.4_1642193889946_0.9283150370510636"},"_hasShrinkwrap":false,"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":{"integrity":"sha512-FK9GJty+MN4X5ml665lcgJe5y0zjF2wgnNVWS1yVnPFuCODCtMJx8B1rFN5NRwDaCbDGjc45OKkusqrx2GFL4g==","shasum":"6e821f5bb8e7e195f5713f82b8b24674d004ea97","tarball":"http://registry-npm.ywwl.com/sort-route-addresses/download/sort-route-addresses-0.0.3.tgz","fileCount":6,"unpackedSize":17414,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcxyjiCRA9TVsSAnZWagAA3kIP/0lyj48wKSXlvypBgEzN\nKx4ji5sNY1opsYahAd0siF0CY41VHYi3/uhxF0n/VvXNHmDRZYBCGO4LWT7E\nP4yEJ/uju8DTWARml8bMrOOju3n0EgmS0CLdwbJaL6wyH0+b/OPXLm5My8pr\nWGt8QRMKOKBMjwZnqhAqn10ujYzwHJmhRd3I16KNXx370k6p/RSWeyD7R47F\nQkg5z4AuRVsa39DFlpYtkT317VcvYBhzYcn8SHoOHLgiYknS+gr2g7279dMa\nVOO2BFJI4u5RDf23TOL9TH0w6tRoR83jPlib7+QBeYsaCCnOGOKaHy06uHvl\nf3xwkjAS/974uWCW3W0Wff77mX0z4MxZ2pfVIET/fDkPKTL1nlfzuwfBPvT2\nRkZTUDqt0jM9xvogt9QG63VlbJ6Y43rupPZLUCrvx1Q59GjOfWWrTpXsrUnD\nQnhOgdmO+KLdvnskMZNB0mjYdsiWOcghHpn1aRd+ZfrNcoX/80c7H9CDI0ZC\n/v4hCqMU2zZoEvfgEA4UiWJHN5OHCfvT3fCKCI0UjBKeVj/BzwAqJVVF8ug5\n0mvCGIGAyBgCt1W+i/EF0IjRc85xtAKpkHKDCr6gcFiZdZxEnqJzjHhs/RLb\nRlFGaOhc7e/6mOVsrb8oN0J3G9+MTkLOlz7j1sTqpNYIj5AkGZfkBp5eUQyH\nWSPh\r\n=Q9XW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDu4YoEPgTUMYjYPUOPTmPXhpXRQR2KwLv7vL7zlwhYLQIhAOKZzUwN7jmppa4KAoh6q8gtE6R/nbUge4igD1jJ6drI"}],"size":6584,"noattachment":false,"key":"/sort-route-addresses/-/sort-route-addresses-0.0.3.tgz"},"maintainers":[{"email":"npm@sailsjs.com","name":"mikermcneil"},{"email":"sgress454@treeline.io","name":"sgress454"}],"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","tarball":"http://registry-npm.ywwl.com/sort-route-addresses/download/sort-route-addresses-0.0.2.tgz","integrity":"sha512-msFjqw8+MXuo6XAoAfv/noU8DkYItli0rlI5JsBsrROr/vmn0JuKJOOA+SXX1rr7ev8rAInYA5YDqkFUytNjIQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDQqIy+3vRAPc0SBROrpzEHVViYfmCh31JG9807Oy0LqwIhAPNN9QcjC1K8qDUtVwghVnkB6+odC+MJjh8fPwWlWfIV"}],"size":6234,"noattachment":false,"key":"/sort-route-addresses/-/sort-route-addresses-0.0.2.tgz"},"maintainers":[{"name":"sgress454","email":"sgress454@treeline.io"}],"_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},"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","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":{},"publish_time":1476983870573,"_cnpm_publish_time":1476983870573}},"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"}