-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes5.html
32 lines (27 loc) · 1.08 KB
/
es5.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
</head>
<body>
<script src="../dist/es5/chardetng.es5.min.js"></script>
<script>
// wasm loading is asynchronous so it cannot be used immediately
chardetng.onReady(function() {
// detect from a string
console.log(chardetng.detect('\u00a0'));
// or a Uint8TypedArray
var enc = new TextEncoder();
console.log(chardetng.detect(enc.encode('this is a test')));
// note that this portion of the API mirrors
// https://docs.rs/chardetng/0.1.10/chardetng/struct.EncodingDetector.html
var detector = chardetng.EncodingDetector.new();
// detector.feed(buffer, isLast = false)
detector.feed('this is a test');
detector.feed(enc.encode('of feeding multiple buffers'), true); // true because we are finished
// detector.guess(topLevelDomain = 'com', allowUTF8 = false)
console.log(detector.guess());
console.log(detector.guess(undefined, true));
});
</script>
</body>
</html>