generated from Richienb/typescript-quickstart
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Richie Bendall <[email protected]>
- Loading branch information
Showing
9 changed files
with
77 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# Build directories | ||
dist/ | ||
docs/ | ||
|
||
# Lock files | ||
package-lock.json | ||
|
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 |
---|---|---|
@@ -1,23 +1,33 @@ | ||
# Fetch Charset Detection | ||
# fetch-charset-detection [![Travis CI Build Status](https://img.shields.io/travis/com/Richienb/fetch-charset-detection/master.svg?style=for-the-badge)](https://travis-ci.com/Richienb/fetch-charset-detection) | ||
|
||
> Charset detection and conversion, originally from `node-fetch`. | ||
[![Build Status](https://travis-ci.com/node-fetch/fetch-charset-detection.svg?branch=master)](https://travis-ci.com/node-fetch/fetch-charset-detection) | ||
Detect the encoding of a buffer and stringify it. Originally from [node-fetch](https://github.com/node-fetch/node-fetch) | ||
|
||
## Install | ||
|
||
``` | ||
```sh | ||
npm install fetch-charset-detection | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
const convertBody = require("fetch-charset-detection"); | ||
const convertBody = require("fetch-charset-detection") | ||
|
||
convertBody(data, headers); | ||
convertBody(content) | ||
``` | ||
|
||
## API | ||
|
||
Refer to the [documentation](https://richienb.github.io/fetch-charset-detection). | ||
### convertBody(content, headers?) | ||
|
||
#### content | ||
|
||
Type: `Buffer` | ||
|
||
The content to stringify. | ||
|
||
#### headers | ||
|
||
Type: [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) | ||
|
||
The HTTP headers provided with the 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 |
---|---|---|
@@ -1,53 +1,65 @@ | ||
{ | ||
"name": "fetch-charset-detection", | ||
"description": "Charset detection and conversion utilities, originally from node-fetch.", | ||
"keywords": [ | ||
"content-type", | ||
"headers", | ||
"http", | ||
"meta", | ||
"node-fetch" | ||
], | ||
"version": "0.0.0", | ||
"main": "dist/index.js", | ||
"description": "Detect the encoding of a buffer and stringify it.", | ||
"repository": "https://github.com/Richienb/fetch-charset-detection.git", | ||
"author": "Richie Bendall <[email protected]>", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"files": [ | ||
"dist" | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"repository": "https://github.com/Richienb/fetch-charset-detection.git", | ||
"author": "Richie Bendall <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"docs": "typedoc", | ||
"build": "tsc && typedoc", | ||
"build": "tsc", | ||
"dev": "tsc --watch", | ||
"lint": "xo", | ||
"test": "xo && ava" | ||
}, | ||
"keywords": [ | ||
"content-type", | ||
"headers", | ||
"http", | ||
"meta", | ||
"parse", | ||
"buffer", | ||
"node-fetch" | ||
], | ||
"dependencies": { | ||
"cheerio": "^1.0.0-rc.3", | ||
"content-type": "^1.0.4", | ||
"iconv-lite": "^0.6.2", | ||
"nice-try": "^2.0.1" | ||
"iconv-lite": "^0.6.2" | ||
}, | ||
"devDependencies": { | ||
"@richienb/tsconfig": "^0.1.1", | ||
"@richienb/typedoc": "^0.1.1", | ||
"@types/cheerio": "^0.22.21", | ||
"@types/content-type": "^1.1.3", | ||
"@types/nice-try": "^2.0.0", | ||
"@typescript-eslint/eslint-plugin": "^4.1.1", | ||
"@typescript-eslint/parser": "^4.1.1", | ||
"ava": "^3.12.1", | ||
"eslint-config-richienb": "^0.4.2", | ||
"node-fetch": "^2.6.0", | ||
"eslint-config-xo-typescript": "^0.32.0", | ||
"node-fetch": "^2.6.1", | ||
"ts-node": "^9.0.0", | ||
"typedoc": "^0.19.0", | ||
"typescript": "^4.0.2", | ||
"xo": "^0.33.0" | ||
"xo": "^0.33.1" | ||
}, | ||
"xo": { | ||
"extends": "richienb" | ||
"extends": "richienb", | ||
"rules": { | ||
"node/no-missing-import": 0 | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": "test.ts", | ||
"rules": { | ||
"@typescript-eslint/no-unsafe-call": 0 | ||
} | ||
} | ||
] | ||
}, | ||
"ava": { | ||
"extensions": [ | ||
|
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
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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import {parse} from "content-type" | ||
import niceTry from "nice-try" | ||
import { parse } from "content-type" | ||
|
||
/** | ||
Get the character set from a Content-Type header. | ||
@param contentType The Content-Type HTTP header. | ||
*/ | ||
function parseContentType(contentType: string) { | ||
return niceTry(() => parse(contentType))?.parameters?.charset ?? contentType | ||
try { | ||
return parse(contentType).parameters.charset | ||
} catch (_) { | ||
return contentType | ||
} | ||
} | ||
|
||
export = parseContentType |
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 was deleted.
Oops, something went wrong.