{"_id":"express-negotiate","_rev":"17-b0a45eda252c45db6399e207840545dc","name":"express-negotiate","description":"Express content negotiation functions","dist-tags":{"latest":"0.0.6"},"versions":{"0.0.1":{"name":"express-negotiate","version":"0.0.1","description":"Express content negotiation functions","keywords":["express"],"author":{"name":"Chris Leishman","email":"chris@leishman.org"},"dependencies":{"mime":">= 0.0.1"},"devDependencies":{"should":"0.2.1","express":">= 2.3.7","expresso":">= 0.7.6"},"main":"index","engines":{"node":">= 0.2.0"},"repository":{"type":"git","url":"git://github.com/chrisleishman/express-negotiate.git"},"_npmUser":{"name":"chrisleishman","email":"chris@leishman.org"},"_id":"express-negotiate@0.0.1","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.6.2","_defaultsLoaded":true,"dist":{"shasum":"43bea0b30c51c7aaeacfc886bee448ecd57b9884","tarball":"https://registry.npmjs.org/express-negotiate/-/express-negotiate-0.0.1.tgz","integrity":"sha512-HFcynfcIomVMm7vBqFHHx6u+IilRj0xVIIDDRtdAX+g0Mi0ohASscKNQpOKWQ41iYRsGjHYINMb9H12wpRRpwA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDmaDlOmcRi9wFaIpXangHD/fbTQ1Nd3m2+22lj71f90AiBKBoqIVtAMvRKls1qsI6fbN8hDTDxI94ScFXHtvpK9QQ=="}]},"maintainers":[{"name":"chrisleishman","email":"chris@leishman.org"}],"directories":{}},"0.0.2":{"name":"express-negotiate","version":"0.0.2","description":"Express content negotiation functions","keywords":["express"],"author":{"name":"Chris Leishman","email":"chris@leishman.org"},"dependencies":{"mime":">= 0.0.1"},"devDependencies":{"should":"0.2.1","express":">= 2.3.7","expresso":">= 0.7.6"},"main":"index","engines":{"node":">= 0.2.0"},"repository":{"type":"git","url":"git://github.com/chrisleishman/express-negotiate.git"},"_npmUser":{"name":"chrisleishman","email":"chris@leishman.org"},"_id":"express-negotiate@0.0.2","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.6.2","_defaultsLoaded":true,"dist":{"shasum":"92b19fbe88c7aead2fcbe0e3cd67498e6a828c08","tarball":"https://registry.npmjs.org/express-negotiate/-/express-negotiate-0.0.2.tgz","integrity":"sha512-YSynOyEglHEcrB4h5oRSd2fp9qLB44EEA02+7xNbNJHFcEpuslrOmSLW9fIN2S/vOaPFa9WC2+S07NqXhG+5Iw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDy/TOy0rnkPg0frJzhP0S7pWgj59+hC14Q2ndfSqb4VAIgD4YJtIApJyDht/if5z4dIFWk5OWV/U/G9md2Vl4fwAQ="}]},"maintainers":[{"name":"chrisleishman","email":"chris@leishman.org"}],"directories":{}},"0.0.3":{"name":"express-negotiate","version":"0.0.3","description":"Express content negotiation functions","keywords":["express"],"author":{"name":"Chris Leishman","email":"chris@leishman.org"},"dependencies":{"mime":">= 0.0.1"},"devDependencies":{"should":"0.2.1","express":"2.4.7","expresso":">= 0.7.6"},"main":"index","engines":{"node":">= 0.2.0"},"repository":{"type":"git","url":"git://github.com/chrisleishman/express-negotiate.git"},"_npmUser":{"name":"chrisleishman","email":"chris@leishman.org"},"_id":"express-negotiate@0.0.3","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.4.7","_defaultsLoaded":true,"dist":{"shasum":"5eb6e408db2c9264bec0d4299f3b7c26f85cf0fc","tarball":"https://registry.npmjs.org/express-negotiate/-/express-negotiate-0.0.3.tgz","integrity":"sha512-O6icxntDxaF9FOIyK+VH5wvkiA/ViP3kyqXpFcjezqL9WQLFgwkPad/g+fWomppyKsNQvIitjA0+q7TXTa4YQQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDEnFhqKWyw5leYF4qVUOLSKuX5RGIdPPRvR3XLvYFergIhAJGBuHFgk2pxg9H7xV3H8bEluiRXK62IbPBeiFLrJq75"}]},"maintainers":[{"name":"chrisleishman","email":"chris@leishman.org"}],"directories":{}},"0.0.4":{"name":"express-negotiate","version":"0.0.4","description":"Express content negotiation functions","keywords":["express"],"author":{"name":"Chris Leishman","email":"chris@leishman.org"},"dependencies":{"mime":">= 0.0.1"},"devDependencies":{"should":"0.2.1","express":"2.4.7","expresso":">= 0.7.6"},"main":"index","engines":{"node":">= 0.2.0"},"repository":{"type":"git","url":"git://github.com/chrisleishman/express-negotiate.git"},"_npmUser":{"name":"chrisleishman","email":"chris@leishman.org"},"_id":"express-negotiate@0.0.4","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.4.7","_defaultsLoaded":true,"dist":{"shasum":"edfec837486151530f9addc72d4e46a3c86f202e","tarball":"https://registry.npmjs.org/express-negotiate/-/express-negotiate-0.0.4.tgz","integrity":"sha512-+94O2KNmzzCLUkzWByRJ1gezBeqLI+vJCssTbp6vtKOR/MHU08aPbKvnY7R9rEG0lF33x5X6rCmklYA6I+2m5A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF3ylhQ0PVmAH853fCVF8YPB45PiqsIXba/eH0KbnNiBAiB+/1x9cVMlL1Fv9zbzhabgMHh6CRqWP00bZGtVHrKhWw=="}]},"maintainers":[{"name":"chrisleishman","email":"chris@leishman.org"}],"directories":{}},"0.0.5":{"name":"express-negotiate","version":"0.0.5","description":"Express content negotiation functions","keywords":["express"],"author":{"name":"Chris Leishman","email":"chris@leishman.org"},"dependencies":{"mime":">= 0.0.1"},"devDependencies":{"should":"0.6.3","express":"2.5.9","expresso":"0.9.2"},"main":"index","engines":{"node":">= 0.2.0"},"repository":{"type":"git","url":"git://github.com/chrisleishman/express-negotiate.git"},"_npmUser":{"name":"chrisleishman","email":"chris@leishman.org"},"_id":"express-negotiate@0.0.5","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.21","_nodeVersion":"v0.6.18","_defaultsLoaded":true,"dist":{"shasum":"f021014d0c882fd19756b24659f1800685d2ff2e","tarball":"https://registry.npmjs.org/express-negotiate/-/express-negotiate-0.0.5.tgz","integrity":"sha512-lPk+wTpBEcK/xAHK3jqpbcPAoaZs7gNC+iuwclB5BbDipDOOg/CUwAa4XOj8hwi9eFB4Tb9avGKuCOGWu09OnA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC2T7hDljrauOLkA1BDzNQTwP/AkSHFK1tXT83IXL6SMQIgQ7FqqqJPzwRbSXbquV4B8o05FdUaWiG+X6lzCLFzd14="}]},"maintainers":[{"name":"chrisleishman","email":"chris@leishman.org"}],"directories":{}},"0.0.6":{"name":"express-negotiate","version":"0.0.6","description":"Express content negotiation functions","keywords":["express"],"author":{"name":"Chris Leishman","email":"chris@leishman.org"},"dependencies":{"mime":"^2.3.1"},"devDependencies":{"should":"0.6.3","express":"2.5.9","expresso":"0.9.2"},"main":"index","engines":{"node":">= 0.2.0"},"repository":{"type":"git","url":"git://github.com/chrisleishman/express-negotiate.git"},"gitHead":"89f721249b185b60896122bdba7ecba1e7ff9183","bugs":{"url":"https://github.com/chrisleishman/express-negotiate/issues"},"homepage":"https://github.com/chrisleishman/express-negotiate#readme","_id":"express-negotiate@0.0.6","_npmVersion":"6.2.0","_nodeVersion":"10.9.0","_npmUser":{"name":"lukasschneider","email":"lukas.schneider@rwth-aachen.de"},"dist":{"integrity":"sha512-zDfBKRCiE8HVxpDW/4idtJRsJekWFU5vCt8MAKhQdhKrWnKSyeOZlsJOFFsydq1YuLeHTRyT0SxapHPpWiT1rA==","shasum":"b7ad49e8b98d7fa2aee319b83af8bd4c7042a23e","tarball":"https://registry.npmjs.org/express-negotiate/-/express-negotiate-0.0.6.tgz","fileCount":6,"unpackedSize":10909,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb2aUwCRA9TVsSAnZWagAASWcP/3WAIXWo1R2KelUwNGRy\neTPJWi61koBve+IXM6HQ63dJwcex4odb8Tk1aNTqdCgMFvnYJ2xKg/XFyW1e\nGwnA+c8WjvmrrVc7xH0oEEe5glijU7thEtd11R18yr6jn5HELRNu3xhxjVak\nV3Vqrz96HZo5iMXUChFb9XDdHHveHezFNUhqaYS0F7M9cqK/eoTJC6IGvxv1\nBIMGADMBSkZ9VfVTcyiZW3hps8ypaV5vLhod5hvQ2odED7K0NTu6GCQzkwjM\n9q9p2wcjXjqIxTM7Q2QvTW9vPJFrsK2XqZ6TR385BCcu+oYtQn0MrPJr5tdV\njZQNwZcDpxbNEwZBFUcv/aPE5hmp/rxLktkNhrE0OCF0WKflE5NREA+sziXB\nW/YDTeEP6qFcpdcvRGHRrUecC0TmopdIYYaQ4ScnOQRmQKGvhmECt0bFxLQD\n37YiNTSWfisXCz35B9hdDFn5stt+jNEgfAY+gYcyNPbd+thT7GP2vFia3cG2\njtZVZK8NCi6NR/JY5ze2Vfv9Czx2TRD08isRO32gnInF/KiHZlA1eB3/XY78\nEEaVVgFgBTQ1eIy8S3sMKAMYLQ8NnleVOlmjcW+NmB/mdemeyZkfVaPqaHmX\nfPHH3FliYDcwWQ1PpB3wthJgQ7e9a4MGrjgUjry3XW747ttQ3vyCbm+oqlH8\nEOc3\r\n=ML3r\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGZCP1fYzSebQlI/mlCs754y+O2mFhouRn8RShN5BR1sAiEAwefDoyv1kcAJWAOieSwEsXr0dZ5hTBRGihTkSFZsuYI="}]},"maintainers":[{"name":"chrisleishman","email":"chris@leishman.org"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/express-negotiate_0.0.6_1540990255209_0.5225186814094003"},"_hasShrinkwrap":false}},"readme":"\n# express-negotiate\n\n  Express content negotiation functions.\n\n## Installation\n\n    $ npm install express-negotiate\n\n## Usage\n\nRequire the module to add the request.negotiate method:\n\n```javascript\nvar express = require('express')\n    , negotiate = require('express-negotiate');\n```\n\nThen use in the route handler:\n\n```javascript\napp.get('/index', function(req, res, next) {\n    req.negotiate({\n          'application/json': function() {\n            res.send('{ message: \"Hello World\" }');\n        }\n        , 'html': function() {\n            res.send('<html><body><h1>Hello World</h1></body></html>');\n        }\n        , 'default': function() {\n            // send HTML anyway\n            res.send('<html><body><h1>Hello World</h1></body></html>');\n        }\n    });\n});\n```\n\nEach handler key is either a full mimetype string, or a file extension string.\n\n## Specifiying priority\n\nWhen multiple handlers are acceptable for satisfying the request, then any may\nbe used the request (it is typically the first specified, however this is\ndependent on the javascript engine implementation).\n\nTo prioritise handlers, simply append a quality in the same notation as the\nclient uses when specifying an Accept header:\n\n```javascript\napp.get('/index', function(req, res, next) {\n    req.negotiate({\n          'application/json;q=0.9': function() {\n            res.send('{ message: \"Hello World\" }');\n        }\n        , 'application/html;q=1.1': function() {\n            res.send('<html><body><h1>Hello World</h1></body></html>');\n        }\n        , 'default': function() {\n            // send HTML anyway\n            res.send('<html><body><h1>Hello World</h1></body></html>');\n        }\n    });\n});\n```\n\nNote that the handler priority is only used after the priorities specified\nby any Accept header in the request have been considered.  A priority cannot be\nspecified on the 'default' handler.\n\n## Combining handlers\n\nWhen the same handler can be used for multiple types, then they can be\ncombined in the string:\n\n```javascript\napp.get('/index', function(req, res, next) {\n    req.negotiate({\n          'application/json;q=0.9': function() {\n            res.send('{ message: \"Hello World\" }');\n        }\n        , 'html;q=1.1,default': function() {\n            res.send('<html><body><h1>Hello World</h1></body></html>');\n        }\n    });\n});\n```\n\n## Handling unacceptable requests\n\nIf there are no acceptable handlers, and no 'default' handler is specified,\nthen req.negotiate will throw a negotiate.NotAcceptable error.  This can be\ncaught and handled using express error handling:\n\n```javascript\napp.get('/index', function(req, res, next) {\n    req.negotiate({\n          'application/json': function() {\n            res.send('{ message: \"Hello World\" }');\n        }\n    });\n});\n\napp.error(function(err, req, res, next) {\n    if (err instanceof negotiate.NotAcceptable) {\n        res.send('Sorry, I dont know how to return any of the content types requested', 406);\n    } else {\n        next(err);\n    }\n});\n```\n\nIn some cases, it is preferable to call next(err) rather than throw an error.\nIf negotiate is passed the 'next' callback function, it will call that\ninstead:\n\n```javascript\napp.get('/index', function(req, res, next) {\n    req.negotiate(next, {\n          'application/json': function() {\n            res.send('{ message: \"Hello World\" }');\n        }\n    });\n});\n```\n\n## Allowing route filename extensions to override Accept header\n\nBy parsing out any filename extension on the route, and passing\nthis to req.negotiate, the client can force a particular\nContent-Type regardless of the Accept header.\n\n```javascript\napp.get('/index.:format?', function(req, res, next) {\n    req.negotiate(req.params.format, {\n          'application/json': function() {\n            res.send('{ message: \"Hello World\" }');\n        }\n    });\n});\n```\n\nPicking up the filename extension on a \"catch-all\" route is a little trickier.\nThe following example uses a regex to achieve this:\n\n```javascript\napp.get(/^.*?(?:\\.([^\\.\\/]+))?$/, function(req, res) {\n    req.negotiate(req.params[0], {\n          'json;q=0.9': function() {\n            res.send({ error: 404, message: 'Not Found' }, 404);\n        }\n        , 'html;q=1.1,default': function() {\n            res.statusCode = 404;\n            res.send('<html><body><h1>Not Found</h1></body></html>');\n        }\n    });\n});\n```\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2011 Chris Leishman &lt;chris@leishman.org&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"chrisleishman","email":"chris@leishman.org"}],"time":{"modified":"2022-06-17T22:28:10.589Z","created":"2011-12-07T17:14:53.142Z","0.0.1":"2011-12-07T17:14:55.351Z","0.0.2":"2011-12-07T22:53:47.036Z","0.0.3":"2011-12-11T14:43:23.183Z","0.0.4":"2011-12-20T01:33:31.362Z","0.0.5":"2012-06-22T16:52:21.636Z","0.0.6":"2018-10-31T12:50:55.558Z"},"author":{"name":"Chris Leishman","email":"chris@leishman.org"},"repository":{"type":"git","url":"git://github.com/chrisleishman/express-negotiate.git"},"users":{"tophsic":true,"jason0518":true},"homepage":"https://github.com/chrisleishman/express-negotiate#readme","keywords":["express"],"bugs":{"url":"https://github.com/chrisleishman/express-negotiate/issues"},"readmeFilename":"Readme.md"}