{"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,"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":1642193890120,"_cnpm_publish_time":1642193890120,"dist-tags":{"latest":"0.0.4"}}