Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fb55/encoding-sniffer
HTML encoding sniffer, with stream support
https://github.com/fb55/encoding-sniffer
encoding-sniffer html html-specification nodejs-streams
Last synced: 3 months ago
JSON representation
HTML encoding sniffer, with stream support
- Host: GitHub
- URL: https://github.com/fb55/encoding-sniffer
- Owner: fb55
- License: mit
- Created: 2021-10-30T17:10:29.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-05-28T19:45:13.000Z (8 months ago)
- Last Synced: 2024-05-29T10:39:46.556Z (8 months ago)
- Topics: encoding-sniffer, html, html-specification, nodejs-streams
- Language: TypeScript
- Homepage:
- Size: 1.81 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# encoding-sniffer [![Node.js CI](https://github.com/fb55/encoding-sniffer/actions/workflows/nodejs-test.yml/badge.svg)](https://github.com/fb55/encoding-sniffer/actions/workflows/nodejs-test.yml)
An implementation of the HTML encoding sniffer algo, with stream support.
This module wraps around [iconv-lite](https://github.com/ashtuchkin/iconv-lite)
to make decoding buffers and streams incredibly easy.## Features
- Support for streams
- Support for XML encoding types, including UTF-16 prefixes and
``
- Allows decoding streams and buffers with a single function call## Installation
```bash
npm install encoding-sniffer
```## Usage
```js
import { DecodeStream, getEncoding, decodeBuffer } from "encoding-sniffer";/**
* All functions accept an optional options object.
*
* Available options are (with default values):
*/
const options = {
/**
* The maximum number of bytes to sniff. Defaults to `1024`.
*/
maxBytes: 1024,
/**
* The encoding specified by the user. If set, this will only be overridden
* by a Byte Order Mark (BOM).
*/
userEncoding: undefined,
/**
* The encoding specified by the transport layer. If set, this will only be
* overridden by a Byte Order Mark (BOM) or the user encoding.
*/
transportLayerEncodingLabel: undefined,
/**
* The default encoding to use, if no encoding can be detected.
*
* Defaults to `"windows-1252"`.
*/
defaultEncoding: "windows-1252",
};// Use the `DecodeStream` transform stream to automatically decode
// the contents of a stream as they are read
const decodeStream = new DecodeStream(options);// Or, use the `getEncoding` function to detect the encoding of a buffer
const encoding = getEncoding(buffer, options);// Use the `decodeBuffer` function to decode the contents of a buffer
const decodedBuffer = decodeBuffer(buffer, options);
```## License
This project is licensed under the MIT License. See the [LICENSE](/LICENSE) file
for more information.