{"_id":"uniloc","_rev":"9-53b0d9ae888b51c5148ffc48e7b7edbc","name":"uniloc","description":"Universal JavaScript Route Parsing and Generation in 1.3KB compressed/minified","dist-tags":{"latest":"0.3.0"},"versions":{"0.1.0":{"name":"uniloc","version":"0.1.0","description":"Universal JavaScript Route Parsing and Generation in 1.3KB compressed/minified","main":"uniloc.js","scripts":{"test":"npm run test"},"repository":{"type":"git","url":"git+https://github.com/unicorn-standard/uniloc.git"},"keywords":["uniloc","routing","unicorn-standard","tiny"],"author":{"name":"James K Nelson","email":"james@jamesknelson.com"},"license":"MIT","bugs":{"url":"https://github.com/unicorn-standard/uniloc/issues"},"homepage":"http://unicornstandard.com/packages/uniloc.html","gitHead":"679a97016c96a640ee4384aa3b4598ebdc068162","_id":"uniloc@0.1.0","_shasum":"7955b6c254bac81b1377e46a5f4ae2356324c9c6","_from":".","_npmVersion":"3.3.1","_nodeVersion":"0.12.7","_npmUser":{"name":"jamesknelson","email":"james@numbat.com.au"},"maintainers":[{"name":"jamesknelson","email":"james@numbat.com.au"}],"dist":{"shasum":"7955b6c254bac81b1377e46a5f4ae2356324c9c6","tarball":"https://registry.npmjs.org/uniloc/-/uniloc-0.1.0.tgz","integrity":"sha512-iQOwrLQc5HvTq4I8L2XLQL16u8AWnrI/kb7kxyyZ7UJ0nJOu1wZVdRCSDf8/FA7IdmDhD48Kz6gTtpAURAQfEQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC3sNJ20drZPt7+srvQXkkcEGqUVpyUK1sGF9oyr+PQWQIhAPDEmm3Shfo4lE/Sn/cCFNp0v5o9sctAwaqf3sq7ylS+"}]}},"0.2.0":{"name":"uniloc","version":"0.2.0","description":"Universal JavaScript Route Parsing and Generation in 1.3KB compressed/minified","main":"uniloc.js","scripts":{"test":"npm run test"},"repository":{"type":"git","url":"git+https://github.com/unicorn-standard/uniloc.git"},"keywords":["uniloc","routing","unicorn-standard","tiny"],"author":{"name":"James K Nelson","email":"james@jamesknelson.com"},"license":"MIT","bugs":{"url":"https://github.com/unicorn-standard/uniloc/issues"},"homepage":"http://unicornstandard.com/packages/uniloc.html","gitHead":"fcef867bcaf346855dc2975e353ac8d0ba961462","_id":"uniloc@0.2.0","_shasum":"8613e1b5937dbf73c5318af142e80defe367683f","_from":".","_npmVersion":"3.3.1","_nodeVersion":"0.12.7","_npmUser":{"name":"jamesknelson","email":"james@numbat.com.au"},"maintainers":[{"name":"jamesknelson","email":"james@jamesknelson.com"}],"dist":{"shasum":"8613e1b5937dbf73c5318af142e80defe367683f","tarball":"https://registry.npmjs.org/uniloc/-/uniloc-0.2.0.tgz","integrity":"sha512-xrq2MkYPdjiCUTmNrp1nFV4bf+MsdkOuZwDgLdrRkKSYzs6IN12+cZZWSu+WAR12Y2I7F4NHGMuorJQkSM40Mw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGAV1RorhlojAxRGeOyyY5r1HcICE5RWNNX8jPmj4zN6AiBP4zMLSoy9lt4AQhSFNyrsxqmj5gaO7syPZ5HnbGgEWg=="}]}},"0.3.0":{"name":"uniloc","version":"0.3.0","description":"Universal JavaScript Route Parsing and Generation in 1.3KB compressed/minified","main":"uniloc.js","scripts":{"test":"npm run test"},"repository":{"type":"git","url":"git+https://github.com/unicorn-standard/uniloc.git"},"keywords":["uniloc","routing","unicorn-standard","tiny"],"author":{"name":"James K Nelson","email":"james@jamesknelson.com"},"license":"MIT","bugs":{"url":"https://github.com/unicorn-standard/uniloc/issues"},"homepage":"http://unicornstandard.com/packages/uniloc.html","gitHead":"38c620aabea39dac2d2b2bffcef570e67ca5f76e","_id":"uniloc@0.3.0","_shasum":"c461c765a2494570beb202bed2e67f7d7f57955a","_from":".","_npmVersion":"3.3.12","_nodeVersion":"0.12.7","_npmUser":{"name":"jamesknelson","email":"james@numbat.com.au"},"maintainers":[{"name":"jamesknelson","email":"james@jamesknelson.com"}],"dist":{"shasum":"c461c765a2494570beb202bed2e67f7d7f57955a","tarball":"https://registry.npmjs.org/uniloc/-/uniloc-0.3.0.tgz","integrity":"sha512-e5ww85FupZlbS5VihjB6pKKrpTNS46NBL4Iqfo8S2KXFYwXjo/NeELqtOmHYnG//gsOoOaIVAvkWyGZbafN89Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCpVfikCMx+MnIlHrSEgvzf9U69UKaSKMnJ9VzmxqlYUwIgVZVe7hOld/s7GcPueszVXJr3tg8FH0pxwnhcr6j3rpQ="}]},"_npmOperationalInternal":{"host":"packages-9-west.internal.npmjs.com","tmp":"tmp/uniloc-0.3.0.tgz_1456632981509_0.21946294861845672"}}},"readme":"# uniloc\n\nUniloc is a utility to match URIs to named routes, and to generate URIs given a route name and options.\n\nIn contrast to many popular routing systems, uniloc's behavior is not affected by the order in which routes are specified.\n\nAdditionally, by assuming that each location in your app has a single canonical URI/method, and assuming the format of your URIs follow a number of fairly uncontroversial conventions, uniloc is able to detect conflicts in your config which may would have resulted in hours of debugging pain in a first-match-wins system.\n\n## Installation\n\nUse as a [standalone file](https://raw.githubusercontent.com/unicorn-standard/uniloc/master/uniloc.js), or install with npm:\n\n```\nnpm install uniloc\n```\n\n## Example\n\n```javascript\n/*\n * Configure routes and aliases\n */\n\nvar ROUTER = uniloc(\n  // Routes\n  { \n    listContacts: 'GET /contacts',\n    postContact: 'POST /contacts',\n    editContact: 'GET /contacts/:id/edit',\n  }, \n\n  // Aliases\n  {\n    'GET /': 'listContacts',\n  }\n);\n\n\n/*\n * Lookup URIs\n */\n\nROUTER.lookup('/contacts/13/edit?details=true')\n// {name: 'editContact', options: {id: 13, details: true}}\n\nROUTER.lookup('/?page=10')\n// {name: 'listContacts', options: {page: 10}}\n\nROUTER.lookup('/?page=10', 'PATCH')\n// null\n\n\n/*\n * Generate URIs\n */\n\nROUTER.generate('listContacts', {page: 10})\n// '/contacts?page=10'\n\nROUTER.generate('editContact', {id: 'james'})\n// '/contacts/james/edit'\n```\n\n## Location strings\n\nUniloc assumes that each of the locations in your app is associated with a single HTTP method, and a single URI or set of URIs where the only varying parts represent the **route parameters**.\n\nGiven this assumption, it is possible to represent each location in the application with a **location string**, which includes the HTTP method, and a URI where the varying parts are marked as parameters. For example:\n\n```\nPATCH /contacts/:contactId/photos/:photoId\n```\n\n### Format\n\n- Location strings must consist of a HTTP method and URI template joined by whitespace\n- The HTTP method must be in UPPERCASE\n- The URI template must start with a `/`, end without a `/`, and must not include the `?` or `#` characters\n- Route parameters are delineated with `/` character or the end of the string, and start with a `:` character followed by the route parameter's name.\n\n## API\n\n### `uniloc(routes, aliases={}) -> {lookup, generate}`\n\n`uniloc` takes two objects:\n\n- `routes`: an object mapping route names to their canonical location string\n- `aliases`: *optional* an object mapping other location strings to the routes named in `routes`\n\nRoute names are just strings. The `.` character is reserved, as it may be used in a future release to specify hierarchy.\n\nWhile two routes or aliases cannot use the same location string, a route without a route parameter in one position *can* overlap another URI with a route parameter in the same position. In this case, the route without the route parameter will be given priority.\n\n#### Example\n\n```javascript\nvar ROUTER = uniloc(\n  // Routes\n  { \n    listContacts: 'GET /contacts',\n    postContact: 'POST /contacts',\n    editContact: 'GET /contacts/:id/edit',\n  }, \n\n  // Aliases\n  {\n    'GET /': 'listContacts',\n  }\n);\n```\n\n### `lookup(URI, method='GET') -> {name, options}`\n\n`lookup` is one of the properties of the object returned by `uniloc`.\n\n`lookup` takes a URI and HTTP method, and returns the route name which matches that URI/method, with an options object containing any route and query parameters. If no location is defined which matches the passed in URI/method, it returns null.\n\n#### Examples\n\n```javascript\nROUTER.lookup('/contacts/13/edit?details=true')\n// Returns {name: 'editContact', options: {id: 13, details: true}}\n\nROUTER.lookup('/?page=10')\n// Returns {name: 'listContacts', options: {page: 10}}\n\nROUTER.lookup('/?page=10', 'PATCH')\n// Returns null\n\n```\n\n### `generate(name, options) -> URI`\n\n`generate` is one of the properties of the object returned by `uniloc`.\n\n`generate` takes a route name and options object, and returns a URI string\nbased on the canonical URI for the given route. Options are substituted in\nfor route parameters where possible, and the remaining options are appended\nas a query string.\n\nIf the given route name doesn't exist, an exception is thrown.\n\n#### Examples\n\n```javascript\nROUTER.generate('listContacts', {page: 10})\n// Returns '/contacts?page=10'\n\nROUTER.generate('editContact', {id: 'james'})\n// Returns '/contacts/james/edit'\n\nROUTER.generate('editFoo', {id: 'james'})\n// Exception!\n```\n","maintainers":[{"name":"jamesknelson","email":"james@jamesknelson.com"}],"time":{"modified":"2022-06-28T04:35:47.139Z","created":"2015-10-04T09:12:46.268Z","0.1.0":"2015-10-04T09:12:46.268Z","0.2.0":"2015-10-05T05:47:23.905Z","0.3.0":"2016-02-28T04:16:22.575Z"},"homepage":"http://unicornstandard.com/packages/uniloc.html","keywords":["uniloc","routing","unicorn-standard","tiny"],"repository":{"type":"git","url":"git+https://github.com/unicorn-standard/uniloc.git"},"author":{"name":"James K Nelson","email":"james@jamesknelson.com"},"bugs":{"url":"https://github.com/unicorn-standard/uniloc/issues"},"license":"MIT","readmeFilename":"README.md","users":{"mhaidarh":true,"wearevilla":true}}