demo___customer_pitch-c4152739-a50b-4b5b-9d4d-0561461666d9.zip-extract/_dependencies/npm/accepts-1.3.8/README.md

Path
demo___customer_pitch-c4152739-a50b-4b5b-9d4d-0561461666d9.zip-extract/_dependencies/npm/accepts-1.3.8/README.md
Status
scanned
Type
file
Name
README.md
Extension
.md
Programming language

      
    
Mime type
text/plain
File type
ASCII text
Tag

      
    
Rootfs path

      
    
Size
4123 (4.0 KB)
MD5
873e624d40d23cf9b54f9d2f74d2c8d1
SHA1
3a884510d2eeed73a4cd5ae0947a6c72cd3c7426
SHA256
c25a1071e5aa1b1b43e10f083e8d97c3dbf1f7700cfa38b5cbc40725662e1ae0
SHA512

      
    
SHA1_git
82680c530c3886540f630f643990e2ec707319d1
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
README.md | 4.0 KB |

# accepts [![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url] [![Node.js Version][node-version-image]][node-version-url] [![Build Status][github-actions-ci-image]][github-actions-ci-url] [![Test Coverage][coveralls-image]][coveralls-url] Higher level content negotiation based on [negotiator](https://www.npmjs.com/package/negotiator). Extracted from [koa](https://www.npmjs.com/package/koa) for general use. In addition to negotiator, it allows: - Allows types as an array or arguments list, ie `(['text/html', 'application/json'])` as well as `('text/html', 'application/json')`. - Allows type shorthands such as `json`. - Returns `false` when no types match - Treats non-existent headers as `*` ## Installation This is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/). Installation is done using the [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): ```sh $ npm install accepts ``` ## API ```js var accepts = require('accepts') ``` ### accepts(req) Create a new `Accepts` object for the given `req`. #### .charset(charsets) Return the first accepted charset. If nothing in `charsets` is accepted, then `false` is returned. #### .charsets() Return the charsets that the request accepts, in the order of the client's preference (most preferred first). #### .encoding(encodings) Return the first accepted encoding. If nothing in `encodings` is accepted, then `false` is returned. #### .encodings() Return the encodings that the request accepts, in the order of the client's preference (most preferred first). #### .language(languages) Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned. #### .languages() Return the languages that the request accepts, in the order of the client's preference (most preferred first). #### .type(types) Return the first accepted type (and it is returned as the same text as what appears in the `types` array). If nothing in `types` is accepted, then `false` is returned. The `types` array can contain full MIME types or file extensions. Any value that is not a full MIME types is passed to `require('mime-types').lookup`. #### .types() Return the types that the request accepts, in the order of the client's preference (most preferred first). ## Examples ### Simple type negotiation This simple example shows how to use `accepts` to return a different typed respond body based on what the client wants to accept. The server lists it's preferences in order and will get back the best match between the client and server. ```js var accepts = require('accepts') var http = require('http') function app (req, res) { var accept = accepts(req) // the order of this list is significant; should be server preferred order switch (accept.type(['json', 'html'])) { case 'json': res.setHeader('Content-Type', 'application/json') res.write('{"hello":"world!"}') break case 'html': res.setHeader('Content-Type', 'text/html') res.write('<b>hello, world!</b>') break default: // the fallback is text/plain, so no need to specify it above res.setHeader('Content-Type', 'text/plain') res.write('hello, world!') break } res.end() } http.createServer(app).listen(3000) ``` You can test this out with the cURL program: ```sh curl -I -H'Accept: text/html' http://localhost:3000/ ``` ## License [MIT](LICENSE) [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/accepts/master [coveralls-url]: https://coveralls.io/r/jshttp/accepts?branch=master [github-actions-ci-image]: https://badgen.net/github/checks/jshttp/accepts/master?label=ci [github-actions-ci-url]: https://github.com/jshttp/accepts/actions/workflows/ci.yml [node-version-image]: https://badgen.net/npm/node/accepts [node-version-url]: https://nodejs.org/en/download [npm-downloads-image]: https://badgen.net/npm/dm/accepts [npm-url]: https://npmjs.org/package/accepts [npm-version-image]: https://badgen.net/npm/v/accepts
Detected license expression
mit
Detected license expression (SPDX)
MIT
Percentage of license text
0.5
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
mit-bdcba66f-6e80-f7bd-7994-748183fe5693 mit MIT
URL Start line End line
https://www.npmjs.com/package/negotiator 9 9
https://www.npmjs.com/package/koa 10 10
https://nodejs.org/en 22 22
https://www.npmjs.com/ 23 23
https://docs.npmjs.com/getting-started/installing-npm-packages-locally 24 24
https://badgen.net/coveralls/c/github/jshttp/accepts/master 132 132
https://coveralls.io/r/jshttp/accepts?branch=master 133 133
https://badgen.net/github/checks/jshttp/accepts/master?label=ci 134 134
https://github.com/jshttp/accepts/actions/workflows/ci.yml 135 135
https://badgen.net/npm/node/accepts 136 136
https://nodejs.org/en/download 137 137
https://badgen.net/npm/dm/accepts 138 138
https://npmjs.org/package/accepts 139 139
https://badgen.net/npm/v/accepts 140 140
Package URL License Primary language
pkg:npm/acme-demo-app@1.0.0 JavaScript
pkg:npm/accepts@1.3.8 mit JavaScript