Skip to content
Browse files

restore browser compatibility

  • Loading branch information...
1 parent c921dac commit bf0e5856afc2fdb1ebe87c6813ffc650d4267145 @rkusa rkusa committed Mar 31, 2012
View
1 index.js
@@ -0,0 +1 @@
+module.exports = require('./src')
View
2 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",
View
4 src/big5freq.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// Big5 frequency table
// by Taiwan's Mandarin Promotion Council
@@ -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);
View
4 src/big5prober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.Big5Prober = function() {
jschardet.MultiByteCharSetProber.apply(this);
@@ -48,4 +48,4 @@ jschardet.Big5Prober = function() {
}
jschardet.Big5Prober.prototype = new jschardet.MultiByteCharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/chardistribution.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.CharDistributionAnalysis = function() {
var ENOUGH_DATA_THRESHOLD = 1024;
@@ -280,4 +280,4 @@ jschardet.EUCJPDistributionAnalysis = function() {
}
jschardet.EUCJPDistributionAnalysis.prototype = new jschardet.CharDistributionAnalysis();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/charsetgroupprober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.CharSetGroupProber = function() {
jschardet.CharSetProber.apply(this);
@@ -115,4 +115,4 @@ jschardet.CharSetGroupProber = function() {
}
jschardet.CharSetGroupProber.prototype = new jschardet.CharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/charsetprober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.CharSetProber = function() {
this.reset = function() {
@@ -65,4 +65,4 @@ jschardet.CharSetProber = function() {
}
}
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/codingstatemachine.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.CodingStateMachine = function(sm) {
var self = this;
@@ -68,4 +68,4 @@ jschardet.CodingStateMachine = function(sm) {
init(sm);
}
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/constants.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.Constants = {
_debug : false,
@@ -43,4 +43,4 @@ jschardet.Constants = {
SHORTCUT_THRESHOLD : 0.95
};
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/escprober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.EscCharSetProber = function() {
jschardet.CharSetProber.apply(this);
@@ -95,4 +95,4 @@ jschardet.EscCharSetProber = function() {
}
jschardet.EscCharSetProber.prototype = new jschardet.CharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/escsm.js
@@ -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
@@ -253,4 +253,4 @@ jschardet.ISO2022KRSMModel = {
"name" : "ISO-2022-KR"
};
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/eucjpprober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.EUCJPProber = function() {
jschardet.MultiByteCharSetProber.apply(this);
@@ -99,4 +99,4 @@ jschardet.EUCJPProber = function() {
}
jschardet.EUCJPProber.prototype = new jschardet.MultiByteCharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/euckrfreq.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// Sampling from about 20M text materials include literature and computer technology
@@ -598,4 +598,4 @@ jschardet.EUCKRCharToFreqOrder = [
8736,8737,8738,8739,8740,8741
];
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/euckrprober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.EUCKRProber = function() {
jschardet.MultiByteCharSetProber.apply(this);
@@ -48,4 +48,4 @@ jschardet.EUCKRProber = function() {
}
jschardet.EUCKRProber.prototype = new jschardet.MultiByteCharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/euctwfreq.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// EUCTW frequency table
// Converted from big5 work
@@ -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);
View
4 src/euctwprober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.EUCTWProber = function() {
jschardet.MultiByteCharSetProber.apply(this);
@@ -48,4 +48,4 @@ jschardet.EUCTWProber = function() {
}
jschardet.EUCTWProber.prototype = new jschardet.MultiByteCharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/gb2312freq.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// GB2312 most frequently used character table
//
@@ -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);
View
4 src/gb2312prober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.GB2312Prober = function() {
jschardet.MultiByteCharSetProber.apply(this);
@@ -48,4 +48,4 @@ jschardet.GB2312Prober = function() {
}
jschardet.GB2312Prober.prototype = new jschardet.MultiByteCharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/hebrewprober.js
@@ -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
@@ -319,4 +319,4 @@ if (!Array.prototype.indexOf)
};
}
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
1 src/index.js
@@ -0,0 +1 @@
+module.exports = require('./init')
View
76 src/init.js
@@ -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])
View
4 src/jisfreq.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// Sampling from about 20M text materials include literature and computer technology
//
@@ -570,4 +570,4 @@ jschardet.JISCharToFreqOrder = [
8256,8257,8258,8259,8260,8261,8262,8263,8264,8265,8266,8267,8268,8269,8270,8271 // 8272
];
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/jpcntx.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// This is hiragana 2-char sequence table, the number in each cell represents its frequency category
jschardet.jp2CharContext = [
@@ -239,4 +239,4 @@ jschardet.EUCJPContextAnalysis = function() {
}
jschardet.EUCJPContextAnalysis.prototype = new jschardet.JapaneseContextAnalysis();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/langbulgarianmodel.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// 255: Control characters that usually does not exist in any text
// 254: Carriage/Return
@@ -229,4 +229,4 @@ jschardet.Win1251BulgarianModel = {
"charsetName" : "windows-1251"
};
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/langcyrillicmodel.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// KOI8-R language model
// Character Mapping Table:
@@ -330,4 +330,4 @@ jschardet.Ibm855Model = {
"charsetName" : "IBM855"
};
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/langgreekmodel.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// 255: Control characters that usually does not exist in any text
// 254: Carriage/Return
@@ -226,4 +226,4 @@ jschardet.Win1253GreekModel = {
"charsetName" : "windows-1253"
};
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/langhebrewmodel.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// 255: Control characters that usually does not exist in any text
// 254: Carriage/Return
@@ -200,4 +200,4 @@ jschardet.Win1255HebrewModel = {
"charsetName" : "windows-1255"
};
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/langhungarianmodel.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// 255: Control characters that usually does not exist in any text
// 254: Carriage/Return
@@ -226,4 +226,4 @@ jschardet.Win1250HungarianModel = {
"charsetName" : "windows-1250"
};
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/langthaimodel.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// 255: Control characters that usually does not exist in any text
// 254: Carriage/Return
@@ -201,4 +201,4 @@ jschardet.TIS620ThaiModel = {
"charsetName" : "TIS-620"
};
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/latin1prober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
(function() {
var UDF = 0; // undefined
@@ -160,4 +160,4 @@ jschardet.Latin1Prober = function() {
}
jschardet.Latin1Prober.prototype = new jschardet.CharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/mbcharsetprober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.MultiByteCharSetProber = function() {
jschardet.CharSetProber.apply(this);
@@ -98,4 +98,4 @@ jschardet.MultiByteCharSetProber = function() {
}
jschardet.MultiByteCharSetProber.prototype = new jschardet.CharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/mbcsgroupprober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.MBCSGroupProber = function() {
jschardet.CharSetGroupProber.apply(this);
@@ -44,4 +44,4 @@ jschardet.MBCSGroupProber = function() {
}
jschardet.MBCSGroupProber.prototype = new jschardet.CharSetGroupProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/mbcssm.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
// BIG5
@@ -560,4 +560,4 @@ jschardet.UTF8SMModel = {
"name" : "UTF-8"
};
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/sbcharsetprober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.SingleByteCharSetProber = function(model, reversed, nameProber) {
jschardet.CharSetProber.apply(this);
@@ -136,4 +136,4 @@ jschardet.SingleByteCharSetProber = function(model, reversed, nameProber) {
}
jschardet.SingleByteCharSetProber.prototype = new jschardet.CharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/sbcsgroupprober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.SBCSGroupProber = function() {
jschardet.CharSetGroupProber.apply(this);
@@ -63,4 +63,4 @@ jschardet.SBCSGroupProber = function() {
}
jschardet.SBCSGroupProber.prototype = new jschardet.CharSetGroupProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/sjisprober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.SJISProber = function() {
jschardet.MultiByteCharSetProber.apply(this);
@@ -98,4 +98,4 @@ jschardet.SJISProber = function() {
}
jschardet.SJISProber.prototype = new jschardet.MultiByteCharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/universaldetector.js
@@ -31,7 +31,7 @@
* This is a port from the python port, version "2.0.1"
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.UniversalDetector = function() {
var MINIMUM_THRESHOLD = 0.20;
@@ -200,4 +200,4 @@ jschardet.UniversalDetector = function() {
init();
}
-};
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);
View
4 src/utf8prober.js
@@ -27,7 +27,7 @@
* 02110-1301 USA
*/
-module.exports = function(jschardet) {
+!function(jschardet) {
jschardet.UTF8Prober = function() {
jschardet.CharSetProber.apply(this);
@@ -92,4 +92,4 @@ jschardet.UTF8Prober = function() {
}
jschardet.UTF8Prober.prototype = new jschardet.CharSetProber();
-}
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module.parent.exports : jschardet);

0 comments on commit bf0e585

Please sign in to comment.
Something went wrong with that request. Please try again.