jschardet
Advanced tools
Comparing version 2.2.1 to 2.3.0
{ | ||
"name": "jschardet", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "Character encoding auto-detection in JavaScript (port of python's chardet)", | ||
@@ -5,0 +5,0 @@ "author": "António Afonso", |
@@ -31,2 +31,10 @@ [![NPM](https://nodei.co/npm/jschardet.png?downloads=true&downloadRank=true)](https://nodei.co/npm/jschardet/) | ||
// Martin Kühl | ||
// jschardet.detectAll("\x3c\x73\x74\x72\x69\x6e\x67\x3e\x4d\x61\x72\x74\x69\x6e\x20\x4b\xfc\x68\x6c\x3c\x2f\x73\x74\x72\x69\x6e\x67\x3e") | ||
// [ | ||
// {encoding: "windows-1252", confidence: 0.95}, | ||
// {encoding: "ISO-8859-2", confidence: 0.8796300205763055}, | ||
// {encoding: "SHIFT_JIS", confidence: 0.01} | ||
// ] | ||
### Browser | ||
@@ -33,0 +41,0 @@ Copy and include [jschardet.min.js](https://github.com/aadsm/jschardet/tree/master/dist/jschardet.min.js) in your web page. |
@@ -34,2 +34,15 @@ /* | ||
exports.detect = function(buffer, options) { | ||
var u = runUniversalDetector(buffer, options); | ||
return u.result; | ||
} | ||
exports.detectAll = function(buffer, options) { | ||
var u = runUniversalDetector(buffer, options); | ||
return u.results; | ||
} | ||
exports.UniversalDetector = UniversalDetector; | ||
exports.enableDebug = function() { | ||
setLogger(console.log.bind(console)); | ||
} | ||
function runUniversalDetector(buffer, options) { | ||
var u = new UniversalDetector(options); | ||
@@ -43,7 +56,3 @@ u.reset(); | ||
u.close(); | ||
return u.result; | ||
} | ||
exports.UniversalDetector = UniversalDetector; | ||
exports.enableDebug = function() { | ||
setLogger(console.log.bind(console)); | ||
} | ||
return u; | ||
} |
@@ -62,2 +62,3 @@ /* | ||
this.result = {"encoding": null, "confidence": 0.0}; | ||
this.results = [] | ||
this.done = false; | ||
@@ -109,2 +110,6 @@ this._mStart = true; | ||
if (this.result.confidence > 0) { | ||
this.results = [this.result]; | ||
} | ||
// If we got to 4 chars without being able to detect a BOM we | ||
@@ -141,2 +146,3 @@ // stop trying. | ||
}; | ||
this.results = [this.result]; | ||
this.done = true; | ||
@@ -158,2 +164,3 @@ } | ||
}; | ||
this.results = [this.result]; | ||
this.done = true; | ||
@@ -177,2 +184,3 @@ break; | ||
this.result = {"encoding": "ascii", "confidence": 1.0}; | ||
this.results.push(this.result); | ||
return this.result; | ||
@@ -182,20 +190,19 @@ } | ||
if( this._mInputState == _state.highbyte ) { | ||
var proberConfidence = null; | ||
var maxProberConfidence = 0.0; | ||
var maxProber = null; | ||
for( var i = 0, prober; prober = this._mCharsetProbers[i]; i++ ) { | ||
if( !prober ) continue; | ||
proberConfidence = prober.getConfidence(); | ||
if( proberConfidence > maxProberConfidence ) { | ||
maxProberConfidence = proberConfidence; | ||
maxProber = prober; | ||
} | ||
if( !prober || !prober.getCharsetName()) continue; | ||
this.results.push({ | ||
"encoding": prober.getCharsetName(), | ||
"confidence": prober.getConfidence() | ||
}); | ||
logger.log(prober.getCharsetName() + " confidence " + prober.getConfidence()); | ||
} | ||
if( maxProber && maxProberConfidence > options.minimumThreshold ) { | ||
this.result = { | ||
"encoding": maxProber.getCharsetName(), | ||
"confidence": maxProber.getConfidence() | ||
}; | ||
return this.result; | ||
this.results.sort(function(a, b) { | ||
return b.confidence - a.confidence; | ||
}); | ||
if (this.results.length > 0) { | ||
var topResult = this.results[0]; | ||
if (topResult.confidence >= options.minimumThreshold) { | ||
this.result = topResult; | ||
return topResult; | ||
} | ||
} | ||
@@ -202,0 +209,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1364271
17389
98