Skip to content

Commit

Permalink
restore browser compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
rkusa committed Mar 31, 2012
1 parent c921dac commit bf0e585
Show file tree
Hide file tree
Showing 38 changed files with 111 additions and 105 deletions.
1 change: 1 addition & 0 deletions index.js
@@ -0,0 +1 @@
module.exports = require('./src')
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jschardet",
"version": "1.0.0",
"version": "1.0.1",
"description": "Character encoding auto-detection in JavaScript (port of python's chardet)",
"main": "src/init",
"author": "António Afonso",
Expand Down
4 changes: 2 additions & 2 deletions src/big5freq.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

// Big5 frequency table
// by Taiwan's Mandarin Promotion Council
Expand Down Expand Up @@ -926,4 +926,4 @@ jschardet.Big5CharToFreqOrder = [
13952,13953,13954,13955,13956,13957,13958,13959,13960,13961,13962,13963,13964,13965,13966,13967, //13968
13968,13969,13970,13971,13972]; //13973

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/big5prober.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.Big5Prober = function() {
jschardet.MultiByteCharSetProber.apply(this);
Expand All @@ -48,4 +48,4 @@ jschardet.Big5Prober = function() {
}
jschardet.Big5Prober.prototype = new jschardet.MultiByteCharSetProber();

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/chardistribution.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.CharDistributionAnalysis = function() {
var ENOUGH_DATA_THRESHOLD = 1024;
Expand Down Expand Up @@ -280,4 +280,4 @@ jschardet.EUCJPDistributionAnalysis = function() {
}
jschardet.EUCJPDistributionAnalysis.prototype = new jschardet.CharDistributionAnalysis();

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/charsetgroupprober.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.CharSetGroupProber = function() {
jschardet.CharSetProber.apply(this);
Expand Down Expand Up @@ -115,4 +115,4 @@ jschardet.CharSetGroupProber = function() {
}
jschardet.CharSetGroupProber.prototype = new jschardet.CharSetProber();

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/charsetprober.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.CharSetProber = function() {
this.reset = function() {
Expand Down Expand Up @@ -65,4 +65,4 @@ jschardet.CharSetProber = function() {
}
}

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/codingstatemachine.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.CodingStateMachine = function(sm) {
var self = this;
Expand Down Expand Up @@ -68,4 +68,4 @@ jschardet.CodingStateMachine = function(sm) {
init(sm);
}

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/constants.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.Constants = {
_debug : false,
Expand All @@ -43,4 +43,4 @@ jschardet.Constants = {
SHORTCUT_THRESHOLD : 0.95
};

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/escprober.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.EscCharSetProber = function() {
jschardet.CharSetProber.apply(this);
Expand Down Expand Up @@ -95,4 +95,4 @@ jschardet.EscCharSetProber = function() {
}
jschardet.EscCharSetProber.prototype = new jschardet.CharSetProber();

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/escsm.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.HZ_cls = [
1,0,0,0,0,0,0,0, // 00 - 07
Expand Down Expand Up @@ -253,4 +253,4 @@ jschardet.ISO2022KRSMModel = {
"name" : "ISO-2022-KR"
};

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/eucjpprober.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.EUCJPProber = function() {
jschardet.MultiByteCharSetProber.apply(this);
Expand Down Expand Up @@ -99,4 +99,4 @@ jschardet.EUCJPProber = function() {
}
jschardet.EUCJPProber.prototype = new jschardet.MultiByteCharSetProber();

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/euckrfreq.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

// Sampling from about 20M text materials include literature and computer technology

Expand Down Expand Up @@ -598,4 +598,4 @@ jschardet.EUCKRCharToFreqOrder = [
8736,8737,8738,8739,8740,8741
];

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/euckrprober.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.EUCKRProber = function() {
jschardet.MultiByteCharSetProber.apply(this);
Expand All @@ -48,4 +48,4 @@ jschardet.EUCKRProber = function() {
}
jschardet.EUCKRProber.prototype = new jschardet.MultiByteCharSetProber();

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/euctwfreq.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

// EUCTW frequency table
// Converted from big5 work
Expand Down Expand Up @@ -430,4 +430,4 @@ jschardet.EUCTWCharToFreqOrder = [
8726,8727,8728,8729,8730,8731,8732,8733,8734,8735,8736,8737,8738,8739,8740,8741
]; // 8742

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/euctwprober.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.EUCTWProber = function() {
jschardet.MultiByteCharSetProber.apply(this);
Expand All @@ -48,4 +48,4 @@ jschardet.EUCTWProber = function() {
}
jschardet.EUCTWProber.prototype = new jschardet.MultiByteCharSetProber();

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/gb2312freq.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

// GB2312 most frequently used character table
//
Expand Down Expand Up @@ -474,4 +474,4 @@ jschardet.GB2312CharToFreqOrder = [
4866,4899,6099,6100,5559,6478,6765,3599,5868,6101,5869,5870,6275,6766,4527,6767
];

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/gb2312prober.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

jschardet.GB2312Prober = function() {
jschardet.MultiByteCharSetProber.apply(this);
Expand All @@ -48,4 +48,4 @@ jschardet.GB2312Prober = function() {
}
jschardet.GB2312Prober.prototype = new jschardet.MultiByteCharSetProber();

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
4 changes: 2 additions & 2 deletions src/hebrewprober.js
Expand Up @@ -27,7 +27,7 @@
* 02110-1301 USA
*/

module.exports = function(jschardet) {
!function(jschardet) {

// This prober doesn't actually recognize a language or a charset.
// It is a helper prober for the use of the Hebrew model probers
Expand Down Expand Up @@ -319,4 +319,4 @@ if (!Array.prototype.indexOf)
};
}

}
}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
1 change: 1 addition & 0 deletions src/index.js
@@ -0,0 +1 @@
module.exports = require('./init')
76 changes: 40 additions & 36 deletions src/init.js
Expand Up @@ -27,48 +27,52 @@
* 02110-1301 USA
*/

var jschardet = exports;
var jschardet = {};

require('./constants')(jschardet);
require('./codingstatemachine')(jschardet);
require('./escsm')(jschardet);
require('./mbcssm')(jschardet);
require('./charsetprober')(jschardet);
require('./mbcharsetprober')(jschardet);
require('./jisfreq')(jschardet);
require('./gb2312freq')(jschardet);
require('./euckrfreq')(jschardet);
require('./big5freq')(jschardet);
require('./euctwfreq')(jschardet);
require('./chardistribution')(jschardet);
require('./jpcntx')(jschardet);
require('./sjisprober')(jschardet);
require('./utf8prober')(jschardet);
require('./charsetgroupprober')(jschardet);
require('./eucjpprober')(jschardet);
require('./gb2312prober')(jschardet);
require('./euckrprober')(jschardet);
require('./big5prober')(jschardet);
require('./euctwprober')(jschardet);
require('./mbcsgroupprober')(jschardet);
require('./sbcharsetprober')(jschardet);
require('./langgreekmodel')(jschardet);
require('./langthaimodel')(jschardet);
require('./langbulgarianmodel')(jschardet);
require('./langcyrillicmodel')(jschardet);
require('./hebrewprober')(jschardet);
require('./langhebrewmodel')(jschardet);
require('./langhungarianmodel')(jschardet);
require('./sbcsgroupprober')(jschardet);
require('./latin1prober')(jschardet);
require('./escprober')(jschardet);
require('./universaldetector')(jschardet);
if (typeof process !== 'undefined' && typeof process.title !== 'undefined')
{
jschardet = exports;
require('./constants');
require('./codingstatemachine');
require('./escsm');
require('./mbcssm');
require('./charsetprober');
require('./mbcharsetprober');
require('./jisfreq');
require('./gb2312freq');
require('./euckrfreq');
require('./big5freq');
require('./euctwfreq');
require('./chardistribution');
require('./jpcntx');
require('./sjisprober');
require('./utf8prober');
require('./charsetgroupprober');
require('./eucjpprober');
require('./gb2312prober');
require('./euckrprober');
require('./big5prober');
require('./euctwprober');
require('./mbcsgroupprober');
require('./sbcharsetprober');
require('./langgreekmodel');
require('./langthaimodel');
require('./langbulgarianmodel');
require('./langcyrillicmodel');
require('./hebrewprober');
require('./langhebrewmodel');
require('./langhungarianmodel');
require('./sbcsgroupprober');
require('./latin1prober');
require('./escprober');
require('./universaldetector');
}

jschardet.VERSION = "0.1";
jschardet.detect = function(buffer) {
var u = new jschardet.UniversalDetector();
u.reset();
if( buffer instanceof Buffer ) {
if( typeof Buffer == 'function' && buffer instanceof Buffer ) {
var str = "";
for (var i = 0; i < buffer.length; ++i)
str += String.fromCharCode(buffer[i])
Expand Down

0 comments on commit bf0e585

Please sign in to comment.