# detconv

> Detective character encoding conversion

Latest version **1.2.0** (published 2017-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install detconv
pnpm add detconv
yarn add detconv
bun add detconv
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2017-05-31 |
| First published | 2017-05-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | ayatoy |
| Maintainers | ayatoy |
| Keywords | encoding, charset, convert |

## Links

- npm: https://www.npmjs.com/package/detconv
- Repository: https://github.com/ayatoy/detconv
- Homepage: https://github.com/ayatoy/detconv#readme
- Issues: https://github.com/ayatoy/detconv/issues
- npm.io page: https://npm.io/package/detconv

## Dependencies (2)

- [jschardet](https://npm.io/package/jschardet.md) ^1.4.2
- [iconv-lite](https://npm.io/package/iconv-lite.md) ^0.4.17

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads
- [datasets-fi-postalcodes](https://npm.io/package/datasets-fi-postalcodes.md) — 1.1K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2017-05-31
- 1.1.1 — 2017-05-17
- 1.1.0 — 2017-05-17
- 1.0.0 — 2017-05-15

## README

## Detective character encoding conversion for Node.js [![Build Status](https://travis-ci.org/ayatoy/detconv.svg?branch=master)](https://travis-ci.org/ayatoy/detconv)

Just combined [jschardet](https://github.com/aadsm/jschardet) and [iconv-lite](https://github.com/ashtuchkin/iconv-lite).

[![NPM](https://nodei.co/npm/detconv.png?compact=true)](https://nodei.co/npm/detconv/)

## Usage

### Function

#### detconv.convert(input[, encoding[, confidence]])

* `input` - Buffer or string. If a Buffer, it tries to detect the encoding. If a string, it will be interpreted as is without attempting to detect it.
* `encoding` - output encoding. `detconv.convert` usually returns an encoded buffer, but if `'string'`, it returns a string without conversion. Default is `'utf-8'`.
* `confidence` - acceptable accuracy. Greater then or equal to 0, less then or equal to 1. Closer to 1 is, higher accuracy required. If not specified, any accuracy is acceptable.

```javascript
const detconv = require('detconv');

const unknownEncodedBuffer = Buffer.from(…);

const utf8EncodedBuffer = detconv.convert(unknownEncodedBuffer, 'utf-8');
```

An exception is thrown in the following cases:
* `input` other than Buffer or string is given.
* Encoding can not be detected.
* Detected accuracy is less than `confidence`.
* Detected encodings is not supported by iconv-lite.
* `encoding` is not supported by iconv-lite.

### Transform stream

#### detconv.convertStream([encoding[, confidence]])

```javascript
const detconv = require('detconv');

const unknownEncodedReadStream = getUnknownEncodedReadStream();

const someWriteStream = getSomeWriteStream();

const detectAndConvert = detconv.convertStream('utf-8');

unknownEncodedReadStream.pipe(detectAndConvert).pipe(someWriteStream);
```

The 'error' event is emitted in the following cases:
* When chunk other than Buffer or string is given.
* `detconv.convert()` throws an exception (because it is used in the implementation).

Depending on the characteristics of the detection method, all of the input chunks are concatenated and buffered. Please be aware that a footprint will be generated according to the input size and output will not occur unless the input is completed.

## Supported encodings

Encodings that can be input are those supported by [jschardet](https://github.com/aadsm/jschardet) and [iconv-lite](https://github.com/ashtuchkin/iconv-lite). Encodings that can be output are those supported by [iconv-lite](https://github.com/ashtuchkin/iconv-lite). In addition, both input and output can be string.

## Test

```bash
$ git clone https://github.com/ayatoy/detconv.git
$ cd detconv
$ npm install
$ npm test
```

## License

MIT

---
_Source: https://npm.io/package/detconv · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
