-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f69c19e
commit 238eedd
Showing
4 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"name": "accepts", | ||
"description": "Higher-level content negotiation", | ||
"version": "1.3.8", | ||
"types": "types/index.d.ts", | ||
"contributors": [ | ||
"Douglas Christopher Wilson <[email protected]>", | ||
"Jonathan Ong <[email protected]> (http://jongleberry.com)" | ||
|
@@ -13,6 +14,7 @@ | |
"negotiator": "0.6.3" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "18.11.18", | ||
"deep-equal": "1.0.1", | ||
"eslint": "7.32.0", | ||
"eslint-config-standard": "14.1.1", | ||
|
@@ -22,12 +24,14 @@ | |
"eslint-plugin-promise": "4.3.1", | ||
"eslint-plugin-standard": "4.1.0", | ||
"mocha": "9.2.0", | ||
"nyc": "15.1.0" | ||
"nyc": "15.1.0", | ||
"tsd": "^0.25.0" | ||
}, | ||
"files": [ | ||
"LICENSE", | ||
"HISTORY.md", | ||
"index.js" | ||
"index.js", | ||
"types/index.d.ts" | ||
], | ||
"engines": { | ||
"node": ">= 0.6" | ||
|
@@ -36,7 +40,8 @@ | |
"lint": "eslint .", | ||
"test": "mocha --reporter spec --check-leaks --bail test/", | ||
"test-ci": "nyc --reporter=lcov --reporter=text npm test", | ||
"test-cov": "nyc --reporter=html --reporter=text npm test" | ||
"test-cov": "nyc --reporter=html --reporter=text npm test", | ||
"test-typescript": "tsd" | ||
}, | ||
"keywords": [ | ||
"content", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/// <reference types="node" /> | ||
|
||
import { IncomingMessage } from "http"; | ||
|
||
declare namespace accepts { | ||
interface Accepts { | ||
/** | ||
* Return the first accepted charset. If nothing in `charsets` is accepted, then `false` is returned. | ||
* If no charsets are supplied, all accepted charsets are returned, in the order of the client's preference | ||
* (most preferred first). | ||
*/ | ||
charset(): string[]; | ||
charset(charsets: string[]): string | string[] | false; | ||
charset(...charsets: string[]): string | string[] | false; | ||
|
||
/** | ||
* Return the first accepted charset. If nothing in `charsets` is accepted, then `false` is returned. | ||
* If no charsets are supplied, all accepted charsets are returned, in the order of the client's preference | ||
* (most preferred first). | ||
*/ | ||
charsets(): string[]; | ||
charsets(charsets: string[]): string | string[] | false; | ||
charsets(...charsets: string[]): string | string[] | false; | ||
|
||
/** | ||
* Return the first accepted encoding. If nothing in `encodings` is accepted, then `false` is returned. | ||
* If no encodings are supplied, all accepted encodings are returned, in the order of the client's preference | ||
* (most preferred first). | ||
*/ | ||
encoding(): string[]; | ||
encoding(encodings: string[]): string | string[] | false; | ||
encoding(...encodings: string[]): string | string[] | false; | ||
|
||
/** | ||
* Return the first accepted encoding. If nothing in `encodings` is accepted, then `false` is returned. | ||
* If no encodings are supplied, all accepted encodings are returned, in the order of the client's preference | ||
* (most preferred first). | ||
*/ | ||
encodings(): string[]; | ||
encodings(encodings: string[]): string | string[] | false; | ||
encodings(...encodings: string[]): string | string[] | false; | ||
|
||
/** | ||
* Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned. | ||
* If no languaes are supplied, all accepted languages are returned, in the order of the client's preference | ||
* (most preferred first). | ||
*/ | ||
language(): string[]; | ||
language(languages: string[]): string | string[] | false; | ||
language(...languages: string[]): string | string[] | false; | ||
|
||
/** | ||
* Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned. | ||
* If no languaes are supplied, all accepted languages are returned, in the order of the client's preference | ||
* (most preferred first). | ||
*/ | ||
languages(): string[]; | ||
languages(languages: string[]): string | string[] | false; | ||
languages(...languages: string[]): string | string[] | false; | ||
|
||
/** | ||
* Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned. | ||
* If no languaes are supplied, all accepted languages are returned, in the order of the client's preference | ||
* (most preferred first). | ||
*/ | ||
lang(): string[]; | ||
lang(languages: string[]): string | string[] | false; | ||
lang(...languages: string[]): string | string[] | false; | ||
|
||
/** | ||
* Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned. | ||
* If no languaes are supplied, all accepted languages are returned, in the order of the client's preference | ||
* (most preferred first). | ||
*/ | ||
langs(): string[]; | ||
langs(languages: string[]): string | string[] | false; | ||
langs(...languages: string[]): string | string[] | false; | ||
|
||
/** | ||
* 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. | ||
* If no types are supplied, return the entire set of acceptable types. | ||
* | ||
* 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`. | ||
*/ | ||
type(types: string[]): string | string[] | false; | ||
type(...types: string[]): string | string[] | false; | ||
types(types: string[]): string | string[] | false; | ||
types(...types: string[]): string | string[] | false; | ||
} | ||
} | ||
|
||
declare function accepts(req: IncomingMessage): accepts.Accepts; | ||
|
||
export = accepts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import accepts from ".."; | ||
|
||
const req: any = {}; | ||
|
||
const accept = accepts(req); | ||
|
||
const charsets = accept.charsets(); | ||
const charsetFromEmpty = accept.charset(); | ||
const charsetFromEmptyArray = accept.charset([]); | ||
const charsetFromParams = accept.charset("json", "text"); | ||
const charsetFromArray = accept.charset(["json", "txt"]); | ||
|
||
const encodings = accept.encodings(); | ||
const encodingFromEmpty = accept.encoding(); | ||
const encodingFromEmptyArray = accept.encoding([]); | ||
const encodingFromParams = accept.encoding("json", "text"); | ||
const encodingFromArray = accept.encoding(["json", "text"]); | ||
|
||
const languages = accept.languages(); | ||
const languageFromEmpty = accept.language(); | ||
const languageFromEmptyArray = accept.language([]); | ||
const languageFromParams = accept.language("json", "text"); | ||
const languageFromArray = accept.language(["json", "text"]); | ||
|
||
const types = accept.types(); | ||
const typeFromEmpty = accept.type(); | ||
const typeFromEmptyArray = accept.type([]); | ||
const typeFromParams = accept.type("json", "text"); | ||
const typeFromArray = accept.type(["json", "text"]); |