Skip to content

Commit 1b40042

Browse files
author
Dmitry Shirokov
committed
feat: Make it work in browser
1 parent b176134 commit 1b40042

File tree

6 files changed

+66
-16
lines changed

6 files changed

+66
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules
44
coverage
55
npm-debug.log
66
lib
7+
TODO.md

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# chardet [![Build Status](https://travis-ci.org/runk/node-chardet.png)](https://travis-ci.org/runk/node-chardet)
22

3-
Chardet is a character detection module for NodeJS written in pure Javascript.
4-
Module is based on ICU project http://site.icu-project.org/, which uses character
5-
occurency analysis to determine the most probable encoding.
3+
*Chardet* is a character detection module written in pure Javascript (Typescript). Module uses occurrence analysis to determine the most probable encoding.
4+
5+
- Packed size is only **22 KB**
6+
- Works in all environments: Node / Browser / Native
7+
- Works on all platforms: Linux / Mac / Windows
8+
- No dependencies
9+
- No native code / bindings
10+
- 100% written in Typescript
11+
- Extensive code coverage
612

713
## Installation
814

@@ -87,3 +93,7 @@ Currently only these encodings are supported.
8793
## Typescript?
8894

8995
Yes. Type definitions are included.
96+
97+
### References
98+
99+
- ICU project http://site.icu-project.org/

package.json

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "chardet",
33
"version": "0.0.0-development",
44
"homepage": "https://github.com/runk/node-chardet",
5-
"description": "Character detector",
5+
"description": "Character encoding detector",
66
"license": "MIT",
77
"repository": {
88
"type": "git",
@@ -22,8 +22,8 @@
2222
"prepublish": "npm run build",
2323
"semantic-release": "semantic-release"
2424
},
25-
"main": "lib/index.js",
2625
"files": ["lib"],
26+
"main": "lib/index.js",
2727
"typings": "lib/index.d.ts",
2828
"engine": {
2929
"node": ">=4"
@@ -50,7 +50,38 @@
5050
"utf8",
5151
"detector",
5252
"chardet",
53-
"icu"
53+
"icu",
54+
"character detection",
55+
"character encoding",
56+
"language",
57+
"iconv",
58+
"iconv-light",
59+
"UTF-8",
60+
"UTF-16",
61+
"UTF-32",
62+
"ISO-2022-JP",
63+
"ISO-2022-KR",
64+
"ISO-2022-CN",
65+
"Shift_JIS",
66+
"Big5",
67+
"EUC-JP",
68+
"EUC-KR",
69+
"GB18030",
70+
"ISO-8859-1",
71+
"ISO-8859-2",
72+
"ISO-8859-5",
73+
"ISO-8859-6",
74+
"ISO-8859-7",
75+
"ISO-8859-8",
76+
"ISO-8859-9",
77+
"windows-1250",
78+
"windows-1251",
79+
"windows-1252",
80+
"windows-1253",
81+
"windows-1254",
82+
"windows-1255",
83+
"windows-1256",
84+
"KOI8-R"
5485
],
5586
"author": "Dmitry Shirokov <[email protected]>",
5687
"contributors": [
@@ -59,5 +90,8 @@
5990
"@suisho",
6091
"@seangarner",
6192
"@zevanty"
62-
]
93+
],
94+
"browser": {
95+
"./lib/fs/node.js": "./lib/fs/browser.js"
96+
}
6397
}

src/fs/browser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default () => {
2+
throw new Error('File system is not available');
3+
};

src/fs/node.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let fsModule: any;
2+
3+
export default () => {
4+
if (typeof module === 'object' && typeof module.exports === 'object') {
5+
fsModule = fsModule ? fsModule : require('fs');
6+
return fsModule;
7+
}
8+
throw new Error('File system is not available');
9+
};

src/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
import { Match } from './match';
22
import { Recogniser, Context } from './encoding';
33

4+
import loadFs from './fs/node';
5+
46
import Utf8 from './encoding/utf8';
57
import * as unicode from './encoding/unicode';
68
import * as mbcs from './encoding/mbcs';
79
import * as sbcs from './encoding/sbcs';
810
import * as iso2022 from './encoding/iso2022';
911

10-
let fsModule: any;
11-
const loadFs = () => {
12-
if (typeof module === 'object' && typeof module.exports === 'object') {
13-
fsModule = fsModule ? fsModule : require('fs');
14-
return fsModule;
15-
}
16-
throw new Error('File system is not available');
17-
}
18-
1912
interface FullOptions {
2013
sampleSize: number
2114
}

0 commit comments

Comments
 (0)