Detect-It-Easy/db/_init
DosX 33711a0407 Add standard DiE-JS framework header to db files
Added a standard header comment to all db framework and detection rule files, indicating they are part of the Detect It Easy (DiE-JS) framework and warning against unauthorized changes. This improves consistency and clarifies file purpose for maintainers.
2025-08-27 23:21:24 +03:00

210 lines
No EOL
6.1 KiB
Text

// Detect It Easy: DiE-JS framework file
// Don't change anything unless you're sure about what you're doing
includeScript("_debug");
var bDetected,
sType,
sName,
sVersion,
sOptions,
sLang,
sLangVersion;
/**
* Initializes the detection process with the given parameters.
*
* @param {string} sType - The type of the item to detect. Defaults to "unknown".
* @param {string} sName - The name of the item to detect. Defaults to "unknown".
* @param {string} [sVersion] - The version of the item to detect. Optional.
* @param {string} [sOptions] - Additional options for detection. Optional.
* @param {string} [sLang] - The programming language of the item to detect. Optional.
* @param {string} [sLangVersion] - The version of the programming language. Optional.
*/
function meta(sTypeInput, sNameInput) {
if (!sTypeInput) _error("No input type.");
sType = sTypeInput;
sName = sNameInput;
sVersion = arguments[2] ? arguments[2] : "";
sOptions = arguments[3] ? arguments[3] : "";
sLang = arguments[4] ? arguments[4] : "";
sLangVersion = arguments[5] ? arguments[5] : "";
bDetected = false;
}
function init() {
meta.apply(null, arguments);
}
/**
* Processes the detection result and resets the detection variables.
*
* If a detection has been made (bDetected is true), this function sets the result
* using the _setResult function with the provided type, name, version, and options.
* After setting the result, it resets the detection flag (bDetected) to false.
*
* Regardless of whether a detection was made, it resets the sName, sVersion, and sOptions
* variables to empty strings.
*/
function result() {
if (bDetected) {
sVersion = sVersion ? sVersion : String();
sOptions = sOptions ? sOptions : String();
if (sName) {
_setResult(sType, sName, sVersion, sOptions);
if (sLang) {
if (sLangVersion) {
_setLang(sLang, sLangVersion);
} else {
_setLang(sLang);
}
}
}
}
sName = sVersion = sOptions = sLang = sLangVersion = '';
var resultValue = bDetected;
bDetected = false;
return resultValue;
}
/**
* Attaches new strings to `this`, separating everything with a comma and no space.
* @param {String...} the open list of strings to append.
*/
String.prototype.append = function () {
var s = this.valueOf(),
sep = ", ";
if (arguments.length) {
if (s.length) s += sep;
s += Array.prototype.join.call(arguments, sep);
}
return s;
}
/**
* Append a string with a custom separator.
* @param {String} sString - String to append.
* @param {String} [sSep=", "] - Separator string.
* @returns {String} The new string.
* @global
* @example
* sOptions = sOptions.appendS("debug","::");
*/
String.prototype.appendS = function (sString, sSep) {
var s = this.valueOf(),
sep = (typeof sSep == "string") ? sSep : ", ";
if (sString) {
if (s.length) s += sep;
s += sString;
}
return s;
}
String.prototype.addIfNone = function (substring) {
var s = this.valueOf();
if (substring && s.indexOf(substring) < 0)
s += substring;
return s;
}
// Some ECMA6 functions that should be removed if DIE transitions to it
String.prototype.beginsWith = function (s, min) { // the default case-sensitive version of beginsWith
var m = (typeof min == "number") ? Math.min(s.length, min) : 0;
if (s.length > this.length - m) return false; else return this.slice(m, s.length) == s;
}
String.prototype.beginsWithCI = function (s, min) { // case-insensitive version of beginsWith
return this.toLowerCase().beginsWith(s.toLowerCase(), min);
}
String.prototype.endsWith = function (s, max) { // the default case-sensitive version of endsWith
var m = (typeof max == "number") ? Math.min(this.length, max) : this.length;
if (s.length > m) return false; else return this.slice(m - s.length, m) == s;
}
String.prototype.endsWithCI = function (s, max) { // the case-insensitive version of endsWith
return this.toLowerCase().endsWith(s.toLowerCase(), max);
}
String.prototype.repeat = function (num) {
if (typeof num !== "number") return this;
var s = this; for (var i = 1; i < num; i++) s += this; return s;
}
/**
* Pad the start of a line with spaces or the character given.
* @param {String or Number} The width desired.
* @param {Number} [nPad=" "] The padding string. Loops.
* @returns {String} The new string.
* @global
* @example
* var a = 12; ...; if("aba12" === a.padStart(5,"ab")) ...
*/
String.prototype.padStart = function (targetLength, padString) {
var s = this.valueOf();
targetLength >>= 0; // truncate if number or convert non-number to 0;
padString = String(padString || ' ');
if (s.length >= targetLength) {
return String(s);
}
targetLength -= s.length;
if (targetLength > padString.length) {
padString += padString.repeat(Math.ceil(targetLength / padString.length));
// append to original to ensure we are longer than needed
}
return padString.slice(0, targetLength) + String(s);
}
Number.prototype.padStart = function (targetLength, padString) {
var s = this.valueOf().toString();
targetLength >>= 0; // truncate if number or convert non-number to 0;
padString = String(padString || ' ');
if (s.length >= targetLength) return s;
targetLength -= s.length;
if (targetLength > padString.length) {
padString += padString.repeat(Math.ceil(targetLength / padString.length));
// append to original to ensure we are longer than needed
}
return padString.slice(0, targetLength) + s;
}
Number.prototype.clamp = function (min, max) { return Math.min(Math.max(this, min), max) }
String.prototype.replaceAll = function (s, r) {
if (typeof s != 'string' || typeof r != 'string') return '?' + s;
var o = '';
for (var i = 0; i < this.length; i++) {
if (this.slice(i, i + s.length) == s) { o += r; i += s.length - 1 } else o += this[i];
}
return o;
}
includeScript("language");