Merge pull request #39 from runk/browser-like-env
feat: Make it work in browser
This commit is contained in:
commit
3fe63a19ac
|
@ -4,3 +4,4 @@ node_modules
|
|||
coverage
|
||||
npm-debug.log
|
||||
lib
|
||||
TODO.md
|
||||
|
|
16
README.md
16
README.md
|
@ -1,8 +1,14 @@
|
|||
# chardet [![Build Status](https://travis-ci.org/runk/node-chardet.png)](https://travis-ci.org/runk/node-chardet)
|
||||
|
||||
Chardet is a character detection module for NodeJS written in pure Javascript.
|
||||
Module is based on ICU project http://site.icu-project.org/, which uses character
|
||||
occurency analysis to determine the most probable encoding.
|
||||
*Chardet* is a character detection module written in pure Javascript (Typescript). Module uses occurrence analysis to determine the most probable encoding.
|
||||
|
||||
- Packed size is only **22 KB**
|
||||
- Works in all environments: Node / Browser / Native
|
||||
- Works on all platforms: Linux / Mac / Windows
|
||||
- No dependencies
|
||||
- No native code / bindings
|
||||
- 100% written in Typescript
|
||||
- Extensive code coverage
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -87,3 +93,7 @@ Currently only these encodings are supported.
|
|||
## Typescript?
|
||||
|
||||
Yes. Type definitions are included.
|
||||
|
||||
### References
|
||||
|
||||
- ICU project http://site.icu-project.org/
|
||||
|
|
42
package.json
42
package.json
|
@ -2,7 +2,7 @@
|
|||
"name": "chardet",
|
||||
"version": "0.0.0-development",
|
||||
"homepage": "https://github.com/runk/node-chardet",
|
||||
"description": "Character detector",
|
||||
"description": "Character encoding detector",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -22,8 +22,8 @@
|
|||
"prepublish": "npm run build",
|
||||
"semantic-release": "semantic-release"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"files": ["lib"],
|
||||
"main": "lib/index.js",
|
||||
"typings": "lib/index.d.ts",
|
||||
"engine": {
|
||||
"node": ">=4"
|
||||
|
@ -50,7 +50,38 @@
|
|||
"utf8",
|
||||
"detector",
|
||||
"chardet",
|
||||
"icu"
|
||||
"icu",
|
||||
"character detection",
|
||||
"character encoding",
|
||||
"language",
|
||||
"iconv",
|
||||
"iconv-light",
|
||||
"UTF-8",
|
||||
"UTF-16",
|
||||
"UTF-32",
|
||||
"ISO-2022-JP",
|
||||
"ISO-2022-KR",
|
||||
"ISO-2022-CN",
|
||||
"Shift_JIS",
|
||||
"Big5",
|
||||
"EUC-JP",
|
||||
"EUC-KR",
|
||||
"GB18030",
|
||||
"ISO-8859-1",
|
||||
"ISO-8859-2",
|
||||
"ISO-8859-5",
|
||||
"ISO-8859-6",
|
||||
"ISO-8859-7",
|
||||
"ISO-8859-8",
|
||||
"ISO-8859-9",
|
||||
"windows-1250",
|
||||
"windows-1251",
|
||||
"windows-1252",
|
||||
"windows-1253",
|
||||
"windows-1254",
|
||||
"windows-1255",
|
||||
"windows-1256",
|
||||
"KOI8-R"
|
||||
],
|
||||
"author": "Dmitry Shirokov <deadrunk@gmail.com>",
|
||||
"contributors": [
|
||||
|
@ -59,5 +90,8 @@
|
|||
"@suisho",
|
||||
"@seangarner",
|
||||
"@zevanty"
|
||||
]
|
||||
],
|
||||
"browser": {
|
||||
"./lib/fs/node.js": "./lib/fs/browser.js"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export default () => {
|
||||
throw new Error('File system is not available');
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
let fsModule: any;
|
||||
|
||||
export default () => {
|
||||
if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
fsModule = fsModule ? fsModule : require('fs');
|
||||
return fsModule;
|
||||
}
|
||||
throw new Error('File system is not available');
|
||||
};
|
11
src/index.ts
11
src/index.ts
|
@ -1,21 +1,14 @@
|
|||
import { Match } from './match';
|
||||
import { Recogniser, Context } from './encoding';
|
||||
|
||||
import loadFs from './fs/node';
|
||||
|
||||
import Utf8 from './encoding/utf8';
|
||||
import * as unicode from './encoding/unicode';
|
||||
import * as mbcs from './encoding/mbcs';
|
||||
import * as sbcs from './encoding/sbcs';
|
||||
import * as iso2022 from './encoding/iso2022';
|
||||
|
||||
let fsModule: any;
|
||||
const loadFs = () => {
|
||||
if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
fsModule = fsModule ? fsModule : require('fs');
|
||||
return fsModule;
|
||||
}
|
||||
throw new Error('File system is not available');
|
||||
}
|
||||
|
||||
interface FullOptions {
|
||||
sampleSize: number
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue