{"_id":"@polka/send-type","_rev":"11-07507bc5f14bd433c372f34a9abfd511","name":"@polka/send-type","description":"A response helper that detects & handles Content-Types","dist-tags":{"latest":"0.5.2"},"versions":{"0.3.0":{"name":"@polka/send-type","version":"0.3.0","description":"A response helper that detects & handles Content-Types","repository":{"type":"git","url":"git+https://github.com/lukeed/polka.git"},"license":"MIT","files":["*.js"],"author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"publishConfig":{"access":"public"},"bugs":{"url":"https://github.com/lukeed/polka/issues"},"homepage":"https://github.com/lukeed/polka#readme","_id":"@polka/send-type@0.3.0","scripts":{},"_shasum":"4b1924e789f9a0d44fb76dcb8767ac3190bb67d3","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.11.1","_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"dist":{"shasum":"4b1924e789f9a0d44fb76dcb8767ac3190bb67d3","tarball":"https://registry.npmjs.org/@polka/send-type/-/send-type-0.3.0.tgz","integrity":"sha512-nuA7i/zHNEkhd4m20xBsdXaNuHDiRZkQM2+1WvZNgYvzuVVWbOxBI9gWq1kSdwLx2raeFS5nhX6K1h+K3JtZzw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCGQO4wjFybpo3Hs+nEznwugfQZkAQsDI6rr0bzqZcutwIhALhUdJaUaYkUgGw7cHDyXS+sqa62bFyu4KuxF99f0Pra"}]},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/send-type-0.3.0.tgz_1516745094859_0.49293946474790573"},"directories":{}},"0.3.1":{"name":"@polka/send-type","version":"0.3.1","description":"A response helper that detects & handles Content-Types","repository":{"type":"git","url":"https://github.com/lukeed/polka.git"},"license":"MIT","files":["*.js"],"author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"publishConfig":{"access":"public"},"_id":"@polka/send-type@0.3.1","dist":{"shasum":"ccbf724f8a56a6b004215e62079cee2c4193c18b","tarball":"https://registry.npmjs.org/@polka/send-type/-/send-type-0.3.1.tgz","integrity":"sha512-mXaLqZsRl/OeYC0xe/M/r5RawuBQ/O8sptdRfn9rW9vMmiMEyNbY4kGdCHt/PBTBCm/sdmM+S0f3G1OaDTPy3w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC+k5YcqZGDea4mU3/in6vxhS8qgvy2hVbI3ShU4QcoagIgaNtEpMAGUnDiDqpAkw80QnM0NTxVmnZQDdh89NDBO8Y="}]},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/send-type-0.3.1.tgz_1517631886470_0.5997961275279522"},"directories":{}},"0.3.2":{"name":"@polka/send-type","version":"0.3.2","description":"A response helper that detects & handles Content-Types","repository":{"type":"git","url":"https://github.com/lukeed/polka.git"},"license":"MIT","files":["*.js"],"author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"publishConfig":{"access":"public"},"_id":"@polka/send-type@0.3.2","dist":{"shasum":"8d39678e40ca22b4bf933c6ba00055a9370c7a1b","tarball":"https://registry.npmjs.org/@polka/send-type/-/send-type-0.3.2.tgz","fileCount":4,"unpackedSize":3457,"integrity":"sha512-pusRIUvmgYklG4Tnilo1fEAQx+5aGQieupjTwBLnvYXQq8edqhPTk0vfopo0XCLf7kAJ/RVSLT20qyqRmD577Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBaZj6/3bjk5cleqL9nEfkiP042YWQY0qi/HX+T+3nPOAiAxNG0XkRC0TdVeRqCvghS9ZhxKXVAkOkFIPRyDQHhk2g=="}]},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/send-type_0.3.2_1517968971796_0.6745041937620639"},"_hasShrinkwrap":false},"0.3.3":{"name":"@polka/send-type","version":"0.3.3","description":"A response helper that detects & handles Content-Types","repository":{"type":"git","url":"https://github.com/lukeed/polka.git"},"license":"MIT","files":["*.js"],"author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"publishConfig":{"access":"public"},"_id":"@polka/send-type@0.3.3","dist":{"shasum":"6b0fde408eee4793653cbb635c52e3b470916221","tarball":"https://registry.npmjs.org/@polka/send-type/-/send-type-0.3.3.tgz","fileCount":4,"unpackedSize":3457,"integrity":"sha512-/RJaj/F4Yqh+bslJmhJ+uzrwoZwws7ks85cHnnIYDAVFza8em/monMlBZejRD0i0HDnee93dDpvPtFayejqs2g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD5cKWG7rZkls2aE5uzmjtbdbzTq4Nh525hm/k7k3oNmQIhAJU0WYp6X9UEWndtD6FTNfNEMtLCnjpItsQRwMLbysrs"}]},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/send-type_0.3.3_1518203331690_0.5453725651048034"},"_hasShrinkwrap":false},"0.3.4":{"name":"@polka/send-type","version":"0.3.4","description":"A response helper that detects & handles Content-Types","repository":{"type":"git","url":"https://github.com/lukeed/polka.git"},"license":"MIT","files":["*.js"],"author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"publishConfig":{"access":"public"},"_id":"@polka/send-type@0.3.4","dist":{"shasum":"0ffd182deac10e2083ef053c32c32f2d5fbc86f1","tarball":"https://registry.npmjs.org/@polka/send-type/-/send-type-0.3.4.tgz","fileCount":4,"unpackedSize":3457,"integrity":"sha512-Xz5TeWiD0mF+4OY4U61cNPzdeXdmKh8Q+z04z/HujcTyioQG3z3Omu2UQFMkLPVnNBzvqlHynFsvKbsVic6v+w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFikYsDeT3NFwVps10tax4UgdEL0C+PaTQnDDjL/uQivAiBGyi4tDwBBmFN2/ZlcS6lQ+D67TcbHWTBoJg0LK6FvXw=="}]},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/send-type_0.3.4_1518819520635_0.16942877751786223"},"_hasShrinkwrap":false},"0.4.0":{"name":"@polka/send-type","version":"0.4.0","description":"A response helper that detects & handles Content-Types","repository":{"type":"git","url":"https://github.com/lukeed/polka.git"},"license":"MIT","files":["*.js"],"author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"publishConfig":{"access":"public"},"_id":"@polka/send-type@0.4.0","dist":{"shasum":"15c134afd5828358453770d58dab660019af0df3","tarball":"https://registry.npmjs.org/@polka/send-type/-/send-type-0.4.0.tgz","fileCount":4,"unpackedSize":3457,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa+ebRCRA9TVsSAnZWagAA2WYP/jXV+0/cHVbhj12lOha6\nrO7XRwzVBwWzde/FG8xpwm8ZlcvF+8xUpQp7Q+puR0EPWg/oCOtKh9MYJuHw\nyXzf3PJlCluAU4W39PZmeXrr8chOi3GqNPmsfJtwjfC+c3zJ5qHkeMJXVBX4\nK8FiemOgGkdvPD/5MEFJoCSZMOucBPy1yOHdWRXjzxCs7mYl3+3HI6gck6q9\nmJMfy14tzOTZhKj30VNDiJ4CEW1m6EYs/7uLvnPoKaYAQDXkKfyX4YO/JYCO\nrcdfSth1i8qcVSTBAs9rE1jkC3I0+UUVLe/3U/GEO9YNwunD1gZopBTm52t6\nzVWIIwEY55nCxLio3KZbLDrpZn7qcZq+zty/BL1U5npBVJKuATr4bbkJWqGa\nXa0CCwJYs/GcG+PuL2LOar9zgzUUqbQX9Q1uMNX+1IT/k6pi64pB3I79Yjeq\ntD3xB6uzahkv38voH9U/y+k/OlntHFSMCiLCDIqQGw3t+R5WbwE5ipjTwZZQ\njlqspAkDCW6ZsCc+aqEwkbRlmVoN5Np2Q24JoyspoGXjwBNAQFTM5xAmeBoe\nviYfUdmsuPJzc58DsyHVQKwabq6AEbpMf+1vVf6faxCpD1GGUwYjyyoDJ8KX\na5qBtISjuDe75h+pAf9rakd2ymKptCf+llq0wricqF3Z51uv+DSvL2gG16pZ\nZc8I\r\n=lFwM\r\n-----END PGP SIGNATURE-----\r\n","integrity":"sha512-IzV20vGrR7vg0yFEbw3FkOnC3txg0sBO4wsY7bNjaUAS9oLF1/Qb/9FWGEwlMbshotpbVDZ1nkr4s4TbazEDwA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDq2ejf0FEk+SDgttf/S9mrbGa4g5zpW2a5x42MWmpvIQIgO6UFkwpDKGr5qV/WtCavMjjEu/mMCeHCDICmdydDBP0="}]},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/send-type_0.4.0_1526326992686_0.6954260566855006"},"_hasShrinkwrap":false},"0.5.0":{"name":"@polka/send-type","version":"0.5.0","description":"A response helper that detects & handles Content-Types","repository":{"type":"git","url":"https://github.com/lukeed/polka.git"},"license":"MIT","author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"publishConfig":{"access":"public"},"_id":"@polka/send-type@0.5.0","dist":{"shasum":"ced804fa06d9619ab3ea5c5093da193aea48fa9a","tarball":"https://registry.npmjs.org/@polka/send-type/-/send-type-0.5.0.tgz","integrity":"sha512-TCC0gbR5Cgx4lRHwd9JX3c9qq4EY+TujCYuy+7AvZpeugbLBirDNvq/jD3NZ+MPgHTnvZhbm9nuRTgse9UmNZA==","fileCount":4,"unpackedSize":3520,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJboUE8CRA9TVsSAnZWagAAmKMP/3MlDDTcCB70DCldR9WK\nXFAx26NHKRr3aa3RXA2MxLHJ+W78mY4ubFGC+KKTqAIX4c/PQjFqDCsG4Y+k\nOH7w7X9ez58GlU10j+B00SoPRxIGXO8bn+eghRHLqGOHZn0OAMwlgHhAjy6Z\nBgwcu349s4A/4dpTRj5S2PIu/kAuEuJWGkabNl3GHEwmLH6EPh4mFftzX6Uf\nvMTFpPX4rLhpkJ73lqpHf3p08hytCEI+hFmGDDYfoJXjzprW/OH9t000SSWu\nVamAew71RXq202Odk/cjWTSCIGMVTrKaO3T99i6dJ434a46n84Sj6nM6GVdN\nYY0P6oKq4yh9N+XFN3Ruzz69/ox4Q8qLoamjUUi0pKy25WCp1ilO3rHooNrY\nw8OKRQ1DBhjcgVUwhKsnrGT19tvBUsvmEj2NnQwK4u4Pu76hOET7xbfS5ocE\nkayE2D9vKTdwzLo5cqOFGn/V1/zPZCfzK4vXmyOZJ31b03IoV6KZD8fP7lpk\n/zo7yaTYkiR7pHqHC6E4TJdiaUTZSsQ0XlSpMsOpr9+GJS7vH53FMExV/WSH\nietJRN2/ugP/F/k9g8ohyTBFzF4PvGDAGdjB7LErpeo61XpfG4TePt1PvrVy\nT/dE9+u7+RNOV0K9chGPVfWsTdtPLgMIatgK4ZsYcU4GEHR4sQTv3dhNlS6I\nOwff\r\n=gpXL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBdt5YWfvUtbpGblUlWaU30XaTotiFeandhOCROnHLHmAiA9RoG53Akg7P6it7zYFxhZ6xeQZ5K/tNrOeiwG08jURg=="}]},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/send-type_0.5.0_1537294652002_0.9783003411702178"},"_hasShrinkwrap":false},"0.5.2":{"name":"@polka/send-type","version":"0.5.2","description":"A response helper that detects & handles Content-Types","repository":{"type":"git","url":"https://github.com/lukeed/polka.git"},"license":"MIT","author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"publishConfig":{"access":"public"},"_id":"@polka/send-type@0.5.2","dist":{"shasum":"65ed19522248e894eb9cfabe7ef0f166c10166a9","integrity":"sha512-jGXalKihnhGQmMQ+xxfxrRfI2cWs38TIZuwgYpnbQDD4r9TkOiU3ocjAS+6CqqMNQNAu9Ul2iHU5YFRDODak2w==","tarball":"https://registry.npmjs.org/@polka/send-type/-/send-type-0.5.2.tgz","fileCount":4,"unpackedSize":3966,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcXgwpCRA9TVsSAnZWagAA7dIP/3c3KGcfQsdpwKZELyUd\nIUEmJvE0lS2U1F+qQ6UaLsZngsNCuSt+EFF6ucZslXZY1fuWMcCVKupdHbIc\nhBzmSLQlHFrlImSSElkPQSJ/DycAztMfRpH8EQdr4TdMgBFScaLdDFtTPYoU\nLWa334Reo8JnEHsdV5AkCcTq4L4UsCjblTZwzfSMoe57mf2Vej0mSNyZeW8r\nX48EKqevBiAvWcC5vdJWQLMbbMbzkIgwBBCWRBQyQWkh/l966gqAZcCOTky6\nOF/AfCgo3v8GvXuJZaRUUYSF5+088up6nbArarqaW/B2jQ7mZMNJ3oD6Rcyo\nDsPaIlTG68jN1VsYvBhTHZOtPsWcoEw37nc7UqPh6z2MYaeRAv1OY3ljuwIu\nOV5t42V0S1Uki35S0SFggfSW4r6fn+3XH8FuLR21lxA7rnzfXZepyaqFYUDc\n4C9Bti/QSB2DrUu9hU86LwmUaubjZi5Hhw8oqe1E7TixM6uLZTK8xLwo8eCm\nZKd+xsdn9QY/DH01JXUu2mTJgNYGL8zER9QCxx7LDSYbp6A5f29yJBBL2+l9\n3bDwNwcTgi9MdiYJSFzPfGX0DEhUk0UkrC1aDJCTaL/di48F5XIA+8xEE+Eq\nQaXiQCvm5vJvhB0SK8b41NMbo4BkQl6Bbmn4lDVmUJ1YxviGfQosUgCI5Uix\nstO0\r\n=P1Du\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBg/THfRIVu8dOI4pbWCSppEF5L83iWLzHHX8GuddH+TAiBHUVMIqZjtzoLtxXv7KQONBO7XoD3cXBKguGR4RGBFsA=="}]},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/send-type_0.5.2_1549667368638_0.6219487140606272"},"_hasShrinkwrap":false}},"readme":"# @polka/send-type [![npm](https://img.shields.io/npm/v/@polka/send-type.svg)](https://npmjs.org/package/@polka/send-type)\n\n> An HTTP response helper that detects `Content-Type`s & handles them accordingly &mdash; _not_ limited to [Polka][polka]!\n\nFor a simpler, bare-bones alternative, check out [`@polka/send`][send] instead~\n\n\n## Install\n\n```\n$ npm install --save @polka/send-type\n```\n\n\n## Usage\n\n```js\nconst { createReadStream } = require('fs');\nconst send = require('@polka/send-type');\n\nmodule.exports = function (req, res) {\n  if (!req.getHeader('authorization')) {\n    // Objects are converted to JSON\n    return send(res, 401, { error:'Token required!' });\n  }\n  // Streams & Buffers are auto-piped\n  // Your 'Content-Type' is always used,\n  // ~> otherwise 'application/octet-stream'\n  let file = createReadStream('massive.mp4');\n  send(res, 206, file, { 'Content-Type': 'video/mp4' });\n}\n```\n\n\n## API\n\n### send(res, code, data, headers)\n\n#### res\nType: `ServerReponse`\n\nThe outgoing HTTP response.\n\n#### code\nType: `Number`<br>\nDefault: `200`\n\nThe `statusCode` for your response.\n\n#### data\nType: `String`<br>\nDefault: `''`\n\nThe `body` for your response. Defaults to the `statusText` for the given `statusCode`.\n\nSee [Data Detections](#data-detections) for special behaviors.\n\n#### headers\nType: `Object`<br>\nDefault: `{}`\n\nThe `headers` for your response.\n\nThe `Content-Type` header is a little unique – it will be set with the value you provide in `headers`. However, if you _did not_ set a value explicitly, then `send-type` will reuse the existing value via [`res.getHeader`](https://nodejs.org/api/http.html#http_response_getheader_name).<br>If neither existed, then the `Content-Type` will be inferred by the data type.\n\nSee [Data Detections](#data-detections) for special behaviors.\n\n\n## Data Detections\n\nThe following operations will be performed for the following data types:\n\n> **Important:** If this is too much magic for you, check out [`@polka/send`][send] instead!\n\n### Buffers\n- Sets `Content-Type` to `'application/octet-stream'`, unless one exists in [`headers`](#headers)\n- Sets `Content-Length`\n\n### Objects\n- Casts [`data`](#data) to string via `JSON.stringify`\n- Sets `Content-Type` to `'application/json; charset=utf-8'`, unless one exists in [`headers`](#headers)\n- Sets `Content-Length`\n\n### Streams\n- Sets `Content-Type` to `'application/octet-stream'`, unless one exists in [`headers`](#headers)\n- Pipes [`data`](#data) into the [`res`](#res) directly\n\n\n## Support\n\nAny issues or questions can be sent to the [Polka][polka] repo, but please specify that you are using `@polka/send-type`.\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n\n[polka]: https://github.com/lukeed/polka\n[send]: https://github.com/lukeed/polka/tree/master/packages/send\n","maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"time":{"modified":"2022-06-12T22:43:32.332Z","created":"2018-01-23T22:04:55.011Z","0.3.0":"2018-01-23T22:04:55.011Z","0.3.1":"2018-02-03T04:24:46.590Z","0.3.2":"2018-02-07T02:02:51.857Z","0.3.3":"2018-02-09T19:08:51.821Z","0.3.4":"2018-02-16T22:18:40.687Z","0.4.0":"2018-05-14T19:43:12.790Z","0.5.0":"2018-09-18T18:17:32.480Z","0.5.2":"2019-02-08T23:09:28.773Z"},"repository":{"type":"git","url":"https://github.com/lukeed/polka.git"},"author":{"name":"Luke Edwards","email":"luke@lukeed.com","url":"https://lukeed.com"},"license":"MIT","readmeFilename":"readme.md"}