Detect-It-Easy/db/_init
2024-11-12 19:22:37 +03:00

156 lines
No EOL
3.7 KiB
Text

var bDetected,
sType,
sName,
sVersion,
sOptions;
/**
* 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.
*/
function init(sTypeInput, sNameInput) {
if (!sTypeInput) throw "No input type.";
sType = sTypeInput;
sName = sNameInput;
sVersion = arguments[2] ? arguments[2] : "";
sOptions = arguments[3] ? arguments[3] : "";
// bDetected = false;
}
/**
* 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) {
_setResult(sType, sName, sVersion, sOptions);
bDetected = false;
}
sName = String();
sVersion = String();
sOptions = String();
}
/**
* Gets the primitive value of the current object.
* @type {string}
*/
String.prototype.append = function() {
var
s = this.valueOf(),
sep = ",";
if (arguments.length) {
if (s) s += sep;
s += arguments[0];
for (var i = 1; i < arguments.length; i++) {
s += sep + arguments[i];
}
}
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() {
var
s = this.valueOf(),
sep = arguments[1] ? arguments[1] : ",";
if (arguments.length) {
if (s) s += sep;
s += arguments[0];
}
return s
}
String.prototype.addIfNone = function() {
var s = this.valueOf();
if (arguments.length)
if (s.indexOf(arguments[0]) < 0) s += arguments[0];
return s;
}
/**
* Pad the start of a line with spaces or the character given.
* This reimplements missing functionality of the more modern ECMAScript.
* @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() {
var s = this.valueOf();
if (!s.length || !arguments.length || s.length <= arguments[0].length) return s;
var c = 0,
p = ' ';
if (arguments.length > 1) p = arguments[1].toString();
var pp = "";
for (var i = 0; i < Math.max(0, arguments[0] - s.length); i++) {
pp += p[c];
c++;
if (c === p.length) c = 0
}
return pp + s
}
Number.prototype.padStart = function() {
var s = this.valueOf().toString();
if (!arguments.length || s.length >= arguments[0]) return s;
var c = 0,
p = ' ';
if (arguments.length > 1) p = arguments[1].toString();
var pp = "";
for (var i = 0; i < Math.max(0, arguments[0] - s.length); i++) {
pp += p[c];
c++;
if (c === p.length) c = 0
}
return pp + s
}
// Just a debug function
function debug(messageText) {
_setResult("dev-output", messageText, "", "");
}
includeScript("language");