mirror of
https://github.com/horsicq/Detect-It-Easy.git
synced 2026-06-24 01:54:08 +00:00
26 lines
No EOL
778 B
JavaScript
Executable file
26 lines
No EOL
778 B
JavaScript
Executable file
// Detect It Easy: detection rule file
|
|
|
|
init("format", "Plain text");
|
|
|
|
function detect() {
|
|
if (Binary.isPlainText()) {
|
|
var sText = Binary.getString(0, Math.min(Binary.getSize(), 3));
|
|
// UTF-8 BOM.
|
|
if (/^\xef\xbb\xbf/.test(sText)) {
|
|
sName = "UTF-8 text";
|
|
}
|
|
|
|
var size = Binary.getSize() < 4096 ? Binary.getSize() : 4096,
|
|
pos = Binary.findByte(0, size, 10);
|
|
|
|
if (pos !== -1) {
|
|
sOptions = (pos != 0 && Binary.readByte(pos - 1) == 13) || (pos + 1 < Binary.getSize() && Binary.readByte(pos + 1) == 13) ? "CRLF" : "LF";
|
|
} else if (Binary.findByte(0, size, 13) != -1) {
|
|
sOptions = "CR";
|
|
}
|
|
|
|
bDetected = true;
|
|
}
|
|
|
|
return result();
|
|
} |