2024-09-09 12:13:10 +02:00
|
|
|
|
var __extends = (this && this.__extends) || (function () {
|
|
|
|
|
var extendStatics = function (d, b) {
|
|
|
|
|
extendStatics = Object.setPrototypeOf ||
|
|
|
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
|
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
|
|
|
return extendStatics(d, b);
|
|
|
|
|
};
|
|
|
|
|
return function (d, b) {
|
|
|
|
|
if (typeof b !== "function" && b !== null)
|
|
|
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
|
|
|
extendStatics(d, b);
|
|
|
|
|
function __() { this.constructor = d; }
|
|
|
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
|
|
|
};
|
|
|
|
|
})();
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:base«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
// }
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:base«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
;
|
2024-09-11 17:24:20 +02:00
|
|
|
|
/*
|
|
|
|
|
declare class console {
|
|
|
|
|
static log(...args : any[]) : void;
|
|
|
|
|
static info(...args : any[]) : void;
|
|
|
|
|
static warn(...args : any[]) : void;
|
|
|
|
|
static error(...args : any[]) : void;
|
|
|
|
|
};
|
|
|
|
|
*/
|
2024-09-09 12:13:10 +02:00
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var base;
|
|
|
|
|
(function (base) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function environment() {
|
2024-09-11 17:24:20 +02:00
|
|
|
|
return "web";
|
2024-09-09 12:13:10 +02:00
|
|
|
|
}
|
|
|
|
|
base.environment = environment;
|
|
|
|
|
})(base = lib_plankton.base || (lib_plankton.base = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:base«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
/*export*/ function pseudopointer_null() {
|
|
|
|
|
return {
|
|
|
|
|
"value": null
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
/*export*/ function pseudopointer_make(value) {
|
|
|
|
|
return {
|
|
|
|
|
"value": value
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
/*export*/ function pseudopointer_isset(pseudopointer) {
|
|
|
|
|
return (pseudopointer.value != null);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
/*export*/ function pseudopointer_read(pseudopointer) {
|
|
|
|
|
if (pseudopointer.value != null) {
|
|
|
|
|
return pseudopointer.value;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var message = "nullpointer dereferencation";
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
/*export*/ function pseudopointer_write(pseudopointer, value) {
|
|
|
|
|
pseudopointer.value = value;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:base«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var instance_verbosity = 0;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function instance_collate(value1, value2) {
|
|
|
|
|
if (typeof (value1) === "object") {
|
|
|
|
|
if (value1 == null) {
|
|
|
|
|
return (value2 == null);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if ("_collate" in value1) {
|
|
|
|
|
return value1["_collate"](value2);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw (new Error("[collate]" + " " + "object has no such method"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (instance_verbosity >= 1) {
|
|
|
|
|
// lib_plankton.log.warn("[collate]" + " " + "primitive value; using default implementation");
|
|
|
|
|
}
|
|
|
|
|
return (value1 === value2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function instance_compare(value1, value2) {
|
|
|
|
|
if (typeof (value1) === "object") {
|
|
|
|
|
if ("_compare" in value1) {
|
|
|
|
|
return value1["_compare"](value2);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw (new Error("[compare]" + " " + "object has no such method"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (instance_verbosity >= 1) {
|
|
|
|
|
// lib_plankton.log.warn("[compare]" + " " + "primitive value; using default implementation");
|
|
|
|
|
}
|
|
|
|
|
return (value1 <= value2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function instance_clone(value) {
|
|
|
|
|
if (typeof (value) === "object") {
|
|
|
|
|
if ("_clone" in value) {
|
|
|
|
|
return value["_clone"]();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw (new Error("[clone]" + " " + "object has no such method"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (instance_verbosity >= 1) {
|
|
|
|
|
// lib_plankton.log.warn("[clone]" + " " + "primitive value; using default implementation");
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc the ability to generate a string out of the element, which identifies it to a high degree
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function instance_hash(value) {
|
|
|
|
|
if (typeof (value) === "object") {
|
|
|
|
|
if ("_hash" in value) {
|
|
|
|
|
return value["_hash"]();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw (new Error("[hash]" + " " + "object has no such method"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (instance_verbosity >= 1) {
|
|
|
|
|
// lib_plankton.log.warn("[hash]" + " " + "primitive value; using default implementation");
|
|
|
|
|
}
|
|
|
|
|
return String(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc the ability to map the element to a textual representation (most likely not injective)
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function instance_show(value) {
|
|
|
|
|
if (typeof (value) === "object") {
|
|
|
|
|
if (value == null) {
|
|
|
|
|
return "NULL";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if ("_show" in value) {
|
|
|
|
|
return value["_show"]();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// throw (new Error("[show]" + " " + "object has no such method"));
|
|
|
|
|
return JSON.stringify(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (instance_verbosity >= 1) {
|
|
|
|
|
// lib_plankton.log.warn("[show]" + " " + "primitive value; using default implementation");
|
|
|
|
|
}
|
|
|
|
|
return String(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:base«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
var class_observer = /** @class */ (function () {
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
function class_observer() {
|
|
|
|
|
this.counter = 0;
|
|
|
|
|
this.actions = {};
|
|
|
|
|
this.buffer = [];
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
class_observer.prototype.empty = function () {
|
|
|
|
|
return (Object.keys(this.actions).length == 0);
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
class_observer.prototype.flush = function () {
|
|
|
|
|
this.actions = {};
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
class_observer.prototype.set = function (id, action) {
|
|
|
|
|
this.actions[id] = action;
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
class_observer.prototype.del = function (id) {
|
|
|
|
|
delete this.actions[id];
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
class_observer.prototype.add = function (action) {
|
|
|
|
|
this.set((this.counter++).toString(), action);
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
class_observer.prototype.notify = function (information, delayed) {
|
|
|
|
|
var _this = this;
|
|
|
|
|
if (information === void 0) { information = {}; }
|
|
|
|
|
if (delayed === void 0) { delayed = false; }
|
|
|
|
|
if (delayed) {
|
|
|
|
|
this.buffer.push(information);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Object.keys(this.actions).forEach(function (id) { return _this.actions[id](information); });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
class_observer.prototype.rollout = function () {
|
|
|
|
|
var _this = this;
|
|
|
|
|
this.buffer.forEach(function (information) { return _this.notify(information, false); });
|
|
|
|
|
this.buffer = [];
|
|
|
|
|
};
|
|
|
|
|
return class_observer;
|
|
|
|
|
}());
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
export interface interface_readable<type_value> {
|
|
|
|
|
|
|
|
|
|
|**
|
|
|
|
|
* @author frac
|
|
|
|
|
*|
|
|
|
|
|
read() : type_executor<type_value, Error>;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
export interface interface_writeable<type_value> {
|
|
|
|
|
|
|
|
|
|
|**
|
|
|
|
|
* @author frac
|
|
|
|
|
*|
|
|
|
|
|
write(value : type_value) : type_executor<void, Error>;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:base«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
var class_error = /** @class */ (function (_super) {
|
|
|
|
|
__extends(class_error, _super);
|
|
|
|
|
/**
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
function class_error(message, suberrors) {
|
|
|
|
|
if (suberrors === void 0) { suberrors = []; }
|
|
|
|
|
var _this = _super.call(this, message) || this;
|
|
|
|
|
_this.suberrors = suberrors;
|
|
|
|
|
_this.mess = message;
|
|
|
|
|
return _this;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @author frac
|
|
|
|
|
*/
|
|
|
|
|
class_error.prototype.toString = function () {
|
|
|
|
|
return ( /*super.toString()*/this.mess + " " + ("[" + this.suberrors.map(function (x) { return x.toString(); }).join(",") + "]"));
|
|
|
|
|
};
|
|
|
|
|
return class_error;
|
|
|
|
|
}(Error));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:base«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:base« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var base;
|
|
|
|
|
(function (base) {
|
|
|
|
|
/**
|
|
|
|
|
* returns the current UNIX timestamp
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function get_current_timestamp(rounded) {
|
|
|
|
|
if (rounded === void 0) { rounded = false; }
|
|
|
|
|
var x = (Date.now() / 1000);
|
|
|
|
|
return (rounded ? Math.round(x) : x);
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
base.get_current_timestamp = get_current_timestamp;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function object_merge(core, mantle) {
|
|
|
|
|
return Object.assign(core, mantle);
|
|
|
|
|
}
|
|
|
|
|
base.object_merge = object_merge;
|
|
|
|
|
})(base = lib_plankton.base || (lib_plankton.base = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:pod«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:pod« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:pod« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:pod«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var pod;
|
|
|
|
|
(function (pod_1) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function make_empty() {
|
|
|
|
|
return {
|
|
|
|
|
"kind": "empty"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
pod_1.make_empty = make_empty;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function make_filled(value) {
|
|
|
|
|
return {
|
|
|
|
|
"kind": "filled",
|
|
|
|
|
"value": value
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
pod_1.make_filled = make_filled;
|
|
|
|
|
/**
|
|
|
|
|
* whether the pod is filled
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function is_filled(pod) {
|
|
|
|
|
return (pod.kind === "filled");
|
|
|
|
|
}
|
|
|
|
|
pod_1.is_filled = is_filled;
|
|
|
|
|
/**
|
|
|
|
|
* return the value, stored in the pod-wrapper
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function cull(pod) {
|
|
|
|
|
if (!is_filled(pod)) {
|
|
|
|
|
throw (new Error("cull from empty"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return pod.value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pod_1.cull = cull;
|
|
|
|
|
/**
|
|
|
|
|
* to pass on a empty-pod or to use a filled-pod
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function propagate(pod, function_) {
|
|
|
|
|
if (!is_filled(pod)) {
|
|
|
|
|
return make_empty();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return make_filled(function_(pod.value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pod_1.propagate = propagate;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function distinguish(pod, function_empty, function_filled) {
|
|
|
|
|
return ((!is_filled(pod))
|
|
|
|
|
? function_empty()
|
|
|
|
|
: function_filled(pod.value));
|
|
|
|
|
}
|
|
|
|
|
pod_1.distinguish = distinguish;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function show(pod, options = {}) {
|
|
|
|
|
options = Object.assign({
|
|
|
|
|
"show_value": value => String(value),
|
|
|
|
|
}, options);
|
|
|
|
|
if (!is_filled(pod)) {
|
|
|
|
|
return "<·>";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return ("<- " + options.show_value(pod.value) + " ->");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pod_1.show = show;
|
|
|
|
|
})(pod = lib_plankton.pod || (lib_plankton.pod = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:pod«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:pod« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:pod« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:pod«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var pod;
|
|
|
|
|
(function (pod) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
class class_pod {
|
|
|
|
|
constructor(subject) { this.subject = subject; }
|
2024-09-11 17:24:20 +02:00
|
|
|
|
tear() { return this.subject; }
|
|
|
|
|
static empty() { return (new class_pod(pod.make_empty())); }
|
|
|
|
|
static filled(value) { return (new class_pod(pod.make_filled(value))); }
|
2024-09-09 12:13:10 +02:00
|
|
|
|
is_empty() { return (!pod.is_filled(this.subject)); }
|
|
|
|
|
is_filled() { return pod.is_filled(this.subject); }
|
|
|
|
|
cull() { return pod.cull(this.subject); }
|
|
|
|
|
show(show_value = undefined) { return pod.show(this.subject, show_value); }
|
|
|
|
|
toString() { return this.show(); }
|
|
|
|
|
propagate(function_) { return new class_pod(pod.propagate(this.subject, function_)); }
|
|
|
|
|
distinguish(function_empty, function_filled) { return pod.distinguish(this.subject, function_empty, function_filled); }
|
|
|
|
|
}
|
|
|
|
|
pod.class_pod = class_pod;
|
|
|
|
|
})(pod = lib_plankton.pod || (lib_plankton.pod = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:call«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* might be completely obsolete
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var call;
|
|
|
|
|
(function (call) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_reject(reason) {
|
|
|
|
|
return Promise.reject(reason);
|
|
|
|
|
}
|
|
|
|
|
call.promise_reject = promise_reject;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_resolve(result) {
|
|
|
|
|
return Promise.resolve(result);
|
|
|
|
|
}
|
|
|
|
|
call.promise_resolve = promise_resolve;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_make(executor) {
|
|
|
|
|
return (new Promise(executor));
|
|
|
|
|
}
|
|
|
|
|
call.promise_make = promise_make;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_then_close(promise, resolver, rejector) {
|
|
|
|
|
promise.then(resolver, rejector);
|
|
|
|
|
}
|
|
|
|
|
call.promise_then_close = promise_then_close;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_then_append(promise, resolver, rejector = null) {
|
|
|
|
|
if (rejector == null) {
|
|
|
|
|
rejector = (reason) => promise_reject(reason);
|
|
|
|
|
}
|
|
|
|
|
return (promise.then(resolver, rejector));
|
|
|
|
|
}
|
|
|
|
|
call.promise_then_append = promise_then_append;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_all(promises) {
|
|
|
|
|
return Promise.all(promises);
|
|
|
|
|
}
|
|
|
|
|
call.promise_all = promise_all;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_chain(promises, start = undefined) {
|
|
|
|
|
return (promises.reduce((chain, promise) => promise_then_append(chain, promise), promise_resolve(start)));
|
|
|
|
|
}
|
|
|
|
|
call.promise_chain = promise_chain;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_condense(promises) {
|
|
|
|
|
return (promise_chain(promises.map(promise => result => promise_then_append(promise(), element => promise_resolve(result.concat([element])))), []));
|
|
|
|
|
}
|
|
|
|
|
call.promise_condense = promise_condense;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_group(promises, options = {
|
|
|
|
|
"serial": false,
|
|
|
|
|
}) {
|
|
|
|
|
const decorate = function (promise, name) {
|
|
|
|
|
return (() => promise_then_append(promise(), value => promise_resolve({ "key": name, "value": value })));
|
|
|
|
|
};
|
|
|
|
|
if (options.serial) {
|
|
|
|
|
return (promise_then_append(promise_condense(Object.keys(promises)
|
|
|
|
|
.map(name => decorate(promises[name], name))), list => promise_resolve(Object.fromEntries(list.map(({ "key": key, "value": value }) => ([key, value]))))));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return (promise_then_append(promise_all(Object.keys(promises)
|
|
|
|
|
.map(name => decorate(promises[name], name))
|
|
|
|
|
.map(promise => promise())), list => promise_resolve(Object.fromEntries(list.map(({ "key": key, "value": value }) => ([key, value]))))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
call.promise_group = promise_group;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_wrap(promise, transformator_result, transformator_reason = lib_plankton.call.id) {
|
|
|
|
|
return (promise_make((resolve, reject) => {
|
|
|
|
|
promise_then_close(promise, result => resolve(transformator_result(result)), reason => reject(transformator_reason(reason)));
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
call.promise_wrap = promise_wrap;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
export function promise_show<type_result, type_reason>(label : string) : (result : type_result)=>type_promise<type_result, type_reason> {
|
|
|
|
|
return (
|
|
|
|
|
result => promise_make<type_result, type_reason>(
|
|
|
|
|
(resolve, reject) => {
|
|
|
|
|
// lib_plankton.log.info(label + ": " + instance_show(result));
|
|
|
|
|
process.stdout.write(label + ": " + instance_show(result));
|
|
|
|
|
resolve(result);
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
export function promise_log<type_result, type_reason>(result : type_result) : (result : type_result)=>type_promise<type_result, type_reason> {
|
|
|
|
|
return promise_show<type_result, type_reason>("log");
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_attach(state, promise, name) {
|
|
|
|
|
return (promise_wrap(promise, result => {
|
|
|
|
|
state[name] = result;
|
|
|
|
|
return state;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
call.promise_attach = promise_attach;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function promise_delay(promise, delay) {
|
|
|
|
|
return promise_make((resolve, reject) => {
|
|
|
|
|
call.timeout(() => {
|
|
|
|
|
promise_then_close(promise, resolve, reject);
|
|
|
|
|
return null;
|
|
|
|
|
}, delay);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
call.promise_delay = promise_delay;
|
|
|
|
|
})(call = lib_plankton.call || (lib_plankton.call = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:call«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var call;
|
|
|
|
|
(function (call) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
class CancellablePromise extends Promise {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
constructor(executor) {
|
|
|
|
|
super((resolve, reject) => { });
|
|
|
|
|
this.subject = (new Promise((resolve, reject) => {
|
|
|
|
|
Promise.race([
|
|
|
|
|
new Promise(executor),
|
|
|
|
|
new Promise((resolve_, reject_) => {
|
|
|
|
|
this.interval = setInterval(() => {
|
|
|
|
|
if (!this.cancelled) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
reject_(new Error("cancelled"));
|
|
|
|
|
this.clear();
|
|
|
|
|
}
|
|
|
|
|
}, 0);
|
|
|
|
|
}),
|
|
|
|
|
])
|
|
|
|
|
.then(resolve, reject);
|
|
|
|
|
}));
|
|
|
|
|
this.cancelled = false;
|
|
|
|
|
this.interval = null;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
clear() {
|
|
|
|
|
if (this.interval === null) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
clearInterval(this.interval);
|
|
|
|
|
this.interval = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
then(onfulfilled, onrejected) {
|
|
|
|
|
this.clear();
|
|
|
|
|
return this.subject.then(onfulfilled, onrejected);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
catch(x) {
|
|
|
|
|
this.clear();
|
|
|
|
|
return this.subject.catch(x);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
cancel() {
|
|
|
|
|
this.cancelled = true;
|
|
|
|
|
this.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
call.CancellablePromise = CancellablePromise;
|
|
|
|
|
})(call = lib_plankton.call || (lib_plankton.call = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:call«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* initializer might be obsolete, since promises are reusable after having been resolved or rejected
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var call;
|
|
|
|
|
(function (call) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
let enum_initializer_state;
|
|
|
|
|
(function (enum_initializer_state) {
|
|
|
|
|
enum_initializer_state[enum_initializer_state["initial"] = 0] = "initial";
|
|
|
|
|
enum_initializer_state[enum_initializer_state["waiting"] = 1] = "waiting";
|
|
|
|
|
enum_initializer_state[enum_initializer_state["successful"] = 2] = "successful";
|
|
|
|
|
enum_initializer_state[enum_initializer_state["failed"] = 3] = "failed";
|
|
|
|
|
})(enum_initializer_state = call.enum_initializer_state || (call.enum_initializer_state = {}));
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function initializer_make(fetcher) {
|
|
|
|
|
let subject = {
|
|
|
|
|
"fetcher": fetcher,
|
|
|
|
|
"state": enum_initializer_state.initial,
|
|
|
|
|
"queue": [],
|
|
|
|
|
"result": undefined,
|
|
|
|
|
"reason": undefined,
|
|
|
|
|
};
|
|
|
|
|
return subject;
|
|
|
|
|
}
|
|
|
|
|
call.initializer_make = initializer_make;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function initializer_actuate(subject) {
|
|
|
|
|
switch (subject.state) {
|
|
|
|
|
case enum_initializer_state.successful: {
|
|
|
|
|
subject.queue.forEach(entry => entry.resolve(subject.result));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case enum_initializer_state.failed: {
|
|
|
|
|
subject.queue.forEach(entry => entry.reject(subject.reason));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error(`unhandled state ${subject.state}`));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function initializer_reset(subject) {
|
|
|
|
|
subject.state = enum_initializer_state.initial;
|
|
|
|
|
subject.queue = [];
|
|
|
|
|
}
|
|
|
|
|
call.initializer_reset = initializer_reset;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function initializer_state(subject) {
|
|
|
|
|
return subject.state;
|
|
|
|
|
}
|
|
|
|
|
call.initializer_state = initializer_state;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function initializer_get(subject) {
|
|
|
|
|
switch (subject.state) {
|
|
|
|
|
case enum_initializer_state.initial: {
|
|
|
|
|
subject.state = enum_initializer_state.waiting;
|
|
|
|
|
return (call.promise_make((resolve, reject) => {
|
|
|
|
|
subject.queue.push({ "resolve": resolve, "reject": reject });
|
|
|
|
|
subject.fetcher().then(result => {
|
|
|
|
|
subject.state = enum_initializer_state.successful;
|
|
|
|
|
subject.result = result;
|
|
|
|
|
initializer_actuate(subject);
|
|
|
|
|
}, reason => {
|
|
|
|
|
subject.state = enum_initializer_state.failed;
|
|
|
|
|
subject.reason = reason;
|
|
|
|
|
initializer_actuate(subject);
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case enum_initializer_state.waiting: {
|
|
|
|
|
return (call.promise_make((resolve, reject) => {
|
|
|
|
|
subject.queue.push({ "resolve": resolve, "reject": reject });
|
|
|
|
|
}));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case enum_initializer_state.successful: {
|
|
|
|
|
return (call.promise_resolve(subject.result));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case enum_initializer_state.failed: {
|
|
|
|
|
return (call.promise_reject(subject.reason));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error(`unhandled state ${subject.state}`));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
call.initializer_get = initializer_get;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function initializer_get_sync(subject) {
|
|
|
|
|
switch (subject.state) {
|
|
|
|
|
case enum_initializer_state.successful: {
|
|
|
|
|
return subject.result;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case enum_initializer_state.failed: {
|
|
|
|
|
throw subject.reason;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error(`unhandled state ${subject.state}`));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function initializer_set_sync(subject, result) {
|
|
|
|
|
switch (subject.state) {
|
|
|
|
|
case enum_initializer_state.successful: {
|
|
|
|
|
subject.result = result;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case enum_initializer_state.failed: {
|
|
|
|
|
subject.state = enum_initializer_state.successful;
|
|
|
|
|
subject.result = result;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error(`unhandled state ${subject.state}`));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})(call = lib_plankton.call || (lib_plankton.call = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:call«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var call;
|
|
|
|
|
(function (call) {
|
|
|
|
|
/*
|
|
|
|
|
The core idea of this library is to provide means for asynchronous program flow. The old-school way to do is,
|
|
|
|
|
is to use callbacks. While this approach is simple and easy to understand, it has some disadvantages. As an
|
|
|
|
|
attempt to relief and improve this, the promise-system was introduced. In principle it solves most of the
|
|
|
|
|
problems found in the callback-approach; however it has some downsides as well:
|
|
|
|
|
|
|
|
|
|
- Convolution of multiple principles
|
|
|
|
|
Promises unite the ideas of asynchronous program flow and error handling.
|
|
|
|
|
|
|
|
|
|
- Instant execution
|
|
|
|
|
Creating a promise results in the instant execution of the given executor prodecure. While this might be
|
|
|
|
|
convenient in some cases, it can be quite disturbing and counter-intuitive in others.
|
|
|
|
|
|
|
|
|
|
- Broken typing
|
|
|
|
|
The Promise system doesn't distinguish between an appending "then" (i.e. passing a function, which returns a
|
|
|
|
|
new promise) and a closing "then" (i.e. passing a function, which has no return value). On top of that it
|
|
|
|
|
allows returning simple values in an appending "then", which results in an implicit call of the executors
|
|
|
|
|
"resolve"-function. The price for these "pragmatic" features is that the whole system can't be typed well.
|
|
|
|
|
And even though JavaScript is not a strictly typed language, it was a quite questionable decision to design
|
|
|
|
|
the promise system in a way, which breaks typing from the start.
|
|
|
|
|
|
|
|
|
|
The deferral-system forseeks to solve these issues while retaining the advantages of the promise-system.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @desc activates the deferral and handles its output according to a given procedure
|
|
|
|
|
* @param {(value : type_value)=>void} procedure a function which receives the output of the deferral as argument
|
|
|
|
|
*/
|
|
|
|
|
function deferral_use(deferral, input, procedure) {
|
|
|
|
|
deferral.representation(input).then(value => {
|
|
|
|
|
procedure(value);
|
|
|
|
|
}, reason => {
|
|
|
|
|
throw reason;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
call.deferral_use = deferral_use;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @desc creates a deferral-subject (similar to "new Promise", where "convey" reflects "resolve"/"reject")
|
|
|
|
|
*/
|
|
|
|
|
function deferral_make(handler) {
|
|
|
|
|
return ({
|
|
|
|
|
"representation": ((input) => (new Promise((resolve, reject) => {
|
|
|
|
|
handler(input, resolve);
|
|
|
|
|
})))
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
call.deferral_make = deferral_make;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @desc wraps a simple function into a deferral (similar to "Promise.resolve"/"Promise.reject")
|
|
|
|
|
*/
|
|
|
|
|
function deferral_wrap(function_) {
|
|
|
|
|
return (deferral_make((input, convey) => convey(function_(input))));
|
|
|
|
|
}
|
|
|
|
|
call.deferral_wrap = deferral_wrap;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function deferral_id() {
|
|
|
|
|
return (deferral_make((input, convey) => convey(input)));
|
|
|
|
|
}
|
|
|
|
|
call.deferral_id = deferral_id;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function deferral_const(value) {
|
|
|
|
|
return (deferral_make((input, convey) => convey(value)));
|
|
|
|
|
}
|
|
|
|
|
call.deferral_const = deferral_const;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function deferral_delay(output, delay) {
|
|
|
|
|
return (deferral_make((input, convey) => {
|
|
|
|
|
setTimeout(() => convey(output), delay);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
call.deferral_delay = deferral_delay;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @desc connects two deferrals to form a new one; the output of the first is taken as input for the second
|
|
|
|
|
* (similar to "Promise.then" when passing a function which returns a new promise)
|
|
|
|
|
* @param {type_deferral<type_value1>} first a simple deferral
|
|
|
|
|
* @param {(value1 : type_value1)=>type_deferral<type_value2>} second a function depending from a value returning a deferral
|
|
|
|
|
*/
|
|
|
|
|
function deferral_compose_serial(first, second) {
|
|
|
|
|
return {
|
|
|
|
|
"representation": ((input) => first.representation(input).then((between) => second.representation(between)))
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
call.deferral_compose_serial = deferral_compose_serial;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function deferral_compose_parallel({ "left": deferral_left, "right": deferral_right, }) {
|
|
|
|
|
return (deferral_make((input, convey) => {
|
|
|
|
|
let object = {
|
|
|
|
|
"left": lib_plankton.pod.make_empty(),
|
|
|
|
|
"right": lib_plankton.pod.make_empty(),
|
|
|
|
|
};
|
|
|
|
|
let finish = function () {
|
|
|
|
|
if (lib_plankton.pod.is_filled(object.left)
|
|
|
|
|
&&
|
|
|
|
|
lib_plankton.pod.is_filled(object.right)) {
|
|
|
|
|
let result = {
|
|
|
|
|
"left": lib_plankton.pod.cull(object.left),
|
|
|
|
|
"right": lib_plankton.pod.cull(object.right),
|
|
|
|
|
};
|
|
|
|
|
convey(result);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
deferral_use(deferral_left, input, output_left => {
|
|
|
|
|
object.left = lib_plankton.pod.make_filled(output_left);
|
|
|
|
|
finish();
|
|
|
|
|
});
|
|
|
|
|
deferral_use(deferral_right, input, output_right => {
|
|
|
|
|
object.right = lib_plankton.pod.make_filled(output_right);
|
|
|
|
|
finish();
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
call.deferral_compose_parallel = deferral_compose_parallel;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @desc repeatedly applied serial composition
|
|
|
|
|
*/
|
|
|
|
|
function deferral_chain(members) {
|
|
|
|
|
return (members.reduce(
|
|
|
|
|
// (result, current) => deferral_compose_serial<type_value, type_value, type_value>(result, current),
|
|
|
|
|
deferral_compose_serial, deferral_id()));
|
|
|
|
|
}
|
|
|
|
|
call.deferral_chain = deferral_chain;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
export function deferral_bunch<type_input, type_output>(
|
|
|
|
|
members : {[name : string] : type_deferral<type_input, type_output>}
|
|
|
|
|
) : type_deferral<type_input, {[name : string] : type_output}> {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
})(call = lib_plankton.call || (lib_plankton.call = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:call«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var call;
|
|
|
|
|
(function (call) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_deferral {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor(subject) {
|
|
|
|
|
this.subject = subject;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static _cram(subject) {
|
|
|
|
|
return (new class_deferral(subject));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static _tear(instance) {
|
|
|
|
|
return instance.subject;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static make(handler) {
|
|
|
|
|
return (class_deferral._cram(call.deferral_make(handler)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
use(input, procedure) {
|
|
|
|
|
return (call.deferral_use(class_deferral._tear(this), input, procedure));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
compose_serial(second) {
|
|
|
|
|
return (class_deferral._cram(call.deferral_compose_serial(class_deferral._tear(this), class_deferral._tear(second))));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static chain(members) {
|
|
|
|
|
return (class_deferral._cram(call.deferral_chain(members.map(member => class_deferral._tear(member)))));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static wrap(function_) {
|
|
|
|
|
return (class_deferral._cram(call.deferral_wrap(function_)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static const_(value) {
|
|
|
|
|
return (class_deferral._cram(call.deferral_const(value)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static delay(output, delay) {
|
|
|
|
|
return (class_deferral._cram(call.deferral_delay(output, delay)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
call.class_deferral = class_deferral;
|
|
|
|
|
})(call = lib_plankton.call || (lib_plankton.call = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:call«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:call« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var call;
|
|
|
|
|
(function (call) {
|
|
|
|
|
/**
|
|
|
|
|
* converts the "arguments"-map into an array
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} args
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function args2list(args) {
|
|
|
|
|
return Object.keys(args).map(key => args[key]);
|
|
|
|
|
}
|
|
|
|
|
call.args2list = args2list;
|
|
|
|
|
/**
|
|
|
|
|
* just the empty function; useful for some callbacks etc.
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function nothing() {
|
|
|
|
|
}
|
|
|
|
|
call.nothing = nothing;
|
|
|
|
|
/**
|
|
|
|
|
* just the identity; useful for some callbacks etc.; defined as function instead of const for using type parameters
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function id(x) {
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
call.id = id;
|
|
|
|
|
/**
|
|
|
|
|
* just the identity; useful for some callbacks etc.
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function const_(x) {
|
|
|
|
|
return (y => x);
|
|
|
|
|
}
|
|
|
|
|
call.const_ = const_;
|
|
|
|
|
/**
|
|
|
|
|
* composes two functions (i.e. returns a function that return the result of the successive execution of both input-functions)
|
|
|
|
|
*
|
|
|
|
|
* @param {function} function_f
|
|
|
|
|
* @param {function} function_g
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function compose(function_f, function_g) {
|
|
|
|
|
return (function (x) {
|
|
|
|
|
// return function_g(function_f(x));
|
|
|
|
|
return function_g(function_f.apply(function_f, args2list(arguments)));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
call.compose = compose;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function curryfy_real(f, n) {
|
|
|
|
|
switch (n) {
|
|
|
|
|
case 0: {
|
|
|
|
|
throw (new Error("[curryfy] impossible"));
|
|
|
|
|
// break;
|
|
|
|
|
}
|
|
|
|
|
case 1: {
|
|
|
|
|
return f;
|
|
|
|
|
// break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
return (function (x) {
|
|
|
|
|
return (curryfy_real(function () { return f.apply(f, [x].concat(args2list(arguments))); }, n - 1));
|
|
|
|
|
});
|
|
|
|
|
// break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* transforms a function with sequential input to a function with leveled input; example: add(2,3) = curryfy(add)(2)(3)
|
|
|
|
|
*
|
|
|
|
|
* @param {function} f
|
|
|
|
|
* @return {function} the currified version of the in put function
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function curryfy(f) {
|
|
|
|
|
return curryfy_real(f, f.length);
|
|
|
|
|
}
|
|
|
|
|
call.curryfy = curryfy;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function convey(value, functions) {
|
|
|
|
|
let result = value;
|
|
|
|
|
functions.forEach(function_ => {
|
|
|
|
|
result = function_(result);
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
call.convey = convey;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function timeout(procedure, delay_in_seconds) {
|
|
|
|
|
return (
|
|
|
|
|
/*window.*/ setTimeout(procedure, Math.floor(delay_in_seconds * 1000)));
|
|
|
|
|
}
|
|
|
|
|
call.timeout = timeout;
|
|
|
|
|
/**
|
|
|
|
|
* Promise version of "setTimeout"
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function defer(seconds, action) {
|
|
|
|
|
return (new Promise((resolve, reject) => {
|
|
|
|
|
setTimeout(() => resolve(action()), Math.floor(seconds * 1000));
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
call.defer = defer;
|
|
|
|
|
/**
|
|
|
|
|
* a definition for a value being "defined"
|
|
|
|
|
*
|
|
|
|
|
* @author neuc
|
|
|
|
|
*/
|
|
|
|
|
function is_def(obj, options = {}) {
|
|
|
|
|
options = Object.assign({
|
|
|
|
|
"null_is_valid": false,
|
|
|
|
|
}, options);
|
|
|
|
|
return (!((typeof (obj) === "undefined")
|
|
|
|
|
||
|
|
|
|
|
(!options.null_is_valid && (obj === null))));
|
|
|
|
|
}
|
|
|
|
|
call.is_def = is_def;
|
|
|
|
|
/**
|
|
|
|
|
* returns the value if set and, when a type is specified, if the type is correct, if not return default_value
|
|
|
|
|
*
|
|
|
|
|
* @author neuc
|
|
|
|
|
*/
|
|
|
|
|
function def_val(value, default_value, options = {}) {
|
|
|
|
|
options = Object.assign({
|
|
|
|
|
"type": null,
|
|
|
|
|
"null_is_valid": false,
|
|
|
|
|
}, options);
|
|
|
|
|
if (is_def(value, { "null_is_valid": options.null_is_valid })
|
|
|
|
|
&&
|
|
|
|
|
(is_def(options.type)
|
|
|
|
|
? ((typeof (value) === options.type)
|
|
|
|
|
||
|
|
|
|
|
((value === null)
|
|
|
|
|
&&
|
|
|
|
|
options.null_is_valid))
|
|
|
|
|
: true)) {
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return default_value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
call.def_val = def_val;
|
|
|
|
|
;
|
|
|
|
|
/**
|
|
|
|
|
* provides the call for an attribute of a class as a regular function; useful for processing lists of objects
|
|
|
|
|
*
|
|
|
|
|
* @param {string} name the name of the attribute
|
|
|
|
|
* @return {function}
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function attribute(name) {
|
|
|
|
|
return (object => object[name]);
|
|
|
|
|
}
|
|
|
|
|
call.attribute = attribute;
|
|
|
|
|
/**
|
|
|
|
|
* provides a method of a class as a regular function; useful for processing lists of objects
|
|
|
|
|
*
|
|
|
|
|
* @param {string} name the name of the method
|
|
|
|
|
* @return {function}
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function method(name) {
|
|
|
|
|
return (function (object) { return object[name].apply(object, args2list(arguments).slice(1)); });
|
|
|
|
|
}
|
|
|
|
|
call.method = method;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function distinguish(coproduct, handlers, options = {}) {
|
|
|
|
|
options = Object.assign({
|
|
|
|
|
"fallback": null,
|
|
|
|
|
}, options);
|
|
|
|
|
if (coproduct.kind in handlers) {
|
|
|
|
|
const handler = handlers[coproduct.kind];
|
|
|
|
|
return handler(coproduct.data);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const message = ("unhandled kind '" + coproduct.kind + "'");
|
|
|
|
|
if (options.fallback !== null) {
|
|
|
|
|
console.warn(message);
|
|
|
|
|
return options.fallback(coproduct);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
call.distinguish = distinguish;
|
|
|
|
|
/**
|
|
|
|
|
* rate limiting algorithm, based on the idea of mana (magic power) in video games:
|
|
|
|
|
* - an actor has a fixed mana capacity, i.e. the maximum amount of available power
|
|
|
|
|
* - an actor has a fixed rate of mana regeneration, i.e. how fast the power is filled up (linear growth)
|
|
|
|
|
* - an action has a defined mana heft, i.e. how much power is required and deducted in order to execute it
|
|
|
|
|
* - mana states are represented by snapshots, i.e. the amount of power at a certain point in time
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
async function rate_limit_check(setup, heft) {
|
|
|
|
|
if (heft > setup.capacity) {
|
|
|
|
|
return Promise.resolve({
|
|
|
|
|
"granted": false,
|
|
|
|
|
"seconds": null,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// get current value
|
|
|
|
|
const current_timestamp = (Date.now() / 1000);
|
|
|
|
|
const old_snapshot_raw = (await setup.get_snapshot());
|
|
|
|
|
const old_snapshot = (old_snapshot_raw
|
|
|
|
|
??
|
|
|
|
|
{ "timestamp": current_timestamp, "value": setup.capacity });
|
|
|
|
|
const seconds_passed = (current_timestamp - old_snapshot.timestamp);
|
|
|
|
|
const current_value = Math.min(setup.capacity, (old_snapshot.value
|
|
|
|
|
+
|
|
|
|
|
(setup.regeneration_rate
|
|
|
|
|
*
|
|
|
|
|
seconds_passed)));
|
|
|
|
|
// analyze
|
|
|
|
|
if (current_value < heft) {
|
|
|
|
|
// too less
|
|
|
|
|
const seconds_needed = ((setup.regeneration_rate <= 0)
|
|
|
|
|
? null
|
|
|
|
|
: ((heft - old_snapshot.value) / setup.regeneration_rate));
|
|
|
|
|
return Promise.resolve({
|
|
|
|
|
"granted": false,
|
|
|
|
|
"seconds": ((seconds_needed === null) ? null : (seconds_needed - seconds_passed)),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// enough -> update snapshot
|
|
|
|
|
const new_value = (current_value - heft);
|
|
|
|
|
// set_snapshot
|
|
|
|
|
if (old_snapshot_raw === null) {
|
|
|
|
|
await setup.set_snapshot({ "timestamp": current_timestamp, "value": new_value });
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
await setup.update_snapshot(current_timestamp, (new_value - old_snapshot.value));
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve({
|
|
|
|
|
"granted": true,
|
|
|
|
|
"seconds": 0,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
call.rate_limit_check = rate_limit_check;
|
|
|
|
|
})(call = lib_plankton.call || (lib_plankton.call = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:file«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:file« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:file« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:file«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var file;
|
|
|
|
|
(function (file) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function read(path) {
|
|
|
|
|
return (fetch("/" + path)
|
|
|
|
|
.then(function (result) { return result.text(); }));
|
2024-09-09 12:13:10 +02:00
|
|
|
|
}
|
2024-09-11 17:24:20 +02:00
|
|
|
|
file.read = read;
|
2024-09-09 12:13:10 +02:00
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function write(path, content) {
|
|
|
|
|
return Promise.reject(new Error("not implemented / not possible"));
|
2024-09-09 12:13:10 +02:00
|
|
|
|
}
|
2024-09-11 17:24:20 +02:00
|
|
|
|
file.write = write;
|
2024-09-09 12:13:10 +02:00
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function blob_read_text(blob) {
|
|
|
|
|
return (lib_plankton.call.promise_make(function (resolve, reject) {
|
|
|
|
|
var reader = (new FileReader());
|
|
|
|
|
reader.addEventListener("load", function (event) {
|
|
|
|
|
resolve((reader.result));
|
|
|
|
|
});
|
|
|
|
|
reader.addEventListener("error", function (event) {
|
|
|
|
|
reject(new Error("reading file failed"));
|
2024-09-09 12:13:10 +02:00
|
|
|
|
});
|
2024-09-11 17:24:20 +02:00
|
|
|
|
reader.addEventListener("abort", function (event) {
|
|
|
|
|
reject(new Error("reading file aborted"));
|
|
|
|
|
});
|
|
|
|
|
reader.readAsText(blob);
|
2024-09-09 12:13:10 +02:00
|
|
|
|
}));
|
|
|
|
|
}
|
2024-09-11 17:24:20 +02:00
|
|
|
|
file.blob_read_text = blob_read_text;
|
2024-09-09 12:13:10 +02:00
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function blob_read_arraybuffer(blob) {
|
|
|
|
|
return (lib_plankton.call.promise_make(function (resolve, reject) {
|
|
|
|
|
var reader = (new FileReader());
|
|
|
|
|
reader.addEventListener("load", function (event) {
|
|
|
|
|
resolve((reader.result));
|
2024-09-09 12:13:10 +02:00
|
|
|
|
});
|
2024-09-11 17:24:20 +02:00
|
|
|
|
reader.addEventListener("error", function (event) {
|
|
|
|
|
reject(new Error("reading file failed"));
|
2024-09-09 12:13:10 +02:00
|
|
|
|
});
|
2024-09-11 17:24:20 +02:00
|
|
|
|
reader.addEventListener("abort", function (event) {
|
|
|
|
|
reject(new Error("reading file aborted"));
|
|
|
|
|
});
|
|
|
|
|
reader.readAsArrayBuffer(blob);
|
2024-09-09 12:13:10 +02:00
|
|
|
|
}));
|
|
|
|
|
}
|
2024-09-11 17:24:20 +02:00
|
|
|
|
file.blob_read_arraybuffer = blob_read_arraybuffer;
|
2024-09-09 12:13:10 +02:00
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function blob_read_dataurl(blob) {
|
|
|
|
|
return (lib_plankton.call.promise_make(function (resolve, reject) {
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
reader.addEventListener("load", function (event) {
|
|
|
|
|
resolve((reader.result));
|
|
|
|
|
});
|
|
|
|
|
reader.addEventListener("error", function (event) {
|
|
|
|
|
reject(new Error("reading file failed"));
|
|
|
|
|
});
|
|
|
|
|
reader.addEventListener("abort", function (event) {
|
|
|
|
|
reject(new Error("reading file aborted"));
|
2024-09-09 12:13:10 +02:00
|
|
|
|
});
|
2024-09-11 17:24:20 +02:00
|
|
|
|
reader.readAsDataURL(blob);
|
2024-09-09 12:13:10 +02:00
|
|
|
|
}));
|
|
|
|
|
}
|
2024-09-11 17:24:20 +02:00
|
|
|
|
file.blob_read_dataurl = blob_read_dataurl;
|
2024-09-09 12:13:10 +02:00
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function blob_write_text(text) {
|
|
|
|
|
var blob = (new Blob([text], { "type": "text/plain" }));
|
|
|
|
|
return lib_plankton.call.promise_resolve(blob);
|
|
|
|
|
}
|
|
|
|
|
file.blob_write_text = blob_write_text;
|
|
|
|
|
})(file = lib_plankton.file || (lib_plankton.file = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function map_clear(map_forEach, map_delete) {
|
|
|
|
|
map_forEach((value, key) => {
|
|
|
|
|
map_delete(key);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
structures.map_clear = map_clear;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function map_keys(map_forEach) {
|
|
|
|
|
let keys = [];
|
|
|
|
|
map_forEach((value, key) => {
|
|
|
|
|
keys.push(key);
|
|
|
|
|
});
|
|
|
|
|
return keys;
|
|
|
|
|
}
|
|
|
|
|
structures.map_keys = map_keys;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function map_values(map_forEach) {
|
|
|
|
|
let values = [];
|
|
|
|
|
map_forEach((value, key) => {
|
|
|
|
|
values.push(value);
|
|
|
|
|
});
|
|
|
|
|
return values;
|
|
|
|
|
}
|
|
|
|
|
structures.map_values = map_values;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function map_pairs(map_forEach) {
|
|
|
|
|
let pairs = [];
|
|
|
|
|
map_forEach((value, key) => {
|
|
|
|
|
let pair = { "key": key, "value": value };
|
|
|
|
|
pairs.push(pair);
|
|
|
|
|
});
|
|
|
|
|
return pairs;
|
|
|
|
|
}
|
|
|
|
|
structures.map_pairs = map_pairs;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function map_toString(map_forEach, show_key = instance_show, show_value = instance_show) {
|
|
|
|
|
return ("["
|
|
|
|
|
+
|
|
|
|
|
(map_pairs(map_forEach)
|
|
|
|
|
.map(({ "key": key, "value": value }) => (show_key(key)
|
|
|
|
|
+
|
|
|
|
|
" -> "
|
|
|
|
|
+
|
|
|
|
|
show_value(value)))
|
|
|
|
|
.join(", "))
|
|
|
|
|
+
|
|
|
|
|
"]");
|
|
|
|
|
}
|
|
|
|
|
structures.map_toString = map_toString;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_mapbase {
|
|
|
|
|
/**
|
|
|
|
|
* @desc [constructor]
|
|
|
|
|
*/
|
|
|
|
|
constructor() {
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [mutator]
|
|
|
|
|
*/
|
|
|
|
|
clear() {
|
|
|
|
|
return (structures.map_clear((procedure) => this.forEach(procedure), (key) => this.delete(key)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
get_safe(key) {
|
|
|
|
|
try {
|
|
|
|
|
const value = this.get(key);
|
|
|
|
|
return lib_plankton.pod.class_pod.filled(value);
|
|
|
|
|
}
|
|
|
|
|
catch (error) {
|
|
|
|
|
return lib_plankton.pod.class_pod.empty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
*/
|
|
|
|
|
keys() {
|
|
|
|
|
return (structures.map_keys((procedure) => this.forEach(procedure)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
*/
|
|
|
|
|
values() {
|
|
|
|
|
return (structures.map_values((procedure) => this.forEach(procedure)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
*/
|
|
|
|
|
pairs() {
|
|
|
|
|
return (structures.map_pairs((procedure) => this.forEach(procedure)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
*/
|
|
|
|
|
toString(show_key = instance_show, show_value = instance_show) {
|
|
|
|
|
return (structures.map_toString((procedure) => this.forEach(procedure), show_key, show_value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.class_mapbase = class_mapbase;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_pair {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor(first, second) {
|
|
|
|
|
this.first = first;
|
|
|
|
|
this.second = second;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [getter]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
first_get() {
|
|
|
|
|
return this.first;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [getter]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
second_get() {
|
|
|
|
|
return this.second;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [mutator] [setter]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
first_set(first) {
|
|
|
|
|
this.first = first;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [mutator] [setter]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
second_set(second) {
|
|
|
|
|
this.second = second;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
swap() {
|
|
|
|
|
return (new class_pair(this.second, this.first));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
transform(transform_first, transform_second) {
|
|
|
|
|
return (new class_pair(transform_first(this.first), transform_second(this.second)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [implementation]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
_clone() {
|
|
|
|
|
return (new class_pair(instance_clone(this.first), instance_clone(this.second)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [implementation]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
_hash() {
|
|
|
|
|
return ("pair_" + instance_hash(this.first) + "_" + instance_hash(this.second) + "");
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [implementation]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
_collate(pair) {
|
|
|
|
|
return (instance_collate(this.first, pair.first)
|
|
|
|
|
&&
|
|
|
|
|
instance_collate(this.second, pair.second));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [implementation]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
_show() {
|
|
|
|
|
return ("(" + instance_show(this.first) + "," + instance_show(this.second) + ")");
|
|
|
|
|
}
|
2024-09-09 12:13:10 +02:00
|
|
|
|
}
|
2024-09-11 17:24:20 +02:00
|
|
|
|
structures.class_pair = class_pair;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_construct(collation, elements = []) {
|
|
|
|
|
let subject = {
|
|
|
|
|
"elements": []
|
|
|
|
|
};
|
|
|
|
|
elements.forEach(element => set_add(collation, subject, element));
|
|
|
|
|
return subject;
|
|
|
|
|
}
|
|
|
|
|
structures.set_construct = set_construct;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_size(subject) {
|
|
|
|
|
return subject.elements.length;
|
|
|
|
|
}
|
|
|
|
|
structures.set_size = set_size;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_has(collation, subject, element) {
|
|
|
|
|
return (subject.elements
|
|
|
|
|
.some(element_ => collation(element, element_)));
|
|
|
|
|
}
|
|
|
|
|
structures.set_has = set_has;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [mutator]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_add(collation, subject, element) {
|
|
|
|
|
if (!set_has(collation, subject, element)) {
|
|
|
|
|
subject.elements.push(element);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.set_add = set_add;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [mutator]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_pop(subject) {
|
|
|
|
|
if (subject.elements.length == 0) {
|
|
|
|
|
return lib_plankton.pod.make_empty();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return lib_plankton.pod.make_filled(subject.elements.pop());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.set_pop = set_pop;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_forEach(subject, function_) {
|
|
|
|
|
subject.elements.forEach(element => function_(element));
|
|
|
|
|
}
|
|
|
|
|
structures.set_forEach = set_forEach;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_map(collation, subject, transformator) {
|
|
|
|
|
return (set_construct(collation, subject.elements.map(element_from => transformator(element_from))));
|
|
|
|
|
}
|
|
|
|
|
structures.set_map = set_map;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_filter(subject, predicate) {
|
|
|
|
|
return (set_construct((x, y) => false, subject.elements.filter(element => predicate(element))));
|
|
|
|
|
}
|
|
|
|
|
structures.set_filter = set_filter;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_dump(subject) {
|
|
|
|
|
return subject.elements;
|
|
|
|
|
}
|
|
|
|
|
structures.set_dump = set_dump;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_subset(collation, subject, object) {
|
|
|
|
|
return (subject.elements
|
|
|
|
|
.every(element => set_has(collation, object, element)));
|
|
|
|
|
}
|
|
|
|
|
structures.set_subset = set_subset;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_superset(collation, subject, object) {
|
|
|
|
|
return (object.elements
|
|
|
|
|
.every(element => set_has(collation, subject, element)));
|
|
|
|
|
}
|
|
|
|
|
structures.set_superset = set_superset;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_equals(collation, subject, object) {
|
|
|
|
|
return (set_subset(collation, subject, object)
|
|
|
|
|
&&
|
|
|
|
|
set_superset(collation, subject, object));
|
|
|
|
|
}
|
|
|
|
|
structures.set_equals = set_equals;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_toString(show_element, subject) {
|
|
|
|
|
return ("{"
|
|
|
|
|
+
|
|
|
|
|
subject.elements.map(element => show_element(element)).join(",")
|
|
|
|
|
+
|
|
|
|
|
"}");
|
|
|
|
|
}
|
|
|
|
|
structures.set_toString = set_toString;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_empty(subject) {
|
|
|
|
|
return (subject.elements.length == 0);
|
|
|
|
|
}
|
|
|
|
|
structures.set_empty = set_empty;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_union(collation, subject, object) {
|
|
|
|
|
let result = set_construct(collation, []);
|
|
|
|
|
subject.elements.forEach(element => set_add(collation, result, element));
|
|
|
|
|
object.elements.forEach(element => set_add(collation, result, element));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
structures.set_union = set_union;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_intersection(collation, subject, object) {
|
|
|
|
|
let result = set_construct(collation, []);
|
|
|
|
|
subject.elements.forEach(element => {
|
|
|
|
|
if (set_has(collation, object, element)) {
|
|
|
|
|
set_add(collation, result, element);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
structures.set_intersection = set_intersection;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_difference(collation, subject, object) {
|
|
|
|
|
let result = set_construct(collation, []);
|
|
|
|
|
subject.elements.forEach(element => {
|
|
|
|
|
if (!set_has(collation, object, element)) {
|
|
|
|
|
set_add(collation, result, element);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
structures.set_difference = set_difference;
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_symmetric_difference(collation, subject, object) {
|
|
|
|
|
// X $ Y = (X ∪ Y) \ (X ∩ Y)
|
|
|
|
|
return (set_difference(collation, set_union(collation, subject, object), set_intersection(collation, subject, object)));
|
|
|
|
|
}
|
|
|
|
|
structures.set_symmetric_difference = set_symmetric_difference;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_union_all(collation, sets) {
|
|
|
|
|
return (sets.reduce((x, y) => ((x == null) ? y : set_union(collation, x, y)), null));
|
|
|
|
|
}
|
|
|
|
|
structures.set_union_all = set_union_all;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_intersection_all(collation, sets) {
|
|
|
|
|
return (sets.reduce((x, y) => ((x == null) ? y : set_intersection(collation, x, y)), null));
|
|
|
|
|
}
|
|
|
|
|
structures.set_intersection_all = set_intersection_all;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_set {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor(elements = [], equality = instance_collate /*<type_element>*/) {
|
|
|
|
|
this.equality = equality;
|
|
|
|
|
this.subject = structures.set_construct(equality, elements);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static from_subject(equality = instance_collate /*<type_element>*/, subject) {
|
|
|
|
|
let set = new class_set([], equality);
|
|
|
|
|
set.subject = subject;
|
|
|
|
|
return set;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
size() {
|
|
|
|
|
return structures.set_size(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
has(element) {
|
|
|
|
|
return structures.set_has(this.equality, this.subject, element);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [mutator]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
add(element) {
|
|
|
|
|
return structures.set_add(this.equality, this.subject, element);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [mutator]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
pop() {
|
|
|
|
|
return (new lib_plankton.pod.class_pod(structures.set_pop(this.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
forEach(function_) {
|
|
|
|
|
return structures.set_forEach(this.subject, function_);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
map(transformator, equality = instance_collate /*<type_element_>*/) {
|
|
|
|
|
return (class_set.from_subject(equality, structures.set_map(equality, this.subject, transformator)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
filter(predicate) {
|
|
|
|
|
return (class_set.from_subject(this.equality, structures.set_filter(this.subject, predicate)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
dump() {
|
|
|
|
|
return structures.set_dump(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
subset(set) {
|
|
|
|
|
return structures.set_subset(this.equality, this.subject, set.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
superset(set) {
|
|
|
|
|
return structures.set_superset(this.equality, this.subject, set.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
equals(set) {
|
|
|
|
|
return structures.set_equals(this.equality, this.subject, set.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
toString() {
|
|
|
|
|
return structures.set_toString(instance_show, this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
empty() {
|
|
|
|
|
return structures.set_empty(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
union(set) {
|
|
|
|
|
return (class_set.from_subject(this.equality, structures.set_union(this.equality, this.subject, set.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
intersection(set) {
|
|
|
|
|
return (class_set.from_subject(this.equality, structures.set_intersection(this.equality, this.subject, set.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
difference(set) {
|
|
|
|
|
return (class_set.from_subject(this.equality, structures.set_difference(this.equality, this.subject, set.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
symmetric_difference(set) {
|
|
|
|
|
return (class_set.from_subject(this.equality, structures.set_symmetric_difference(this.equality, this.subject, set.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [implementation]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
_collate(set) {
|
|
|
|
|
return structures.set_equals(this.equality, this.subject, set.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [implementation]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
_show() {
|
|
|
|
|
return structures.set_toString(instance_show, this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static union_all(sets) {
|
|
|
|
|
if (sets.length === 0) {
|
|
|
|
|
let message = "empty union";
|
|
|
|
|
// console.warn("--", message);
|
|
|
|
|
return (new class_set());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return (class_set.from_subject(sets[0].equality, structures.set_union_all(sets[0].equality, sets.map(set => set.subject))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static intersection_all(sets) {
|
|
|
|
|
if (sets.length === 0) {
|
|
|
|
|
let message = "empty intersection is not defined";
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return (class_set.from_subject(sets[0].equality, structures.set_intersection_all(sets[0].equality, sets.map(set => set.subject))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.class_set = class_set;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function stack_construct() {
|
|
|
|
|
return {
|
|
|
|
|
"elements": []
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
structures.stack_construct = stack_construct;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function stack_size(subject) {
|
|
|
|
|
return subject.elements.length;
|
|
|
|
|
}
|
|
|
|
|
structures.stack_size = stack_size;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function stack_scan(subject) {
|
|
|
|
|
if (stack_size(subject) == 0) {
|
|
|
|
|
let message = "empty";
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return subject.elements[subject.elements.length - 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.stack_scan = stack_scan;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function stack_take(subject) {
|
|
|
|
|
let element = stack_scan(subject);
|
|
|
|
|
subject.elements.pop();
|
|
|
|
|
return element;
|
|
|
|
|
}
|
|
|
|
|
structures.stack_take = stack_take;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function stack_give(subject, element) {
|
|
|
|
|
subject.elements.push(element);
|
|
|
|
|
}
|
|
|
|
|
structures.stack_give = stack_give;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_stack {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor() {
|
|
|
|
|
this.subject = structures.stack_construct();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
size() {
|
|
|
|
|
return structures.stack_size(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
scan() {
|
|
|
|
|
return structures.stack_scan(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
take() {
|
|
|
|
|
return structures.stack_take(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
give(element) {
|
|
|
|
|
return structures.stack_give(this.subject, element);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.class_stack = class_stack;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function queue_construct() {
|
|
|
|
|
return {
|
|
|
|
|
"elements": []
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
structures.queue_construct = queue_construct;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function queue_size(subject) {
|
|
|
|
|
return subject.elements.length;
|
|
|
|
|
}
|
|
|
|
|
structures.queue_size = queue_size;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function queue_scan(subject) {
|
|
|
|
|
if (queue_size(subject) == 0) {
|
|
|
|
|
let message = "empty";
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return subject.elements[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.queue_scan = queue_scan;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function queue_take(subject) {
|
|
|
|
|
let element = queue_scan(subject);
|
|
|
|
|
subject.elements.shift();
|
|
|
|
|
return element;
|
|
|
|
|
}
|
|
|
|
|
structures.queue_take = queue_take;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function queue_give(subject, element) {
|
|
|
|
|
subject.elements.push(element);
|
|
|
|
|
}
|
|
|
|
|
structures.queue_give = queue_give;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_queue {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor() {
|
|
|
|
|
this.subject = structures.queue_construct();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
size() {
|
|
|
|
|
return structures.queue_size(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
scan() {
|
|
|
|
|
return structures.queue_scan(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
take() {
|
|
|
|
|
return structures.queue_take(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
give(element) {
|
|
|
|
|
return structures.queue_give(this.subject, element);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.class_queue = class_queue;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function simplemap_construct() {
|
|
|
|
|
return {
|
|
|
|
|
"memory": {}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
structures.simplemap_construct = simplemap_construct;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function simplemap_has(subject, key) {
|
|
|
|
|
return (key in subject.memory);
|
|
|
|
|
}
|
|
|
|
|
structures.simplemap_has = simplemap_has;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function simplemap_get_safe(subject, key) {
|
|
|
|
|
if (key in subject.memory) {
|
|
|
|
|
return lib_plankton.pod.make_filled(subject.memory[key]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return lib_plankton.pod.make_empty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.simplemap_get_safe = simplemap_get_safe;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function simplemap_get(subject, key, fallback = lib_plankton.pod.make_empty()) {
|
|
|
|
|
if (key in subject.memory) {
|
|
|
|
|
return subject.memory[key];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (!lib_plankton.pod.is_filled(fallback)) {
|
|
|
|
|
throw (new Error("key not found"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return lib_plankton.pod.cull(fallback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.simplemap_get = simplemap_get;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function simplemap_set(subject, key, value) {
|
|
|
|
|
subject.memory[key] = value;
|
|
|
|
|
}
|
|
|
|
|
structures.simplemap_set = simplemap_set;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function simplemap_delete(subject, key) {
|
|
|
|
|
delete subject.memory[key];
|
|
|
|
|
}
|
|
|
|
|
structures.simplemap_delete = simplemap_delete;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function simplemap_clear(subject) {
|
|
|
|
|
// subject.memory = {};
|
|
|
|
|
Object.keys(subject.memory).forEach(key => { delete subject.memory[key]; });
|
|
|
|
|
}
|
|
|
|
|
structures.simplemap_clear = simplemap_clear;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function simplemap_forEach(subject, function_) {
|
|
|
|
|
Object.keys(subject.memory).forEach(key => {
|
|
|
|
|
let value = subject.memory[key];
|
|
|
|
|
function_(value, key);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
structures.simplemap_forEach = simplemap_forEach;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function simplemap_from_object(object) {
|
|
|
|
|
let subject = simplemap_construct();
|
|
|
|
|
Object.keys(object).forEach((key) => {
|
|
|
|
|
let value = object[key];
|
|
|
|
|
subject.memory[key] = value;
|
|
|
|
|
});
|
|
|
|
|
return subject;
|
|
|
|
|
}
|
|
|
|
|
structures.simplemap_from_object = simplemap_from_object;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_simplemap extends structures.class_mapbase {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static make() {
|
|
|
|
|
const subject = structures.simplemap_construct();
|
|
|
|
|
return (new class_simplemap(subject));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static from_object(object) {
|
|
|
|
|
return (new class_simplemap(structures.simplemap_from_object(object)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @desc [constructor]
|
|
|
|
|
*/
|
|
|
|
|
constructor(subject = structures.simplemap_construct()) {
|
|
|
|
|
super();
|
|
|
|
|
this.subject = subject;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
has(key) {
|
|
|
|
|
return structures.simplemap_has(this.subject, key);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
get(key, fallback = lib_plankton.pod.class_pod.empty()) {
|
|
|
|
|
return structures.simplemap_get(this.subject, key, fallback.tear());
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
set(key, value) {
|
|
|
|
|
return structures.simplemap_set(this.subject, key, value);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
delete(key) {
|
|
|
|
|
return structures.simplemap_delete(this.subject, key);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
forEach(procedure) {
|
|
|
|
|
return structures.simplemap_forEach(this.subject, procedure);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.class_simplemap = class_simplemap;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function hashmap_construct(hashing, pairs) {
|
|
|
|
|
const subject = {
|
|
|
|
|
"core": structures.simplemap_construct(),
|
|
|
|
|
"hashing": hashing,
|
|
|
|
|
};
|
|
|
|
|
pairs.forEach((pair) => {
|
|
|
|
|
hashmap_set(subject, pair.key, pair.value);
|
|
|
|
|
});
|
|
|
|
|
return subject;
|
|
|
|
|
}
|
|
|
|
|
structures.hashmap_construct = hashmap_construct;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function hashmap_has(subject, key) {
|
|
|
|
|
const key_ = subject.hashing(key);
|
|
|
|
|
return structures.simplemap_has(subject.core, key_);
|
|
|
|
|
}
|
|
|
|
|
structures.hashmap_has = hashmap_has;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function hashmap_get(subject, key, fallback = lib_plankton.pod.make_empty()) {
|
|
|
|
|
/*
|
|
|
|
|
we have to adjust the fallback argument, so that it can be used in our underlying simplemap core
|
|
|
|
|
therefore we pack the value together with any key as dummy
|
|
|
|
|
*/
|
|
|
|
|
const fallback_ = lib_plankton.pod.propagate(fallback, (value) => ({
|
|
|
|
|
"key": key,
|
|
|
|
|
"value": value
|
|
|
|
|
}));
|
|
|
|
|
const key_ = subject.hashing(key);
|
|
|
|
|
return (structures.simplemap_get(subject.core, key_, fallback_)
|
|
|
|
|
.value);
|
|
|
|
|
}
|
|
|
|
|
structures.hashmap_get = hashmap_get;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function hashmap_set(subject, key, value) {
|
|
|
|
|
const key_ = subject.hashing(key);
|
|
|
|
|
return (structures.simplemap_set(subject.core, key_, { "key": key, "value": value }));
|
|
|
|
|
}
|
|
|
|
|
structures.hashmap_set = hashmap_set;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function hashmap_delete(subject, key) {
|
|
|
|
|
const key_ = subject.hashing(key);
|
|
|
|
|
return (structures.simplemap_delete(subject.core, key_));
|
|
|
|
|
}
|
|
|
|
|
structures.hashmap_delete = hashmap_delete;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function hashmap_clear(subject) {
|
|
|
|
|
return structures.simplemap_clear(subject.core);
|
|
|
|
|
}
|
|
|
|
|
structures.hashmap_clear = hashmap_clear;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function hashmap_forEach(subject, procedure) {
|
|
|
|
|
return (structures.simplemap_forEach(subject.core, ({ "key": key, "value": value }, key_) => {
|
|
|
|
|
procedure(value, key);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
structures.hashmap_forEach = hashmap_forEach;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function hashmap_dump(subject) {
|
|
|
|
|
let result = [];
|
|
|
|
|
hashmap_forEach(subject, (value, key) => {
|
|
|
|
|
result.push({
|
|
|
|
|
"key": key,
|
|
|
|
|
"value": value,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
structures.hashmap_dump = hashmap_dump;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_hashmap extends structures.class_mapbase {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @desc [constructor]
|
|
|
|
|
*/
|
|
|
|
|
constructor(hashing = instance_hash, pairs = []) {
|
|
|
|
|
super();
|
|
|
|
|
this.subject = structures.hashmap_construct(hashing, pairs);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
has(key) {
|
|
|
|
|
return structures.hashmap_has(this.subject, key);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
get(key, fallback = lib_plankton.pod.class_pod.empty()) {
|
|
|
|
|
return structures.hashmap_get(this.subject, key, fallback.tear());
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
set(key, value) {
|
|
|
|
|
return structures.hashmap_set(this.subject, key, value);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
delete(key) {
|
|
|
|
|
return structures.hashmap_delete(this.subject, key);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
forEach(procedure) {
|
|
|
|
|
return structures.hashmap_forEach(this.subject, procedure);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.class_hashmap = class_hashmap;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function collatemap_construct() {
|
|
|
|
|
return {
|
|
|
|
|
"pairs": [],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
structures.collatemap_construct = collatemap_construct;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function collatemap_has(collation, subject, key) {
|
|
|
|
|
return subject.pairs.some((pair) => collation(key, pair.key));
|
|
|
|
|
}
|
|
|
|
|
structures.collatemap_has = collatemap_has;
|
|
|
|
|
/**
|
|
|
|
|
* @todo use .find
|
|
|
|
|
*/
|
|
|
|
|
function collatemap_get(collation, subject, key, fallback) {
|
|
|
|
|
let value;
|
|
|
|
|
const found = (subject.pairs
|
|
|
|
|
.some((pair) => {
|
|
|
|
|
if (collation(key, pair.key)) {
|
|
|
|
|
value = pair.value;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
if (found) {
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (!lib_plankton.pod.is_filled(fallback)) {
|
|
|
|
|
throw (new Error("key not found"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return lib_plankton.pod.cull(fallback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.collatemap_get = collatemap_get;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function collatemap_set(collation, subject, key, value) {
|
|
|
|
|
const found = (subject.pairs
|
|
|
|
|
.some((pair) => {
|
|
|
|
|
if (collation(key, pair.key)) {
|
|
|
|
|
pair.value = value;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
if (found) {
|
|
|
|
|
// nothing
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
subject.pairs.push({
|
|
|
|
|
"key": key,
|
|
|
|
|
"value": value
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.collatemap_set = collatemap_set;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function collatemap_delete(collation, subject, key) {
|
|
|
|
|
let index;
|
|
|
|
|
const found = (subject.pairs
|
|
|
|
|
.some((pair, index_) => {
|
|
|
|
|
if (collation(key, pair.key)) {
|
|
|
|
|
index = index_;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
if (found) {
|
|
|
|
|
subject.pairs.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.collatemap_delete = collatemap_delete;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function collatemap_forEach(
|
|
|
|
|
// collation : type_collation<type_key>,
|
|
|
|
|
subject, function_) {
|
|
|
|
|
subject.pairs
|
|
|
|
|
.forEach((pair) => {
|
|
|
|
|
function_(pair.value, pair.key);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
structures.collatemap_forEach = collatemap_forEach;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_collatemap extends structures.class_mapbase {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @desc [constructor]
|
|
|
|
|
*/
|
|
|
|
|
constructor(collation = instance_collate) {
|
|
|
|
|
super();
|
|
|
|
|
this.subject = structures.collatemap_construct();
|
|
|
|
|
this.collation = collation;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
has(key) {
|
|
|
|
|
return structures.collatemap_has(this.collation, this.subject, key);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
get(key, fallback = lib_plankton.pod.class_pod.empty()) {
|
|
|
|
|
return structures.collatemap_get(this.collation, this.subject, key, fallback.tear());
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
set(key, value) {
|
|
|
|
|
return structures.collatemap_set(this.collation, this.subject, key, value);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
delete(key) {
|
|
|
|
|
return structures.collatemap_delete(this.collation, this.subject, key);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @implementation
|
|
|
|
|
*/
|
|
|
|
|
forEach(procedure) {
|
|
|
|
|
return structures.collatemap_forEach(this.subject, procedure);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.class_collatemap = class_collatemap;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
structures.class_map = class_collatemap;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_graph {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor(equality = null, nodes = [], edges = []) {
|
|
|
|
|
if (equality == null) {
|
|
|
|
|
// equality = ((node1, node2) => lib_plankton.trait.call("collatable", "collate", {"kind": "auto"}, {"first": node1, "second": node2}));
|
|
|
|
|
equality = instance_collate /*<type_node>*/;
|
|
|
|
|
}
|
|
|
|
|
this.equality = equality;
|
|
|
|
|
this.nodes = nodes;
|
|
|
|
|
this.edges = edges;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [getter]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
nodes_get() {
|
|
|
|
|
return this.nodes;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [mutator]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
add_node(node) {
|
|
|
|
|
this.nodes.push(node);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [getter]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
edges_get() {
|
|
|
|
|
return this.edges;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [mutator]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
add_edge(edge) {
|
|
|
|
|
this.edges.push(edge);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
has(node) {
|
|
|
|
|
return this.nodes.some(node_ => this.equality(node, node_));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
outgoing(node) {
|
|
|
|
|
return this.edges.filter(edge => this.equality(edge.from, node));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
incoming(node) {
|
|
|
|
|
return this.edges.filter(edge => this.equality(edge.to, node));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
without(pivot) {
|
|
|
|
|
return (new class_graph(this.equality, this.nodes.filter(node => (!this.equality(node, pivot))), this.edges.filter(edge => ((!this.equality(edge.from, pivot)) && (!this.equality(edge.to, pivot))))));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] returns the topologic sorting of the nodes (if it exists)
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
topsort() {
|
|
|
|
|
let graph = this;
|
|
|
|
|
if (graph.nodes.length == 0) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let pivot;
|
|
|
|
|
let found = graph.nodes.some(node => {
|
|
|
|
|
let count = graph.edges.filter(edge => this.equality(edge.to, node)).length;
|
|
|
|
|
if (count == 0) {
|
|
|
|
|
pivot = node;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// console.info("'" + String(node) + "' has " + count.toString() + " incoming edges");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (found) {
|
|
|
|
|
return [pivot].concat(graph.without(pivot).topsort());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw (new Error("circular dependencies found"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] returns the reduced version of a graph representing an order relation (implicit transitivity)
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
hasse() {
|
|
|
|
|
return (new class_graph(this.equality, this.nodes, this.edges.filter((edge) => {
|
|
|
|
|
let reachable = (this.outgoing(edge.from)
|
|
|
|
|
.map((edge_) => edge_.to)
|
|
|
|
|
.map((node) => this.outgoing(node).map((edge_) => edge_.to))
|
|
|
|
|
.reduce((x, y) => x.concat(y), []));
|
|
|
|
|
return (!reachable.some(node => this.equality(node, edge.to)));
|
|
|
|
|
})));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
output_dot({ "extract_id": extract_id = null, "extract_label": extract_label = null, "rotate": rotate = false, } = {}) {
|
|
|
|
|
let index = node => {
|
|
|
|
|
let i = -1;
|
|
|
|
|
let found = this.nodes.some((node_, i_) => {
|
|
|
|
|
if (this.equality(node, node_)) {
|
|
|
|
|
i = i_;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return i;
|
|
|
|
|
};
|
|
|
|
|
if (extract_id == null) {
|
|
|
|
|
// instance_hash
|
|
|
|
|
extract_id = (node => index(node).toFixed(0));
|
|
|
|
|
}
|
|
|
|
|
if (extract_label == null) {
|
|
|
|
|
extract_label = instance_show;
|
|
|
|
|
}
|
|
|
|
|
let nodeid = (node) => {
|
|
|
|
|
return ("node_" + extract_id(node));
|
|
|
|
|
};
|
|
|
|
|
return ({
|
|
|
|
|
"common": {
|
|
|
|
|
"fontname": "Monospace",
|
|
|
|
|
"rankdir": (rotate ? "LR" : "TB"),
|
|
|
|
|
},
|
|
|
|
|
"nodes": {
|
|
|
|
|
"head": {
|
|
|
|
|
"fontname": "Monospace",
|
|
|
|
|
"style": "filled",
|
|
|
|
|
"fillcolor": "0.35+0.6+0.8",
|
|
|
|
|
},
|
|
|
|
|
"list": this.nodes_get()
|
|
|
|
|
.map((node, index) => {
|
|
|
|
|
return {
|
|
|
|
|
"id": nodeid(node),
|
|
|
|
|
"attributes": {
|
|
|
|
|
"label": extract_label(node),
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
"edges": {
|
|
|
|
|
"head": {
|
|
|
|
|
"fontname": "Monospace"
|
|
|
|
|
},
|
|
|
|
|
"list": this.edges_get()
|
|
|
|
|
.map((edge, index) => {
|
|
|
|
|
return {
|
|
|
|
|
"id_from": nodeid(edge.from),
|
|
|
|
|
"id_to": nodeid(edge.to),
|
|
|
|
|
"attributes": {}
|
|
|
|
|
};
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.class_graph = class_graph;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
structures.relation_le = "le";
|
|
|
|
|
structures.relation_ge = "ge";
|
|
|
|
|
structures.relation_lt = "lt";
|
|
|
|
|
structures.relation_gt = "gt";
|
|
|
|
|
structures.relation_eq = "eq";
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function binnode_construct(data) {
|
|
|
|
|
return {
|
|
|
|
|
"data": data,
|
|
|
|
|
"left": null,
|
|
|
|
|
"right": null,
|
|
|
|
|
"depth": 1,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function binnode_isdef(subject) {
|
|
|
|
|
return (!(subject === null));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function binnode_child_get(subject, left) {
|
|
|
|
|
if (left) {
|
|
|
|
|
return subject.left;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return subject.right;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function binnode_child_set(subject, left, value) {
|
|
|
|
|
if (left) {
|
|
|
|
|
subject.left = value;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
subject.right = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo remove later on
|
|
|
|
|
*/
|
|
|
|
|
function binnode_update_depth(subject) {
|
|
|
|
|
subject.depth = (1
|
|
|
|
|
+
|
|
|
|
|
Math.max((binnode_isdef(subject.left) ? subject.left.depth : 0), (binnode_isdef(subject.right) ? subject.right.depth : 0)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo remove later
|
|
|
|
|
*/
|
|
|
|
|
function binnode_depth(subject) {
|
|
|
|
|
return (1
|
|
|
|
|
+
|
|
|
|
|
Math.max((binnode_isdef(subject.left) ? binnode_depth(subject.left) : 0), (binnode_isdef(subject.right) ? binnode_depth(subject.right) : 0)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo remove later on
|
|
|
|
|
*/
|
|
|
|
|
function binnode_check_depths(subject) {
|
|
|
|
|
return ((binnode_isdef(subject.left) ? binnode_check_depths(subject.left) : true)
|
|
|
|
|
&&
|
|
|
|
|
(binnode_isdef(subject.right) ? binnode_check_depths(subject.right) : true)
|
|
|
|
|
&&
|
|
|
|
|
(subject.depth === binnode_depth(subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function binnode_imbalance(subject) {
|
|
|
|
|
if (true) {
|
|
|
|
|
return ((binnode_isdef(subject.right) ? subject.right.depth : 0)
|
|
|
|
|
-
|
|
|
|
|
(binnode_isdef(subject.left) ? subject.left.depth : 0));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return ((binnode_isdef(subject.right) ? binnode_depth(subject.right) : 0)
|
|
|
|
|
-
|
|
|
|
|
(binnode_isdef(subject.left) ? binnode_depth(subject.left) : 0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function binnode_insert(compare, subject, data) {
|
|
|
|
|
let node;
|
|
|
|
|
const left = compare(data, subject.data);
|
|
|
|
|
if (binnode_child_get(subject, left) == null) {
|
|
|
|
|
node = binnode_construct(data);
|
|
|
|
|
binnode_child_set(subject, left, node);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
node = binnode_insert(compare, binnode_child_get(subject, left), data);
|
|
|
|
|
}
|
|
|
|
|
binnode_update_depth(subject);
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function binnode_update_parent(subject, parent, child) {
|
|
|
|
|
if (binnode_isdef(parent)) {
|
|
|
|
|
if (parent.left === subject) {
|
|
|
|
|
parent.left = child;
|
|
|
|
|
}
|
|
|
|
|
else if (parent.right === subject) {
|
|
|
|
|
parent.right = child;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.warn("-- updating parent failed :/");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function binnode_drag(subject, left, parent = null) {
|
|
|
|
|
let child = binnode_child_get(subject, !left);
|
|
|
|
|
let grandchild = binnode_child_get(child, left);
|
|
|
|
|
binnode_child_set(subject, !left, grandchild);
|
|
|
|
|
binnode_child_set(child, left, subject);
|
|
|
|
|
binnode_update_parent(subject, parent, child);
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function binnode_rebalance(subject, parent = null) {
|
|
|
|
|
// rebalance children first
|
|
|
|
|
{
|
|
|
|
|
if (binnode_isdef(subject.left)) {
|
|
|
|
|
binnode_rebalance(subject.left, subject);
|
|
|
|
|
if (binnode_isdef(parent))
|
|
|
|
|
binnode_update_depth(parent);
|
|
|
|
|
}
|
|
|
|
|
if (binnode_isdef(subject.right)) {
|
|
|
|
|
binnode_rebalance(subject.right, subject);
|
|
|
|
|
if (binnode_isdef(parent))
|
|
|
|
|
binnode_update_depth(parent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// now rebalance the current node
|
|
|
|
|
{
|
|
|
|
|
const imbalance = binnode_imbalance(subject);
|
|
|
|
|
if (Math.abs(imbalance) >= 2) {
|
|
|
|
|
const left = (imbalance < 0);
|
|
|
|
|
let child = binnode_child_get(subject, left);
|
|
|
|
|
const imbalance_ = binnode_imbalance(child);
|
|
|
|
|
if (imbalance * imbalance_ < 0) {
|
|
|
|
|
// sub dragging
|
|
|
|
|
let child_ = binnode_drag(child, left, subject);
|
|
|
|
|
binnode_update_depth(binnode_child_get(child_, left));
|
|
|
|
|
binnode_update_depth(child_);
|
|
|
|
|
}
|
|
|
|
|
// core dragging
|
|
|
|
|
let subject_ = binnode_drag(subject, !left, parent);
|
|
|
|
|
binnode_update_depth(subject);
|
|
|
|
|
binnode_update_depth(subject_);
|
|
|
|
|
if (parent != null)
|
|
|
|
|
binnode_update_depth(parent);
|
|
|
|
|
return subject_;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return subject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @desc see misc/foo.py for some interesting facts explaining the handlers
|
|
|
|
|
* @desc lists all nodes that match the given piece of the data with the given relation
|
|
|
|
|
*/
|
|
|
|
|
function binnode_search(compare, subject, data, relation = "eq") {
|
|
|
|
|
const x = subject.data;
|
|
|
|
|
const y = data;
|
|
|
|
|
const situation_le = compare(x, y);
|
|
|
|
|
const situation_ge = compare(y, x);
|
|
|
|
|
const situation_lt = (situation_le && (!situation_ge));
|
|
|
|
|
const situation_gt = ((!situation_le) && situation_ge);
|
|
|
|
|
const situation_eq = (situation_le && situation_ge);
|
|
|
|
|
// recursive call
|
|
|
|
|
const deepen = (left) => {
|
|
|
|
|
const child = binnode_child_get(subject, left);
|
|
|
|
|
if (binnode_isdef(child)) {
|
|
|
|
|
return binnode_search(compare, child, data, relation);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/*
|
|
|
|
|
handlers that describe how the search is to be executed;
|
|
|
|
|
if "subject", the current node is added to the search results (~ situation)
|
|
|
|
|
if "left", the left subtree is regarded as well
|
|
|
|
|
if "right", the right subtree is regarded as well
|
|
|
|
|
*/
|
|
|
|
|
const handlers = {
|
|
|
|
|
"lt": {
|
|
|
|
|
"subject": (situation_lt),
|
|
|
|
|
"left": (true),
|
|
|
|
|
"right": (situation_lt),
|
|
|
|
|
},
|
|
|
|
|
"le": {
|
|
|
|
|
"subject": (situation_le),
|
|
|
|
|
"left": (true),
|
|
|
|
|
"right": (situation_lt),
|
|
|
|
|
},
|
|
|
|
|
"eq": {
|
|
|
|
|
"subject": (situation_eq),
|
|
|
|
|
"left": (!situation_lt),
|
|
|
|
|
"right": (situation_lt),
|
|
|
|
|
},
|
|
|
|
|
"ge": {
|
|
|
|
|
"subject": (situation_ge),
|
|
|
|
|
"left": (!situation_lt),
|
|
|
|
|
"right": (true),
|
|
|
|
|
},
|
|
|
|
|
"gt": {
|
|
|
|
|
"subject": (situation_gt),
|
|
|
|
|
"left": (situation_gt),
|
|
|
|
|
"right": (true),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
if (relation in handlers) {
|
|
|
|
|
let result = [];
|
|
|
|
|
const handler = handlers[relation];
|
|
|
|
|
if (handler.subject) {
|
|
|
|
|
result = result.concat([subject]);
|
|
|
|
|
}
|
|
|
|
|
if (handler.left) {
|
|
|
|
|
result = result.concat(deepen(true));
|
|
|
|
|
}
|
|
|
|
|
if (handler.right) {
|
|
|
|
|
result = result.concat(deepen(false));
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const message = `unhandled relation '${relation}'`;
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @desc returns the first found node, which matches the given data or "null" if not found
|
|
|
|
|
*/
|
|
|
|
|
function binnode_find(compare, subject, data) {
|
|
|
|
|
const le = compare(data, subject.data);
|
|
|
|
|
const ge = compare(subject.data, data);
|
|
|
|
|
if (le && ge) {
|
|
|
|
|
return subject;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const child = binnode_child_get(subject, le);
|
|
|
|
|
return ((binnode_isdef(child))
|
|
|
|
|
? binnode_find(compare, child, data)
|
|
|
|
|
: null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function binnode_traverse(subject) {
|
|
|
|
|
return ([]
|
|
|
|
|
.concat((binnode_isdef(subject.left) ? binnode_traverse(subject.left) : []))
|
|
|
|
|
.concat([subject.data])
|
|
|
|
|
.concat((binnode_isdef(subject.right) ? binnode_traverse(subject.right) : [])));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function binnode_show(show_data, subject, depth = 0) {
|
|
|
|
|
const indent = (n, sequence = " ") => sequence["repeat"](n);
|
|
|
|
|
let str = "";
|
|
|
|
|
{
|
|
|
|
|
str += indent(depth);
|
|
|
|
|
str += show_data(subject.data);
|
|
|
|
|
str += (" " + "[" + binnode_imbalance(subject).toFixed(0) + "]");
|
|
|
|
|
str += (" " + "{" + binnode_depth(subject).toFixed(0) + "/" + subject.depth.toFixed(0) + "}");
|
|
|
|
|
str += "\n";
|
|
|
|
|
}
|
|
|
|
|
if (binnode_isdef(subject.left) || binnode_isdef(subject.right)) {
|
|
|
|
|
// left
|
|
|
|
|
{
|
|
|
|
|
if (binnode_isdef(subject.left)) {
|
|
|
|
|
str += binnode_show(show_data, subject.left, depth + 1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
str += (indent(depth + 1) + "~" + "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// right
|
|
|
|
|
{
|
|
|
|
|
if (binnode_isdef(subject.right)) {
|
|
|
|
|
str += binnode_show(show_data, subject.right, depth + 1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
str += (indent(depth + 1) + "~" + "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function bintree_construct() {
|
|
|
|
|
return {
|
|
|
|
|
"root": null,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
structures.bintree_construct = bintree_construct;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function bintree_depth(subject) {
|
|
|
|
|
return ((binnode_isdef(subject.root))
|
|
|
|
|
? binnode_depth(subject.root)
|
|
|
|
|
: 0);
|
|
|
|
|
}
|
|
|
|
|
structures.bintree_depth = bintree_depth;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo remove later on
|
|
|
|
|
*/
|
|
|
|
|
function bintree_check_depths(subject) {
|
|
|
|
|
return ((binnode_isdef(subject.root))
|
|
|
|
|
? binnode_check_depths(subject.root)
|
|
|
|
|
: true);
|
|
|
|
|
}
|
|
|
|
|
structures.bintree_check_depths = bintree_check_depths;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function bintree_insert(compare, subject, data, rebalance = true) {
|
|
|
|
|
// basic insertion
|
|
|
|
|
{
|
|
|
|
|
if (binnode_isdef(subject.root)) {
|
|
|
|
|
binnode_insert(compare, subject.root, data);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
subject.root = binnode_construct(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// rebalancing
|
|
|
|
|
{
|
|
|
|
|
if (rebalance) {
|
|
|
|
|
subject.root = binnode_rebalance(subject.root);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.bintree_insert = bintree_insert;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function bintree_search(compare, subject, data, relation = undefined) {
|
|
|
|
|
const binnodes = ((binnode_isdef(subject.root))
|
|
|
|
|
? binnode_search(compare, subject.root, data, relation)
|
|
|
|
|
: []);
|
|
|
|
|
return binnodes.map(binnode => binnode.data);
|
|
|
|
|
}
|
|
|
|
|
structures.bintree_search = bintree_search;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @deprecated only used for AVL-Tree-Index atm.
|
|
|
|
|
*/
|
|
|
|
|
function bintree_find(compare, subject, data) {
|
|
|
|
|
const binnode = ((binnode_isdef(subject.root))
|
|
|
|
|
? binnode_find(compare, subject.root, data)
|
|
|
|
|
: null);
|
|
|
|
|
if (binnode == null) {
|
|
|
|
|
const message = "not found";
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return binnode.data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
structures.bintree_find = bintree_find;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function bintree_traverse(subject) {
|
|
|
|
|
return ((binnode_isdef(subject.root))
|
|
|
|
|
? binnode_traverse(subject.root)
|
|
|
|
|
: []);
|
|
|
|
|
}
|
|
|
|
|
structures.bintree_traverse = bintree_traverse;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function bintree_show(show_data, subject) {
|
|
|
|
|
return ((binnode_isdef(subject.root))
|
|
|
|
|
? binnode_show(show_data, subject.root)
|
|
|
|
|
: "--");
|
|
|
|
|
}
|
|
|
|
|
structures.bintree_show = bintree_show;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo tidy up or remove
|
|
|
|
|
*/
|
|
|
|
|
function binnode_gather(subject, result = { "nodes": [], "edges": [], "lastid": 0 }) {
|
|
|
|
|
result.lastid += 1;
|
|
|
|
|
const node = { "id": result.lastid, "subject": subject };
|
|
|
|
|
result.nodes.push(node);
|
|
|
|
|
if (binnode_isdef(subject.left)) {
|
|
|
|
|
// result.lastid += 1;
|
|
|
|
|
const node_ = { "id": result.lastid + 1, "subject": subject.left };
|
|
|
|
|
result.edges.push({ "from": node, "to": node_ });
|
|
|
|
|
result = binnode_gather(subject.left, result);
|
|
|
|
|
}
|
|
|
|
|
if (binnode_isdef(subject.right)) {
|
|
|
|
|
// result.lastid += 1;
|
|
|
|
|
const node_ = { "id": result.lastid + 1, "subject": subject.right };
|
|
|
|
|
result.edges.push({ "from": node, "to": node_ });
|
|
|
|
|
result = binnode_gather(subject.right, result);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo tidy up or remove
|
|
|
|
|
*/
|
|
|
|
|
function bintree_to_graph(subject) {
|
|
|
|
|
const gathering = binnode_gather(subject.root);
|
|
|
|
|
const graph = new structures.class_graph((x, y) => (x.data == y.data), gathering.nodes, gathering.edges);
|
|
|
|
|
return graph;
|
|
|
|
|
}
|
|
|
|
|
structures.bintree_to_graph = bintree_to_graph;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:structures«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:structures« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:structures«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var structures;
|
|
|
|
|
(function (structures) {
|
2024-09-09 12:13:10 +02:00
|
|
|
|
/**
|
2024-09-11 17:24:20 +02:00
|
|
|
|
* @author fenris
|
2024-09-09 12:13:10 +02:00
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
class class_bintree {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor(compare = instance_compare) {
|
|
|
|
|
this.subject = structures.bintree_construct();
|
|
|
|
|
this.compare = compare;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
depth() {
|
|
|
|
|
return structures.bintree_depth(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
insert(data, rebalance = true) {
|
|
|
|
|
return structures.bintree_insert(this.compare, this.subject, data, rebalance);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
delete(data) {
|
|
|
|
|
let message = "not implemented";
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
search(relation, data) {
|
|
|
|
|
return structures.bintree_search(this.compare, this.subject, data, relation);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
traverse() {
|
|
|
|
|
return structures.bintree_traverse(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
show() {
|
|
|
|
|
return structures.bintree_show(instance_show /*<type_data>*/, this.subject);
|
|
|
|
|
}
|
2024-09-09 12:13:10 +02:00
|
|
|
|
}
|
2024-09-11 17:24:20 +02:00
|
|
|
|
structures.class_bintree = class_bintree;
|
|
|
|
|
})(structures = lib_plankton.structures || (lib_plankton.structures = {}));
|
2024-09-09 12:13:10 +02:00
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:code«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:code«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:code«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var code;
|
|
|
|
|
(function (code) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function inverse_encode(decode, to) {
|
|
|
|
|
return decode(to);
|
|
|
|
|
}
|
|
|
|
|
code.inverse_encode = inverse_encode;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function inverse_decode(encode, from) {
|
|
|
|
|
return encode(from);
|
|
|
|
|
}
|
|
|
|
|
code.inverse_decode = inverse_decode;
|
|
|
|
|
})(code = lib_plankton.code || (lib_plankton.code = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:code«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var code;
|
|
|
|
|
(function (code) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var class_code_inverse = /** @class */ (function () {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function class_code_inverse(subject) {
|
|
|
|
|
this.subject = subject;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_code_inverse.prototype.encode = function (to) {
|
|
|
|
|
var _this = this;
|
|
|
|
|
return code.inverse_encode(function (x) { return _this.subject.decode(x); }, to);
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_code_inverse.prototype.decode = function (from) {
|
|
|
|
|
var _this = this;
|
|
|
|
|
return code.inverse_decode(function (x) { return _this.subject.encode(x); }, from);
|
|
|
|
|
};
|
|
|
|
|
return class_code_inverse;
|
|
|
|
|
}());
|
|
|
|
|
code.class_code_inverse = class_code_inverse;
|
|
|
|
|
})(code = lib_plankton.code || (lib_plankton.code = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:code«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var code;
|
|
|
|
|
(function (code) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function pair_encode(encode_first, encode_second, from) {
|
|
|
|
|
var between = encode_first(from);
|
|
|
|
|
var to = encode_second(between);
|
|
|
|
|
return to;
|
|
|
|
|
}
|
|
|
|
|
code.pair_encode = pair_encode;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function pair_decode(decode_first, decode_second, to) {
|
|
|
|
|
var between = decode_second(to);
|
|
|
|
|
var from = decode_first(between);
|
|
|
|
|
return from;
|
|
|
|
|
}
|
|
|
|
|
code.pair_decode = pair_decode;
|
|
|
|
|
})(code = lib_plankton.code || (lib_plankton.code = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:code«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var code;
|
|
|
|
|
(function (code) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var class_code_pair = /** @class */ (function () {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function class_code_pair(first, second) {
|
|
|
|
|
this.first = first;
|
|
|
|
|
this.second = second;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_code_pair.prototype.encode = function (from) {
|
|
|
|
|
var _this = this;
|
|
|
|
|
return code.pair_encode(function (x) { return _this.first.encode(x); }, function (x) { return _this.second.encode(x); }, from);
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_code_pair.prototype.decode = function (to) {
|
|
|
|
|
var _this = this;
|
|
|
|
|
return code.pair_decode(function (x) { return _this.first.decode(x); }, function (x) { return _this.second.decode(x); }, to);
|
|
|
|
|
};
|
|
|
|
|
return class_code_pair;
|
|
|
|
|
}());
|
|
|
|
|
code.class_code_pair = class_code_pair;
|
|
|
|
|
})(code = lib_plankton.code || (lib_plankton.code = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:code«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var code;
|
|
|
|
|
(function (code) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function chain_encode(encode_links, from) {
|
|
|
|
|
var value = from;
|
|
|
|
|
encode_links
|
|
|
|
|
.forEach(function (link) {
|
|
|
|
|
value = link(value);
|
|
|
|
|
});
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
code.chain_encode = chain_encode;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function chain_decode(decode_links, to) {
|
|
|
|
|
var value = to;
|
|
|
|
|
decode_links
|
|
|
|
|
.reverse()
|
|
|
|
|
.forEach(function (link) {
|
|
|
|
|
value = link(value);
|
|
|
|
|
});
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
code.chain_decode = chain_decode;
|
|
|
|
|
})(code = lib_plankton.code || (lib_plankton.code = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:code«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var code;
|
|
|
|
|
(function (code) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var class_code_chain = /** @class */ (function () {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function class_code_chain(links) {
|
|
|
|
|
this.links = links;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_code_chain.prototype.encode = function (from) {
|
|
|
|
|
return code.chain_encode(this.links.map(function (link) { return (function (x) { return link.encode(x); }); }), from);
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_code_chain.prototype.decode = function (to) {
|
|
|
|
|
return code.chain_decode(this.links.map(function (link) { return (function (x) { return link.decode(x); }); }), to);
|
|
|
|
|
};
|
|
|
|
|
return class_code_chain;
|
|
|
|
|
}());
|
|
|
|
|
code.class_code_chain = class_code_chain;
|
|
|
|
|
})(code = lib_plankton.code || (lib_plankton.code = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:code«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var code;
|
|
|
|
|
(function (code) {
|
|
|
|
|
/**
|
|
|
|
|
* @author Christian Fraß <frass@greenscale.de>
|
|
|
|
|
*/
|
|
|
|
|
function flatten_encode(from, keys) {
|
|
|
|
|
if (keys === void 0) { keys = null; }
|
|
|
|
|
if (keys === null) {
|
|
|
|
|
if (from.length > 0) {
|
|
|
|
|
keys = Object.keys(from[0]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw (new Error("encoding impossible"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
"keys": keys,
|
|
|
|
|
"data": from.map(function (line) { return keys.map(function (name) { return line[name]; }); })
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
code.flatten_encode = flatten_encode;
|
|
|
|
|
/**
|
|
|
|
|
* @author Christian Fraß <frass@greenscale.de>
|
|
|
|
|
*/
|
|
|
|
|
function flatten_decode(to) {
|
|
|
|
|
return (to.data
|
|
|
|
|
.map(function (dataset) {
|
|
|
|
|
var dataset_ = {};
|
|
|
|
|
dataset
|
|
|
|
|
.forEach(function (value, index) {
|
|
|
|
|
var name = to.keys[index];
|
|
|
|
|
dataset_[name] = value;
|
|
|
|
|
});
|
|
|
|
|
return dataset_;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
code.flatten_decode = flatten_decode;
|
|
|
|
|
})(code = lib_plankton.code || (lib_plankton.code = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:code«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:code« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var code;
|
|
|
|
|
(function (code) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var class_code_flatten = /** @class */ (function () {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function class_code_flatten() {
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_code_flatten.prototype.encode = function (x) {
|
|
|
|
|
return code.flatten_encode(x);
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_code_flatten.prototype.decode = function (x) {
|
|
|
|
|
return code.flatten_decode(x);
|
|
|
|
|
};
|
|
|
|
|
return class_code_flatten;
|
|
|
|
|
}());
|
|
|
|
|
code.class_code_flatten = class_code_flatten;
|
|
|
|
|
})(code = lib_plankton.code || (lib_plankton.code = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:json«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:json« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:json« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:json«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var json;
|
|
|
|
|
(function (json) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function encode(source, options = {}) {
|
|
|
|
|
options = Object.assign({
|
|
|
|
|
"formatted": false,
|
|
|
|
|
}, options);
|
|
|
|
|
return JSON.stringify(source, undefined, (options.formatted ? "\t" : undefined));
|
2024-09-09 12:13:10 +02:00
|
|
|
|
}
|
|
|
|
|
json.encode = encode;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function decode(target) {
|
|
|
|
|
return JSON.parse(target);
|
2024-09-09 12:13:10 +02:00
|
|
|
|
}
|
|
|
|
|
json.decode = decode;
|
2024-09-11 17:24:20 +02:00
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function implementation_code() {
|
|
|
|
|
return {
|
|
|
|
|
"encode": x => encode(x),
|
|
|
|
|
"decode": decode,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
json.implementation_code = implementation_code;
|
2024-09-09 12:13:10 +02:00
|
|
|
|
})(json = lib_plankton.json || (lib_plankton.json = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:json«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:json« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:json« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:json«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var json;
|
|
|
|
|
(function (json) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_json {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor() {
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
encode(x) {
|
|
|
|
|
return json.encode(x);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
decode(x) {
|
|
|
|
|
return json.decode(x);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
json.class_json = class_json;
|
|
|
|
|
})(json = lib_plankton.json || (lib_plankton.json = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
|
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
|
|
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
|
|
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
|
|
|
function step(op) {
|
|
|
|
|
if (f) throw new TypeError("Generator is already executing.");
|
|
|
|
|
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
|
|
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
|
|
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
|
|
|
switch (op[0]) {
|
|
|
|
|
case 0: case 1: t = op; break;
|
|
|
|
|
case 4: _.label++; return { value: op[1], done: false };
|
|
|
|
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
|
|
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
|
|
|
default:
|
|
|
|
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
|
|
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
|
|
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
|
|
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
|
|
|
if (t[2]) _.ops.pop();
|
|
|
|
|
_.trys.pop(); continue;
|
|
|
|
|
}
|
|
|
|
|
op = body.call(thisArg, _);
|
|
|
|
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
|
|
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:email«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:email« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:lang« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:email«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var email;
|
|
|
|
|
(function (email) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function send(smtp_credentials, sender, receivers, subject, content) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
|
|
|
return __generator(this, function (_a) {
|
2024-09-11 17:24:20 +02:00
|
|
|
|
return [2 /*return*/, Promise.reject(new Error("not implemented"))];
|
2024-09-09 12:13:10 +02:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
email.send = send;
|
|
|
|
|
})(email = lib_plankton.email || (lib_plankton.email = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
var __extends = (this && this.__extends) || (function () {
|
|
|
|
|
var extendStatics = function (d, b) {
|
|
|
|
|
extendStatics = Object.setPrototypeOf ||
|
|
|
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
|
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
|
|
|
return extendStatics(d, b);
|
|
|
|
|
};
|
|
|
|
|
return function (d, b) {
|
|
|
|
|
if (typeof b !== "function" && b !== null)
|
|
|
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
|
|
|
extendStatics(d, b);
|
|
|
|
|
function __() { this.constructor = d; }
|
|
|
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
|
|
|
};
|
|
|
|
|
})();
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:log«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:log« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:lang« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:log«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var log;
|
|
|
|
|
(function (log) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
var enum_level;
|
|
|
|
|
(function (enum_level) {
|
|
|
|
|
enum_level[enum_level["debug"] = 0] = "debug";
|
|
|
|
|
enum_level[enum_level["info"] = 1] = "info";
|
|
|
|
|
enum_level[enum_level["notice"] = 2] = "notice";
|
|
|
|
|
enum_level[enum_level["warning"] = 3] = "warning";
|
|
|
|
|
enum_level[enum_level["error"] = 4] = "error";
|
|
|
|
|
})(enum_level = log.enum_level || (log.enum_level = {}));
|
|
|
|
|
;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function level_order(level1, level2) {
|
|
|
|
|
return (level1 <= level2);
|
|
|
|
|
}
|
|
|
|
|
log.level_order = level_order;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function level_show(level) {
|
|
|
|
|
switch (level) {
|
|
|
|
|
case enum_level.debug: return "debug";
|
|
|
|
|
case enum_level.info: return "info";
|
|
|
|
|
case enum_level.notice: return "notice";
|
|
|
|
|
case enum_level.warning: return "warning";
|
|
|
|
|
case enum_level.error: return "error";
|
|
|
|
|
default: return "(unknown)";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.level_show = level_show;
|
|
|
|
|
})(log = lib_plankton.log || (lib_plankton.log = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:log«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:log« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:lang« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:lang«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
* @todo remove
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var log;
|
|
|
|
|
(function (log) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
/*export*/ var level_stack = [0];
|
|
|
|
|
function level_push(level) { level_stack.push(level); }
|
|
|
|
|
log.level_push = level_push;
|
|
|
|
|
function level_pop() { if (level_stack.length > 1) {
|
|
|
|
|
level_stack.pop();
|
|
|
|
|
} }
|
|
|
|
|
log.level_pop = level_pop;
|
|
|
|
|
function level_get() { return level_stack.slice(-1)[0]; }
|
|
|
|
|
/*
|
|
|
|
|
export function level_inc() : void {level_push(level_get()+1);}
|
|
|
|
|
export function level_dec() : void {level_push(level_get()-1);}
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var indent_stack = [0];
|
|
|
|
|
function indent_push(indent) { indent_stack.push(indent); }
|
|
|
|
|
log.indent_push = indent_push;
|
|
|
|
|
function indent_pop() { if (indent_stack.length > 1) {
|
|
|
|
|
indent_stack.pop();
|
|
|
|
|
} }
|
|
|
|
|
log.indent_pop = indent_pop;
|
|
|
|
|
function indent_get() { return level_stack.slice(-1)[0]; }
|
|
|
|
|
function indent_inc() { level_push(level_get() + 1); }
|
|
|
|
|
log.indent_inc = indent_inc;
|
|
|
|
|
function indent_dec() { level_push(level_get() - 1); }
|
|
|
|
|
log.indent_dec = indent_dec;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function write(_a) {
|
|
|
|
|
var message = _a["message"], _b = _a["type"], type = _b === void 0 ? null : _b, _c = _a["prefix"], prefix = _c === void 0 ? null : _c, _d = _a["level"], level = _d === void 0 ? 0 : _d, _e = _a["indent"], indent = _e === void 0 ? 0 : _e;
|
|
|
|
|
var entry = {
|
|
|
|
|
"level": ((type === null)
|
|
|
|
|
? lib_plankton.log.enum_level.info
|
|
|
|
|
: {
|
|
|
|
|
"debug": lib_plankton.log.enum_level.debug,
|
|
|
|
|
"info": lib_plankton.log.enum_level.info,
|
|
|
|
|
"notice": lib_plankton.log.enum_level.notice,
|
|
|
|
|
"warning": lib_plankton.log.enum_level.warning,
|
|
|
|
|
"error": lib_plankton.log.enum_level.error
|
|
|
|
|
}[type]),
|
|
|
|
|
"incident": message,
|
|
|
|
|
"details": {
|
|
|
|
|
"prefix": prefix,
|
|
|
|
|
"level": level,
|
|
|
|
|
"indent": indent
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
lib_plankton.log.add(entry);
|
|
|
|
|
}
|
|
|
|
|
log.write = write;
|
|
|
|
|
})(log = lib_plankton.log || (lib_plankton.log = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:log«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:log« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:lang« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:log«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var log;
|
|
|
|
|
(function (log) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
var class_channel = /** @class */ (function () {
|
|
|
|
|
function class_channel() {
|
|
|
|
|
}
|
|
|
|
|
return class_channel;
|
|
|
|
|
}());
|
|
|
|
|
log.class_channel = class_channel;
|
|
|
|
|
})(log = lib_plankton.log || (lib_plankton.log = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:log«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:log« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:lang« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:log«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var log;
|
|
|
|
|
(function (log) {
|
|
|
|
|
/**
|
2024-09-11 17:24:20 +02:00
|
|
|
|
* output for writing log entries to web console
|
2024-09-09 12:13:10 +02:00
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
var class_channel_console = /** @class */ (function (_super) {
|
|
|
|
|
__extends(class_channel_console, _super);
|
|
|
|
|
function class_channel_console() {
|
2024-09-09 12:13:10 +02:00
|
|
|
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
class_channel_console.prototype.add = function (entry) {
|
|
|
|
|
var _a;
|
|
|
|
|
var renderers = (_a = {},
|
|
|
|
|
_a[log.enum_level.debug] = {
|
|
|
|
|
"renderer": function (i, d) { return console.log(i, d); },
|
|
|
|
|
"show_level": true
|
|
|
|
|
},
|
|
|
|
|
_a[log.enum_level.info] = {
|
|
|
|
|
"renderer": function (i, d) { return console.info(i, d); },
|
|
|
|
|
"show_level": false
|
|
|
|
|
},
|
|
|
|
|
_a[log.enum_level.notice] = {
|
|
|
|
|
"renderer": function (i, d) { return console.log(i, d); },
|
|
|
|
|
"show_level": true
|
|
|
|
|
},
|
|
|
|
|
_a[log.enum_level.warning] = {
|
|
|
|
|
"renderer": function (i, d) { return console.warn(i, d); },
|
|
|
|
|
"show_level": false
|
|
|
|
|
},
|
|
|
|
|
_a[log.enum_level.error] = {
|
|
|
|
|
"renderer": function (i, d) { return console.error(i, d); },
|
|
|
|
|
"show_level": false
|
|
|
|
|
},
|
|
|
|
|
_a);
|
|
|
|
|
var setting = renderers[entry.level];
|
|
|
|
|
setting.renderer(((setting.show_level
|
|
|
|
|
? ("[" + log.level_show(entry.level) + "]" + " ")
|
|
|
|
|
: "")
|
2024-09-09 12:13:10 +02:00
|
|
|
|
+
|
2024-09-11 17:24:20 +02:00
|
|
|
|
("" + entry.incident + "")), entry.details);
|
2024-09-09 12:13:10 +02:00
|
|
|
|
};
|
2024-09-11 17:24:20 +02:00
|
|
|
|
return class_channel_console;
|
2024-09-09 12:13:10 +02:00
|
|
|
|
}(log.class_channel));
|
2024-09-11 17:24:20 +02:00
|
|
|
|
log.class_channel_console = class_channel_console;
|
2024-09-09 12:13:10 +02:00
|
|
|
|
})(log = lib_plankton.log || (lib_plankton.log = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:log«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:log« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:lang« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:log«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var log;
|
|
|
|
|
(function (log) {
|
|
|
|
|
/**
|
|
|
|
|
* decorator for filtering out log entries below a certain level threshold
|
|
|
|
|
*/
|
|
|
|
|
var class_channel_minlevel = /** @class */ (function (_super) {
|
|
|
|
|
__extends(class_channel_minlevel, _super);
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function class_channel_minlevel(core, threshold) {
|
|
|
|
|
var _this = _super.call(this) || this;
|
|
|
|
|
_this.core = core;
|
|
|
|
|
_this.threshold = threshold;
|
|
|
|
|
return _this;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
class_channel_minlevel.prototype.add = function (entry) {
|
|
|
|
|
if (!log.level_order(this.threshold, entry.level)) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.core.add(entry);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return class_channel_minlevel;
|
|
|
|
|
}(log.class_channel));
|
|
|
|
|
log.class_channel_minlevel = class_channel_minlevel;
|
|
|
|
|
})(log = lib_plankton.log || (lib_plankton.log = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:log«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:log« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:lang« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:log«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var log;
|
|
|
|
|
(function (log) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function translate_level(level_string) {
|
|
|
|
|
return {
|
|
|
|
|
"debug": log.enum_level.debug,
|
|
|
|
|
"info": log.enum_level.info,
|
|
|
|
|
"notice": log.enum_level.notice,
|
|
|
|
|
"warning": log.enum_level.warning,
|
|
|
|
|
"error": log.enum_level.error
|
|
|
|
|
}[level_string];
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function channel_make(description) {
|
2024-09-11 17:24:20 +02:00
|
|
|
|
var _a;
|
2024-09-09 12:13:10 +02:00
|
|
|
|
switch (description.kind) {
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unhandled log channel kind: " + description.kind));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-09-11 17:24:20 +02:00
|
|
|
|
case "console": {
|
|
|
|
|
return (new log.class_channel_minlevel(new log.class_channel_console(), translate_level((_a = description.data["threshold"]) !== null && _a !== void 0 ? _a : "debug")));
|
2024-09-09 12:13:10 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.channel_make = channel_make;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function conf_default() {
|
|
|
|
|
return [
|
2024-09-11 17:24:20 +02:00
|
|
|
|
new log.class_channel_minlevel(new log.class_channel_console(), log.enum_level.notice),
|
2024-09-09 12:13:10 +02:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
log.conf_default = conf_default;
|
|
|
|
|
})(log = lib_plankton.log || (lib_plankton.log = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:log«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:log« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:lang« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:log«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var log;
|
|
|
|
|
(function (log) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
var _channel_stack = null;
|
|
|
|
|
/**
|
|
|
|
|
* pushes a new configuration on the stack and activates it
|
|
|
|
|
*/
|
|
|
|
|
function conf_push(channels) {
|
|
|
|
|
if (_channel_stack === null) {
|
|
|
|
|
_channel_stack = [];
|
|
|
|
|
}
|
|
|
|
|
_channel_stack.push(channels);
|
|
|
|
|
}
|
|
|
|
|
log.conf_push = conf_push;
|
|
|
|
|
/**
|
|
|
|
|
* pops the current active configuration from the stack
|
|
|
|
|
*/
|
|
|
|
|
function conf_pop() {
|
|
|
|
|
if (_channel_stack.length > 0) {
|
|
|
|
|
_channel_stack.pop();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.conf_pop = conf_pop;
|
|
|
|
|
/**
|
|
|
|
|
* makes the logging system ready
|
|
|
|
|
*/
|
|
|
|
|
function setup() {
|
|
|
|
|
if (_channel_stack === null) {
|
|
|
|
|
_channel_stack = [];
|
|
|
|
|
conf_push(log.conf_default());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* consumes a log entry, i.e. sends it to the currently active outputs
|
|
|
|
|
*/
|
|
|
|
|
function add(entry) {
|
|
|
|
|
setup();
|
|
|
|
|
_channel_stack.slice(-1)[0].forEach(function (channel) { return channel.add(entry); });
|
|
|
|
|
}
|
|
|
|
|
log.add = add;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function debug(incident, details) {
|
|
|
|
|
if (details === void 0) { details = {}; }
|
|
|
|
|
add({ "level": log.enum_level.debug, "incident": incident, "details": details });
|
|
|
|
|
}
|
|
|
|
|
log.debug = debug;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function info(incident, details) {
|
|
|
|
|
if (details === void 0) { details = {}; }
|
|
|
|
|
add({ "level": log.enum_level.info, "incident": incident, "details": details });
|
|
|
|
|
}
|
|
|
|
|
log.info = info;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function notice(incident, details) {
|
|
|
|
|
if (details === void 0) { details = {}; }
|
|
|
|
|
add({ "level": log.enum_level.notice, "incident": incident, "details": details });
|
|
|
|
|
}
|
|
|
|
|
log.notice = notice;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function warning(incident, details) {
|
|
|
|
|
if (details === void 0) { details = {}; }
|
|
|
|
|
add({ "level": log.enum_level.warning, "incident": incident, "details": details });
|
|
|
|
|
}
|
|
|
|
|
log.warning = warning;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function error(incident, details) {
|
|
|
|
|
if (details === void 0) { details = {}; }
|
|
|
|
|
add({ "level": log.enum_level.error, "incident": incident, "details": details });
|
|
|
|
|
}
|
|
|
|
|
log.error = error;
|
|
|
|
|
})(log = lib_plankton.log || (lib_plankton.log = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:log«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:log« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:lang« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:log«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var log;
|
|
|
|
|
(function (log) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
log.conf_push([
|
|
|
|
|
log.channel_make({
|
2024-09-11 17:24:20 +02:00
|
|
|
|
"kind": "console",
|
2024-09-09 12:13:10 +02:00
|
|
|
|
"data": {
|
|
|
|
|
"threshold": "info"
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
})(log = lib_plankton.log || (lib_plankton.log = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:args«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:args« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:args« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:args«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var args;
|
|
|
|
|
(function (args) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
var enum_environment;
|
|
|
|
|
(function (enum_environment) {
|
|
|
|
|
enum_environment["cli"] = "cli";
|
|
|
|
|
enum_environment["url"] = "url";
|
|
|
|
|
})(enum_environment = args.enum_environment || (args.enum_environment = {}));
|
|
|
|
|
;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
var enum_kind;
|
|
|
|
|
(function (enum_kind) {
|
|
|
|
|
enum_kind["positional"] = "positional";
|
|
|
|
|
enum_kind["volatile"] = "volatile";
|
|
|
|
|
})(enum_kind = args.enum_kind || (args.enum_kind = {}));
|
|
|
|
|
;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
var enum_type;
|
|
|
|
|
(function (enum_type) {
|
|
|
|
|
enum_type["boolean"] = "boolean";
|
|
|
|
|
enum_type["integer"] = "int";
|
|
|
|
|
enum_type["float"] = "float";
|
|
|
|
|
enum_type["string"] = "string";
|
|
|
|
|
})(enum_type = args.enum_type || (args.enum_type = {}));
|
|
|
|
|
;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
var enum_mode;
|
|
|
|
|
(function (enum_mode) {
|
|
|
|
|
enum_mode["replace"] = "replace";
|
|
|
|
|
enum_mode["accumulate"] = "accumulate";
|
|
|
|
|
})(enum_mode = args.enum_mode || (args.enum_mode = {}));
|
|
|
|
|
;
|
|
|
|
|
})(args = lib_plankton.args || (lib_plankton.args = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:args«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:args« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:args« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:args«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var args;
|
|
|
|
|
(function (args) {
|
|
|
|
|
/*
|
|
|
|
|
export enum_mode {
|
|
|
|
|
replace = "replace",
|
|
|
|
|
accumulate = "accumulate",
|
|
|
|
|
};
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var class_argument = /** @class */ (function () {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function class_argument(_a) {
|
|
|
|
|
var name = _a["name"], _b = _a["type"], type = _b === void 0 ? args.enum_type.string : _b, _c = _a["kind"], kind = _c === void 0 ? args.enum_kind.positional : _c, _d = _a["mode"], mode = _d === void 0 ? args.enum_mode.replace : _d, _e = _a["default"], default_ = _e === void 0 ? null : _e, _f = _a["info"], info = _f === void 0 ? null : _f, _g = _a["parameters"], parameters = _g === void 0 ? {} : _g, _h = _a["hidden"], hidden = _h === void 0 ? false : _h;
|
|
|
|
|
this.name = name;
|
|
|
|
|
this.type = type;
|
|
|
|
|
this.kind = kind;
|
|
|
|
|
this.mode = mode;
|
|
|
|
|
this.default_ = default_;
|
|
|
|
|
this.info = info;
|
|
|
|
|
this.parameters = parameters;
|
|
|
|
|
this.hidden = hidden;
|
|
|
|
|
if (!this.check()) {
|
|
|
|
|
throw (new Error("invalid argument-setup"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.positional = function (_a) {
|
|
|
|
|
var name = _a["name"], _b = _a["type"], type = _b === void 0 ? args.enum_type.string : _b, _c = _a["mode"], mode = _c === void 0 ? args.enum_mode.replace : _c, _d = _a["default"], default_ = _d === void 0 ? null : _d, _e = _a["info"], info = _e === void 0 ? null : _e, _f = _a["hidden"], hidden = _f === void 0 ? false : _f, index = _a["index"];
|
|
|
|
|
return (new class_argument({
|
|
|
|
|
"name": name,
|
|
|
|
|
"kind": args.enum_kind.positional,
|
|
|
|
|
"type": type,
|
|
|
|
|
"mode": mode,
|
|
|
|
|
"default": default_,
|
|
|
|
|
"info": info,
|
|
|
|
|
"hidden": hidden,
|
|
|
|
|
"parameters": {
|
|
|
|
|
"index": index
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.volatile = function (_a) {
|
|
|
|
|
var name = _a["name"], _b = _a["type"], type = _b === void 0 ? args.enum_type.string : _b, _c = _a["mode"], mode = _c === void 0 ? args.enum_mode.replace : _c, _d = _a["default"], default_ = _d === void 0 ? null : _d, _e = _a["info"], info = _e === void 0 ? null : _e, _f = _a["hidden"], hidden = _f === void 0 ? false : _f, indicators_short = _a["indicators_short"], indicators_long = _a["indicators_long"];
|
|
|
|
|
return (new class_argument({
|
|
|
|
|
"name": name,
|
|
|
|
|
"kind": args.enum_kind.volatile,
|
|
|
|
|
"type": type,
|
|
|
|
|
"mode": mode,
|
|
|
|
|
"default": default_,
|
|
|
|
|
"info": info,
|
|
|
|
|
"hidden": hidden,
|
|
|
|
|
"parameters": {
|
|
|
|
|
"indicators_short": indicators_short,
|
|
|
|
|
"indicators_long": indicators_long
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.check = function () {
|
|
|
|
|
var _this = this;
|
|
|
|
|
return [
|
|
|
|
|
function () { return ((!(_this.kind == args.enum_kind.volatile))
|
|
|
|
|
||
|
|
|
|
|
(("indicators_long" in _this.parameters)
|
|
|
|
|
&&
|
|
|
|
|
(_this.parameters["indicators_long"]["length"] >= 0))); },
|
|
|
|
|
].every(function (condition) { return condition(); });
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.name_get = function () {
|
|
|
|
|
return this.name;
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.kind_get = function () {
|
|
|
|
|
return this.kind;
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.type_get = function () {
|
|
|
|
|
return this.type;
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.mode_get = function () {
|
|
|
|
|
return this.mode;
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.default_get = function () {
|
|
|
|
|
return this.default_;
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.parameters_get = function () {
|
|
|
|
|
return this.parameters;
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.hidden_get = function () {
|
|
|
|
|
return this.hidden;
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.toString = function () {
|
|
|
|
|
return "<".concat(this.name, ">");
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.indicator_main = function () {
|
|
|
|
|
if (this.kind === args.enum_kind.volatile) {
|
|
|
|
|
return this.parameters["indicators_long"][0];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.pattern_value = function () {
|
|
|
|
|
switch (this.type) {
|
|
|
|
|
case args.enum_type.boolean: {
|
|
|
|
|
return "false|true";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case args.enum_type.integer: {
|
|
|
|
|
return "[0-9]+";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case args.enum_type.float: {
|
|
|
|
|
return "\\d*(?:\\.\\d+)?";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case args.enum_type.string: {
|
|
|
|
|
return "\\S+";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unhandled type ".concat(this.type)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.extract = function (raw) {
|
|
|
|
|
switch (this.type) {
|
|
|
|
|
case args.enum_type.boolean: {
|
|
|
|
|
return (raw != "false");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case args.enum_type.integer: {
|
|
|
|
|
return parseInt(raw);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case args.enum_type.float: {
|
|
|
|
|
return parseFloat(raw);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case args.enum_type.string: {
|
|
|
|
|
return raw;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unhandled type ".concat(this.type)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.assign = function (data, target, raw) {
|
|
|
|
|
var value = this.extract(raw);
|
|
|
|
|
switch (this.mode) {
|
|
|
|
|
case args.enum_mode.replace: {
|
|
|
|
|
data[target] = value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case args.enum_mode.accumulate: {
|
|
|
|
|
/*
|
|
|
|
|
if (! (this.name in data)) {
|
|
|
|
|
data[this.name] = [];
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
data[target].push(value);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unhandled mode ".concat(this.mode)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.make = function (data, target) {
|
|
|
|
|
var value = data[target];
|
|
|
|
|
return value.toString();
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_argument.prototype.generate_help = function () {
|
|
|
|
|
var _this = this;
|
|
|
|
|
var _a, _b, _c, _d;
|
|
|
|
|
var output = "";
|
|
|
|
|
{
|
|
|
|
|
switch (this.kind) {
|
|
|
|
|
case args.enum_kind.positional: {
|
|
|
|
|
var line = "";
|
|
|
|
|
line += "\t";
|
|
|
|
|
line += "<".concat(this.name, ">");
|
|
|
|
|
line += "\n";
|
|
|
|
|
output += line;
|
|
|
|
|
}
|
|
|
|
|
case args.enum_kind.volatile: {
|
|
|
|
|
var line = "";
|
|
|
|
|
line += "\t";
|
|
|
|
|
if (this.type === args.enum_type.boolean) {
|
|
|
|
|
line += ([]
|
|
|
|
|
.concat(((_a = this.parameters["indicators_short"]) !== null && _a !== void 0 ? _a : []).map(function (indicator) { return ("-" + indicator); }))
|
|
|
|
|
.concat(((_b = this.parameters["indicators_long"]) !== null && _b !== void 0 ? _b : []).map(function (indicator) { return ("--" + indicator); }))
|
|
|
|
|
.join(" | "));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
line += ([]
|
|
|
|
|
.concat(((_c = this.parameters["indicators_short"]) !== null && _c !== void 0 ? _c : []).map(function (indicator) { return ("-" + indicator + " " + ("<" + _this.name + ">")); }))
|
|
|
|
|
.concat(((_d = this.parameters["indicators_long"]) !== null && _d !== void 0 ? _d : []).map(function (indicator) { return ("--" + indicator + "=" + ("<" + _this.name + ">")); }))
|
|
|
|
|
.join(" | "));
|
|
|
|
|
}
|
|
|
|
|
line += "\n";
|
|
|
|
|
output += line;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var line = "";
|
|
|
|
|
line += "\t\t";
|
|
|
|
|
var infotext = ((this.info == null) ? "(no info available)" : this.info);
|
|
|
|
|
line += infotext;
|
|
|
|
|
if ((this.type != "boolean") && (this.default_ != null)) {
|
|
|
|
|
line += "; default: ".concat(this.default_.toString());
|
|
|
|
|
}
|
|
|
|
|
line += "\n";
|
|
|
|
|
output += line;
|
|
|
|
|
}
|
|
|
|
|
return output;
|
|
|
|
|
};
|
|
|
|
|
return class_argument;
|
|
|
|
|
}());
|
|
|
|
|
args.class_argument = class_argument;
|
|
|
|
|
})(args = lib_plankton.args || (lib_plankton.args = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:args«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:args« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:args« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:args«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var args;
|
|
|
|
|
(function (args) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var settings = {
|
|
|
|
|
"environment": {
|
|
|
|
|
"cli": {
|
|
|
|
|
"symbols": {
|
|
|
|
|
"delimiter": " ",
|
|
|
|
|
"prefix": "--",
|
|
|
|
|
"assignment": "="
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"url": {
|
|
|
|
|
"symbols": {
|
|
|
|
|
"delimiter": "&",
|
|
|
|
|
"prefix": "",
|
|
|
|
|
"assignment": "="
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
args.verbosity = 0;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo check validity
|
|
|
|
|
*/
|
|
|
|
|
var class_handler = /** @class */ (function () {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function class_handler(arguments_) {
|
|
|
|
|
this.arguments_ = arguments_;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_handler.prototype.filter = function (kind) {
|
|
|
|
|
var arguments_ = {};
|
|
|
|
|
for (var _i = 0, _a = Object.entries(this.arguments_); _i < _a.length; _i++) {
|
|
|
|
|
var _b = _a[_i], name = _b[0], argument = _b[1];
|
|
|
|
|
if (argument.kind_get() == kind) {
|
|
|
|
|
arguments_[name] = argument;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return arguments_;
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_handler.prototype.read = function (environment, input, data) {
|
|
|
|
|
var _this = this;
|
|
|
|
|
if (data === void 0) { data = {}; }
|
|
|
|
|
switch (environment) {
|
|
|
|
|
case args.enum_environment.cli:
|
|
|
|
|
case args.enum_environment.url: {
|
|
|
|
|
// default values
|
|
|
|
|
{
|
|
|
|
|
for (var _i = 0, _a = Object.entries(this.arguments_); _i < _a.length; _i++) {
|
|
|
|
|
var _b = _a[_i], name = _b[0], argument = _b[1];
|
|
|
|
|
data[name] = argument.default_get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// preprocessing
|
|
|
|
|
{
|
|
|
|
|
// short indicators (lil hacky ...)
|
|
|
|
|
{
|
|
|
|
|
if (environment == args.enum_environment.cli) {
|
|
|
|
|
for (var _c = 0, _d = Object.entries(this.filter(args.enum_kind.volatile)); _c < _d.length; _c++) {
|
|
|
|
|
var _e = _d[_c], name = _e[0], argument = _e[1];
|
|
|
|
|
// console.info(argument.parameters_get()["indicators_short"].join("|"));
|
|
|
|
|
var pattern_from = "";
|
|
|
|
|
{
|
|
|
|
|
pattern_from += "(?:^|".concat(settings["environment"][environment]["symbols"]["delimiter"], ")");
|
|
|
|
|
pattern_from += "-".concat(argument.parameters_get()["indicators_short"].join("|"));
|
|
|
|
|
pattern_from += "(?:$|".concat(settings["environment"][environment]["symbols"]["delimiter"], ")");
|
|
|
|
|
}
|
|
|
|
|
var pattern_to = "";
|
|
|
|
|
{
|
|
|
|
|
pattern_to += settings["environment"][environment]["symbols"]["delimiter"];
|
|
|
|
|
pattern_to += settings["environment"][environment]["symbols"]["prefix"];
|
|
|
|
|
pattern_to += argument.indicator_main();
|
|
|
|
|
if (argument.type_get() == args.enum_type.boolean) {
|
|
|
|
|
pattern_to += settings["environment"][environment]["symbols"]["delimiter"];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
pattern_to += settings["environment"][environment]["symbols"]["assignment"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var result = input.replace(new RegExp(pattern_from, "g"), pattern_to);
|
|
|
|
|
lib_plankton.log.debug("lib_args:read:replacing", {
|
|
|
|
|
"pattern_from": pattern_from,
|
|
|
|
|
"pattern_to": pattern_to,
|
|
|
|
|
"input": input,
|
|
|
|
|
"result": result
|
|
|
|
|
});
|
|
|
|
|
input = result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lib_plankton.log.debug("lib_args:read:current_input", {
|
|
|
|
|
"input": input
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// parsing
|
|
|
|
|
{
|
|
|
|
|
var parts = input
|
|
|
|
|
.split(settings["environment"][environment]["symbols"]["delimiter"])
|
|
|
|
|
.filter(function (x) { return (x != ""); });
|
|
|
|
|
var index_expected_1 = 0;
|
|
|
|
|
parts.forEach(function (part) {
|
|
|
|
|
lib_plankton.log.debug("lib_args:read:analyzing", {
|
|
|
|
|
"part": part
|
|
|
|
|
});
|
|
|
|
|
var found = [
|
|
|
|
|
function () {
|
|
|
|
|
lib_plankton.log.debug("lib_args:read:probing_as_volatile", {
|
|
|
|
|
"part": part
|
|
|
|
|
});
|
|
|
|
|
for (var _i = 0, _a = Object.entries(_this.filter(args.enum_kind.volatile)); _i < _a.length; _i++) {
|
|
|
|
|
var _b = _a[_i], name = _b[0], argument = _b[1];
|
|
|
|
|
lib_plankton.log.debug("lib_args:read:probing_as_volatile:trying", {
|
|
|
|
|
"part": part,
|
|
|
|
|
"argument": argument.toString()
|
|
|
|
|
});
|
|
|
|
|
var pattern = "";
|
|
|
|
|
{
|
|
|
|
|
var pattern_front = "";
|
|
|
|
|
pattern_front += "".concat(settings["environment"][environment]["symbols"]["prefix"]);
|
|
|
|
|
pattern_front += "(?:".concat(argument.parameters_get()["indicators_long"].join("|"), ")");
|
|
|
|
|
pattern += pattern_front;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var pattern_back = "";
|
|
|
|
|
pattern_back += "".concat(settings["environment"][environment]["symbols"]["assignment"]);
|
|
|
|
|
pattern_back += "(".concat(argument.pattern_value(), ")");
|
|
|
|
|
if (argument.type_get() == args.enum_type.boolean) {
|
|
|
|
|
pattern_back = "(?:".concat(pattern_back, ")?");
|
|
|
|
|
}
|
|
|
|
|
pattern += pattern_back;
|
|
|
|
|
}
|
|
|
|
|
lib_plankton.log.debug("lib_args:read:probing_as_volatile:pattern", {
|
|
|
|
|
"pattern": pattern
|
|
|
|
|
});
|
|
|
|
|
var regexp = new RegExp(pattern);
|
|
|
|
|
var matching = regexp.exec(part);
|
|
|
|
|
lib_plankton.log.debug("lib_args:read:probing_as_volatile:matching", {
|
|
|
|
|
"matching": matching
|
|
|
|
|
});
|
|
|
|
|
if (matching == null) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
argument.assign(data, name, matching[1]);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
function () {
|
|
|
|
|
lib_plankton.log.debug("lib_args:read:probing_as_positional", {
|
|
|
|
|
"part": part
|
|
|
|
|
});
|
|
|
|
|
var positional = _this.filter(args.enum_kind.positional);
|
|
|
|
|
for (var _i = 0, _a = Object.entries(positional); _i < _a.length; _i++) {
|
|
|
|
|
var _b = _a[_i], name = _b[0], argument = _b[1];
|
|
|
|
|
if (argument.parameters_get()['index'] !== index_expected_1) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
lib_plankton.log.debug("lib_args:read:probing_as_positional:trying", {
|
|
|
|
|
"part": part,
|
|
|
|
|
"argument": argument.toString()
|
|
|
|
|
});
|
|
|
|
|
var pattern = "";
|
|
|
|
|
{
|
|
|
|
|
var pattern_back = "";
|
|
|
|
|
pattern_back += "(".concat(argument.pattern_value(), ")");
|
|
|
|
|
pattern += pattern_back;
|
|
|
|
|
}
|
|
|
|
|
lib_plankton.log.debug("lib_args:read:probing_as_positional:pattern", {
|
|
|
|
|
"pattern": pattern
|
|
|
|
|
});
|
|
|
|
|
var regexp = new RegExp(pattern);
|
|
|
|
|
var matching = regexp.exec(part);
|
|
|
|
|
lib_plankton.log.debug("lib_args:read:probing_as_positional:matching", {
|
|
|
|
|
"matching": matching
|
|
|
|
|
});
|
|
|
|
|
if (matching == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
argument.assign(data, name, matching[1]);
|
|
|
|
|
index_expected_1 += 1;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
].some(function (x) { return x(); });
|
|
|
|
|
if (!found) {
|
|
|
|
|
lib_plankton.log.warning("lib_args:read:could_not_parse", {
|
|
|
|
|
"part": part
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unhandled environment ".concat(environment)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo handle if the data object doesn't have the required field or the type is wrong or sth.
|
|
|
|
|
*/
|
|
|
|
|
class_handler.prototype.write = function (environment, data) {
|
|
|
|
|
switch (environment) {
|
|
|
|
|
case args.enum_environment.cli: {
|
|
|
|
|
return (([]
|
|
|
|
|
.concat(Object.entries(this.filter(args.enum_kind.volatile)).map(function (_a) {
|
|
|
|
|
var name = _a[0], argument = _a[1];
|
|
|
|
|
var values;
|
|
|
|
|
switch (argument.mode_get()) {
|
|
|
|
|
case args.enum_mode.replace: {
|
|
|
|
|
values = [data[argument.name_get()]];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case args.enum_mode.accumulate: {
|
|
|
|
|
values = data[argument.name_get()];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (values
|
|
|
|
|
.map(function (value) { return ((settings["environment"][environment]["symbols"]["prefix"]
|
|
|
|
|
+
|
|
|
|
|
argument.parameters_get()["indicators_long"][0])
|
|
|
|
|
+
|
|
|
|
|
(settings["environment"][environment]["symbols"]["assignment"]
|
|
|
|
|
+
|
|
|
|
|
value.toString())); })
|
|
|
|
|
.join(" "));
|
|
|
|
|
}))
|
|
|
|
|
.concat(Object.entries(this.filter(args.enum_kind.positional)).map(function (_a) {
|
|
|
|
|
var name = _a[0], argument = _a[1];
|
|
|
|
|
var raw = "";
|
|
|
|
|
{
|
|
|
|
|
var raw_back = "";
|
|
|
|
|
raw_back += argument.make(data, name);
|
|
|
|
|
raw += raw_back;
|
|
|
|
|
}
|
|
|
|
|
return raw;
|
|
|
|
|
})))
|
|
|
|
|
.join(settings["environment"][environment]["symbols"]["delimiter"]));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unhandled environment ".concat(environment)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @desc manpage-like info-sheet
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_handler.prototype.generate_help = function (_a) {
|
|
|
|
|
var _b = _a["programname"], programname = _b === void 0 ? null : _b, _c = _a["author"], author = _c === void 0 ? null : _c, _d = _a["description"], description = _d === void 0 ? null : _d, _e = _a["executable"], executable = _e === void 0 ? null : _e;
|
|
|
|
|
var environment = args.enum_environment.cli;
|
|
|
|
|
var output = "";
|
|
|
|
|
{
|
|
|
|
|
var section = "";
|
|
|
|
|
{
|
|
|
|
|
var line = "";
|
|
|
|
|
line += "";
|
|
|
|
|
line += "INFO";
|
|
|
|
|
line += "\n";
|
|
|
|
|
section += line;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var line = "";
|
|
|
|
|
line += "\t";
|
|
|
|
|
line += "".concat(programname, " -- ").concat(description);
|
|
|
|
|
line += "\n";
|
|
|
|
|
section += line;
|
|
|
|
|
}
|
|
|
|
|
section += "\n";
|
|
|
|
|
output += section;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
if (author != null) {
|
|
|
|
|
var section = "";
|
|
|
|
|
{
|
|
|
|
|
var line = "";
|
|
|
|
|
line += "";
|
|
|
|
|
line += "AUTHOR";
|
|
|
|
|
line += "\n";
|
|
|
|
|
section += line;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var line = "";
|
|
|
|
|
line += "\t";
|
|
|
|
|
line += "".concat(author);
|
|
|
|
|
line += "\n";
|
|
|
|
|
section += line;
|
|
|
|
|
}
|
|
|
|
|
section += "\n";
|
|
|
|
|
output += section;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var section = "";
|
|
|
|
|
{
|
|
|
|
|
var line = "";
|
|
|
|
|
line += "";
|
|
|
|
|
line += "SYNOPSIS";
|
|
|
|
|
line += "\n";
|
|
|
|
|
section += line;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var line = "";
|
|
|
|
|
line += "\t";
|
|
|
|
|
line += executable;
|
|
|
|
|
line += settings["environment"][environment]["symbols"]["delimiter"];
|
|
|
|
|
line += Object.entries(this.filter(args.enum_kind.positional))
|
|
|
|
|
.map(function (_a) {
|
|
|
|
|
var name = _a[0], argument = _a[1];
|
|
|
|
|
var part = "";
|
|
|
|
|
part += "<".concat(argument.name_get(), ">");
|
|
|
|
|
return part;
|
|
|
|
|
})
|
|
|
|
|
.join(settings["environment"][environment]["symbols"]["delimiter"]);
|
|
|
|
|
line += settings["environment"][environment]["symbols"]["delimiter"];
|
|
|
|
|
line += Object.entries(this.filter(args.enum_kind.volatile))
|
|
|
|
|
.filter(function (_a) {
|
|
|
|
|
var name = _a[0], argument = _a[1];
|
|
|
|
|
return (!argument.hidden_get());
|
|
|
|
|
})
|
|
|
|
|
.map(function (_a) {
|
|
|
|
|
var name = _a[0], argument = _a[1];
|
|
|
|
|
var part = "";
|
|
|
|
|
// part += settings["environment"][environment]["symbols"]["prefix"];
|
|
|
|
|
part += "-";
|
|
|
|
|
part += argument.parameters_get()["indicators_short"][0];
|
|
|
|
|
if (argument.type_get() != "boolean") {
|
|
|
|
|
/*
|
|
|
|
|
part += settings["environment"][environment]["symbols"]["assignment"];
|
|
|
|
|
part += `<${argument.name_get()}>`;
|
|
|
|
|
*/
|
|
|
|
|
part += " ";
|
|
|
|
|
part += "<".concat(argument.name_get(), ">");
|
|
|
|
|
}
|
|
|
|
|
part = "[".concat(part, "]");
|
|
|
|
|
return part;
|
|
|
|
|
})
|
|
|
|
|
.join(settings["environment"][environment]["symbols"]["delimiter"]);
|
|
|
|
|
line += "\n";
|
|
|
|
|
section += line;
|
|
|
|
|
}
|
|
|
|
|
section += "\n";
|
|
|
|
|
output += section;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var section = "";
|
|
|
|
|
{
|
|
|
|
|
var line = "";
|
|
|
|
|
line += "";
|
|
|
|
|
line += "OPTIONS";
|
|
|
|
|
line += "\n";
|
|
|
|
|
section += line;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
section += (Object.entries(this.arguments_)
|
|
|
|
|
.filter(function (_a) {
|
|
|
|
|
var name = _a[0], argument = _a[1];
|
|
|
|
|
return (!argument.hidden_get());
|
|
|
|
|
})
|
|
|
|
|
.map(function (_a) {
|
|
|
|
|
var name = _a[0], argument = _a[1];
|
|
|
|
|
return argument.generate_help();
|
|
|
|
|
})
|
|
|
|
|
.join("\n"));
|
|
|
|
|
}
|
|
|
|
|
section += "\n";
|
|
|
|
|
output += section;
|
|
|
|
|
}
|
|
|
|
|
return output;
|
|
|
|
|
};
|
|
|
|
|
return class_handler;
|
|
|
|
|
}());
|
|
|
|
|
args.class_handler = class_handler;
|
|
|
|
|
})(args = lib_plankton.args || (lib_plankton.args = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:string«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:string« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:string« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:string«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var plain_text_to_html = function (text) {
|
|
|
|
|
let ret = text;
|
|
|
|
|
ret = ret.replace(/ /g, " "); // convert multiple whitespace to forced ones
|
|
|
|
|
ret = ret.split("\n").join("<br/>");
|
|
|
|
|
return ret;
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @desc makes a valid
|
|
|
|
|
*/
|
|
|
|
|
var format_sentence = function (str, rtl = false, caseSense = true) {
|
|
|
|
|
if (str === "") {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let marks = {
|
|
|
|
|
".": true,
|
|
|
|
|
"?": true,
|
|
|
|
|
"!": true
|
|
|
|
|
};
|
|
|
|
|
let default_mark = ".";
|
|
|
|
|
let ret = str.split("");
|
|
|
|
|
if (!rtl) {
|
|
|
|
|
ret[0] = ret[0].toLocaleUpperCase();
|
|
|
|
|
if (!(ret[ret.length - 1] in marks)) {
|
|
|
|
|
ret.push(default_mark);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ret[ret.length - 1] = ret[ret.length - 1].toLocaleUpperCase();
|
|
|
|
|
if (!(ret[0] in marks)) {
|
|
|
|
|
ret.unshift(default_mark);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret.join("");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var fill_string_template = function (template_string, object, fabric = function (object, key) { return object[key]; }, delimiter = "%", default_string = null, sloppy) {
|
|
|
|
|
function get_tags(str) {
|
|
|
|
|
let r = new RegExp(delimiter + "[^\\s^" + delimiter + "]+" + delimiter, "gi");
|
|
|
|
|
return ((str.match(r) || []).map(function (e) {
|
|
|
|
|
return e.slice(delimiter.length, e.length - delimiter.length);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
function replace_tag(str, tag, value) {
|
|
|
|
|
let r = new RegExp(delimiter + tag + delimiter, "gi");
|
|
|
|
|
return str.replace(r, value);
|
|
|
|
|
}
|
|
|
|
|
function replace_tags(str, obj) {
|
|
|
|
|
return (get_tags(str).reduce(function (ret, key) {
|
|
|
|
|
let value = "";
|
|
|
|
|
try {
|
|
|
|
|
value = fabric(obj, key);
|
|
|
|
|
if ((!sloppy && (value === void 0)) || (sloppy && (value == void 0))) {
|
|
|
|
|
value = default_string;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
console.warn("invalid placeholder " + key);
|
|
|
|
|
value = default_string;
|
|
|
|
|
}
|
|
|
|
|
return replace_tag(ret, key, value);
|
|
|
|
|
}, str));
|
|
|
|
|
}
|
|
|
|
|
return replace_tags(template_string, object);
|
|
|
|
|
};
|
|
|
|
|
var make_string_template = function (_template, _fabrics = {}) {
|
|
|
|
|
function replace_tag(str, tag, value) {
|
|
|
|
|
var r = new RegExp("%" + tag + "%", "gi");
|
|
|
|
|
return str.replace(r, value);
|
|
|
|
|
}
|
|
|
|
|
function replace_tags(str, obj) {
|
|
|
|
|
return (Object.keys(obj).reduce(function (ret, key) {
|
|
|
|
|
return replace_tag(ret, key, _fabrics[key] || obj[key]);
|
|
|
|
|
}, str));
|
|
|
|
|
}
|
|
|
|
|
return (function (tags) {
|
|
|
|
|
return replace_tags(_template, tags);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
var make_eml_header = (function () {
|
|
|
|
|
let _template = "";
|
|
|
|
|
_template += "From: %from%\n";
|
|
|
|
|
_template += "To: %recipient%\n";
|
|
|
|
|
_template += "Subject: %subject%\n";
|
|
|
|
|
_template += "X-Mailer: greenscale-plankton.emlgen\n";
|
|
|
|
|
return make_string_template(_template);
|
|
|
|
|
})();
|
|
|
|
|
var make_eml_body = (function () {
|
|
|
|
|
let exports = {};
|
|
|
|
|
exports["simple_body"] = make_string_template("Content-Type: %contenttype%\n\n%body%\n\n");
|
|
|
|
|
// very basic implementation
|
|
|
|
|
// parts = [{contenttype:"text/html; charset=UTF-8", body: "<h1>foo</h1>" }, {...}]
|
|
|
|
|
exports["body_boundrary"] = function (parts, boundrary) {
|
|
|
|
|
let _template = "";
|
|
|
|
|
_template += "--%boundrary%\n";
|
|
|
|
|
_template += "Content-Type: %contenttype%\n\n%body%\n\n";
|
|
|
|
|
//_template += "--%boundrary%--\n\n";
|
|
|
|
|
let maker = make_string_template(_template);
|
|
|
|
|
return (parts.reduce(function (prev, curr) {
|
|
|
|
|
curr.boundrary = boundrary;
|
|
|
|
|
return [prev, maker(curr)].join("");
|
|
|
|
|
}, ""));
|
|
|
|
|
};
|
|
|
|
|
// body must be base64 encoded!
|
|
|
|
|
exports["attachment_boundrary"] = function (parts, boundrary) {
|
|
|
|
|
let _template = "";
|
|
|
|
|
_template += "--%boundrary%\n";
|
|
|
|
|
_template += "Content-Type: %contenttype%\n";
|
|
|
|
|
_template += "Content-Transfer-Encoding: base64\n";
|
|
|
|
|
_template += "Content-Disposition: %disposition%; filename=\"%name%\"\n\n";
|
|
|
|
|
_template += "%body%\n\n";
|
|
|
|
|
//_template += "--%boundrary%--\n\n";
|
|
|
|
|
let maker = make_string_template(_template);
|
|
|
|
|
return (parts.reduce(function (prev, curr) {
|
|
|
|
|
curr.boundrary = boundrary;
|
|
|
|
|
if (curr.disposition === void 0)
|
|
|
|
|
curr.disposition = "inline";
|
|
|
|
|
return [prev, maker(curr)].join("");
|
|
|
|
|
}, ""));
|
|
|
|
|
};
|
|
|
|
|
exports["gen_boundrary"] = function () {
|
|
|
|
|
return ("xxxxxxxxxxxxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
|
|
|
let r = crypto.getRandomValues(new Uint8Array(1))[0] % 16 | 0, v = c == "x" ? r : (r & 0x3 | 0x8);
|
|
|
|
|
return v.toString(16);
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
// simple implementation without alternatives (old rfc)
|
|
|
|
|
exports["complete_boundrary"] = function (bodyparts, attachments) {
|
|
|
|
|
let ret = "";
|
|
|
|
|
let boundrary = exports["gen_boundrary"]();
|
|
|
|
|
ret += exports["body_boundrary"](bodyparts, boundrary);
|
|
|
|
|
ret += exports["attachment_boundrary"](attachments, boundrary);
|
|
|
|
|
ret += "--" + boundrary + "--\n\nINVISIBLE!!!!";
|
|
|
|
|
return (exports["simple_body"]({
|
|
|
|
|
"contenttype": sprintf("multipart/mixed; boundary=%s", [boundrary]),
|
|
|
|
|
"body": ret
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
return exports;
|
|
|
|
|
})();
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:string«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:string« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:string« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:string«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var string;
|
|
|
|
|
(function (string) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
const hexdigits = 4;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
const index_max = (1 << (4 * hexdigits));
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var index_is = 0;
|
|
|
|
|
/**
|
|
|
|
|
* @author neuc,frac
|
|
|
|
|
*/
|
|
|
|
|
function empty(str) {
|
|
|
|
|
return (str.trim() === "");
|
|
|
|
|
}
|
|
|
|
|
string.empty = empty;
|
|
|
|
|
/**
|
|
|
|
|
* @desc returns a unique string
|
|
|
|
|
* @param {string} prefix an optional prefix for the generated string
|
|
|
|
|
* @return {string}
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function generate(prefix = "string_") {
|
|
|
|
|
if (index_is > index_max) {
|
|
|
|
|
throw (new Error("[string_generate] out of valid indices"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return string.sprintf(prefix + "%0" + hexdigits.toString() + "X", [index_is++]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string.generate = generate;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function join(parts, glue = " ") {
|
|
|
|
|
if (parts.length == 0) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return parts.join(glue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string.join = join;
|
|
|
|
|
/**
|
|
|
|
|
* @desc splits a string, but returns an empty list, if the string is empty
|
|
|
|
|
* @param {string} chain
|
|
|
|
|
* @param {string} separator
|
|
|
|
|
* @return {Array<string>}
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function split(chain, separator = " ") {
|
|
|
|
|
if (chain.length == 0) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return chain.split(separator);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string.split = split;
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no
|
|
|
|
|
*/
|
|
|
|
|
function explode(str, needle, max) {
|
|
|
|
|
let temp = str.split(needle);
|
|
|
|
|
const right = temp.splice(max - 1);
|
|
|
|
|
temp.push(right.join(needle));
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
string.explode = explode;
|
|
|
|
|
/**
|
|
|
|
|
* @desc concats a given word with itself n times
|
|
|
|
|
* @param {string} word
|
|
|
|
|
* @param {int}
|
|
|
|
|
* @return {string}
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function repeat(word, count) {
|
|
|
|
|
// return ((count == 0) ? "" : (word + repeat(word, count-1)));
|
|
|
|
|
let result = "";
|
|
|
|
|
for (let n = 0; n < count; n += 1) {
|
|
|
|
|
result += word;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
string.repeat = repeat;
|
|
|
|
|
/**
|
|
|
|
|
* @desc lengthens a string by repeatedly appending or prepending another string
|
|
|
|
|
* @param {string} word the string to pad
|
|
|
|
|
* @param {int} length the length, which the result shall have
|
|
|
|
|
* @param {string} symbol the string, which will be added (multiple times)
|
|
|
|
|
* @param {boolean} [prepend]; whether to prepend (~true) or append (~false); default: false
|
|
|
|
|
* @return {string} the padded string
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function pad(word, length, symbol = " ", mode = "append") {
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case "prepend": {
|
|
|
|
|
// insert symbols only at the beginning
|
|
|
|
|
while (word.length < length)
|
|
|
|
|
word = symbol + word;
|
|
|
|
|
return word.substring(word.length - length);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "append": {
|
|
|
|
|
// insert symbols only at the end
|
|
|
|
|
while (word.length < length)
|
|
|
|
|
word = word + symbol;
|
|
|
|
|
return word.substring(0, length);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "widen": {
|
|
|
|
|
// insert symbols at both sides
|
|
|
|
|
let left = (((length - word.length) & 1) === 0);
|
|
|
|
|
while (word.length < length) {
|
|
|
|
|
word = (left
|
|
|
|
|
? (symbol + word)
|
|
|
|
|
: (word + symbol));
|
|
|
|
|
left = (!left);
|
|
|
|
|
}
|
|
|
|
|
return word.substring(0, length);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
const message = ("unhandled mode '" + mode + "'");
|
|
|
|
|
console.warn(message);
|
|
|
|
|
return word;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string.pad = pad;
|
|
|
|
|
/**
|
|
|
|
|
* @desc checks if a given string conttains a certain substring
|
|
|
|
|
* @param {string} string
|
|
|
|
|
* @param {string} part
|
|
|
|
|
* @return {boolean}
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function contains(chain, part) {
|
|
|
|
|
if (typeof (chain) !== "string") {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return (chain.indexOf(part) >= 0);
|
|
|
|
|
}
|
|
|
|
|
string.contains = contains;
|
|
|
|
|
/**
|
|
|
|
|
* @desc checks if a given string starts with a certain substring
|
|
|
|
|
* @param {string} string
|
|
|
|
|
* @param {string} part
|
|
|
|
|
* @return {boolean}
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function startsWith(chain, part) {
|
|
|
|
|
if (typeof (chain) !== "string") {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// return (string.indexOf(part) === 0);
|
|
|
|
|
return ((function (m, n) {
|
|
|
|
|
if (n === 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (m === 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return ((chain[0] == part[0])
|
|
|
|
|
&&
|
|
|
|
|
startsWith(chain.substring(1), part.substring(1)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})(chain.length, part.length));
|
|
|
|
|
}
|
|
|
|
|
string.startsWith = startsWith;
|
|
|
|
|
/**
|
|
|
|
|
* @desc checks if a given string ends with a certain substring
|
|
|
|
|
* @param {string} string
|
|
|
|
|
* @param {string} part
|
|
|
|
|
* @return {boolean}
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function endsWith(chain, part) {
|
|
|
|
|
if (typeof (chain) !== "string") {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// return (string.lastIndexOf(part) === string.length-part.length);
|
|
|
|
|
return ((function (m, n) {
|
|
|
|
|
if (n === 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (m === 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// console.info(("(" + string[m-1] + " == " + part[n-1] + ")") + " = " + String(string[m-1] == part[n-1]));
|
|
|
|
|
return ((chain[m - 1] === part[n - 1])
|
|
|
|
|
&&
|
|
|
|
|
endsWith(chain.substring(0, m - 1), part.substring(0, n - 1)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})(chain.length, part.length));
|
|
|
|
|
}
|
|
|
|
|
string.endsWith = endsWith;
|
|
|
|
|
/**
|
|
|
|
|
* @desc count the occourrences of a string in a string
|
|
|
|
|
* @param string haystack_string the string wich should be examined
|
|
|
|
|
* @param string needle_string the string which should be counted
|
|
|
|
|
* @author neuc
|
|
|
|
|
*/
|
|
|
|
|
function count_occourrences(haystack_string, needle_string, check_escape) {
|
|
|
|
|
let cnt = 0;
|
|
|
|
|
let pos = -1;
|
|
|
|
|
do {
|
|
|
|
|
pos = haystack_string.indexOf(needle_string, pos + 1);
|
|
|
|
|
if ((!check_escape) || (haystack_string[pos - 1] != "\\")) {
|
|
|
|
|
cnt++;
|
|
|
|
|
}
|
|
|
|
|
} while (pos >= 0);
|
|
|
|
|
return (cnt - 1);
|
|
|
|
|
}
|
|
|
|
|
string.count_occourrences = count_occourrences;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function replace(str, replacements, options = {}) {
|
|
|
|
|
options = Object.assign({}, options);
|
|
|
|
|
let result = str;
|
|
|
|
|
replacements.forEach(replacement => {
|
|
|
|
|
lib_plankton.log.debug("lib_plankton.string.replace", {
|
|
|
|
|
"from": replacement.from,
|
|
|
|
|
"to": replacement.to,
|
|
|
|
|
});
|
|
|
|
|
result = result.replace(new RegExp(replacement.from, "g"), replacement.to);
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
string.replace = replace;
|
|
|
|
|
/**
|
|
|
|
|
* @desc replaces occurences of "{{name}}" in a string by the corresponding values of an argument object
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function coin(str, args, options = {}) {
|
|
|
|
|
options = Object.assign({
|
|
|
|
|
"legacy": false,
|
|
|
|
|
"open": "{{",
|
|
|
|
|
"close": "}}",
|
|
|
|
|
}, options);
|
|
|
|
|
Object.keys(args).forEach((key) => {
|
|
|
|
|
// old syntax
|
|
|
|
|
{
|
|
|
|
|
if (options.legacy) {
|
|
|
|
|
const value = args[key];
|
|
|
|
|
const regexp_argument = new RegExp("\\${" + key + "}", "g");
|
|
|
|
|
lib_plankton.log.debug("lib_plankton.string.coin", {
|
|
|
|
|
"key": key,
|
|
|
|
|
"regex": regexp_argument.toString(),
|
|
|
|
|
"value": value,
|
|
|
|
|
});
|
|
|
|
|
str = str.replace(regexp_argument, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// new syntax
|
|
|
|
|
{
|
|
|
|
|
const value = args[key];
|
|
|
|
|
const regexp_argument = new RegExp(options.open + key + options.close, "g");
|
|
|
|
|
lib_plankton.log.debug("lib_plankton.string.coin", {
|
|
|
|
|
"key": key,
|
|
|
|
|
"regex": regexp_argument.toString(),
|
|
|
|
|
"value": value,
|
|
|
|
|
});
|
|
|
|
|
str = str.replace(regexp_argument, value);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
string.coin = coin;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @deprecated use limit
|
|
|
|
|
*/
|
|
|
|
|
function cut(str, length, delimiter = "…") {
|
|
|
|
|
if (str.length <= length) {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return (str.slice(0, length - delimiter.length) + delimiter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string.cut = cut;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function limit(str, options = {}) {
|
|
|
|
|
options = Object.assign({
|
|
|
|
|
"length": 120,
|
|
|
|
|
"indicator": "…",
|
|
|
|
|
}, options);
|
|
|
|
|
return ((str.length <= options.length)
|
|
|
|
|
? str
|
|
|
|
|
: (str.slice(0, options.length - options.indicator.length) + options.indicator));
|
|
|
|
|
}
|
|
|
|
|
string.limit = limit;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function slice(str, size) {
|
|
|
|
|
let slices = [];
|
|
|
|
|
let rest = str;
|
|
|
|
|
while (rest.length > 0) {
|
|
|
|
|
slices.push(rest.slice(0, size));
|
|
|
|
|
rest = rest.slice(size);
|
|
|
|
|
}
|
|
|
|
|
return slices;
|
|
|
|
|
}
|
|
|
|
|
string.slice = slice;
|
|
|
|
|
})(string = lib_plankton.string || (lib_plankton.string = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
var lib_string;
|
|
|
|
|
(function (lib_string) {
|
|
|
|
|
lib_string.empty = lib_plankton.string.empty;
|
|
|
|
|
lib_string.generate = lib_plankton.string.generate;
|
|
|
|
|
lib_string.split = lib_plankton.string.split;
|
|
|
|
|
lib_string.explode = lib_plankton.string.repeat;
|
|
|
|
|
lib_string.repeat = lib_plankton.string.repeat;
|
|
|
|
|
lib_string.pad = lib_plankton.string.pad;
|
|
|
|
|
lib_string.contains = lib_plankton.string.contains;
|
|
|
|
|
lib_string.startsWith = lib_plankton.string.startsWith;
|
|
|
|
|
lib_string.endsWith = lib_plankton.string.endsWith;
|
|
|
|
|
lib_string.count_occourrences = lib_plankton.string.count_occourrences;
|
|
|
|
|
lib_string.coin = lib_plankton.string.coin;
|
|
|
|
|
lib_string.stance = lib_plankton.string.coin;
|
|
|
|
|
lib_string.cut = lib_plankton.string.cut;
|
|
|
|
|
})(lib_string || (lib_string = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:string«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:string« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:string« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:string«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var string;
|
|
|
|
|
(function (string) {
|
|
|
|
|
var pattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/;
|
|
|
|
|
var gpattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/g;
|
|
|
|
|
function split_format(format) {
|
|
|
|
|
var tmp = format.match(pattern);
|
|
|
|
|
if (tmp === null)
|
|
|
|
|
return null;
|
|
|
|
|
return {
|
|
|
|
|
'flags': tmp[1].split(""),
|
|
|
|
|
'width': Number(tmp[2]),
|
|
|
|
|
'precision': tmp[3] === '' ? null : Number(tmp[3]),
|
|
|
|
|
'specifier': tmp[4],
|
|
|
|
|
'string': format
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
function make_err(format, arg, should) {
|
|
|
|
|
return ("[sprintf]" + " " + "argument for '" + format.string + "' has to be '" + should + "' but '" + arg + "' is '" + typeof arg + "'!");
|
|
|
|
|
}
|
|
|
|
|
function test_arg(format, arg, should) {
|
|
|
|
|
if (typeof arg !== should) {
|
|
|
|
|
console.warn(make_err(format, arg, should));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
function string_fill(str, char, len, left) {
|
|
|
|
|
while (str.length < len) {
|
|
|
|
|
if (left) {
|
|
|
|
|
str += char;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
str = char + str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* the known_parameters are used to parse the different identifiers for the welln known syntax:
|
|
|
|
|
* flag width precision identifier
|
|
|
|
|
* %{[0#+- ]}{[0-9]*}.{[0-9]*}[fFdiueEgGsoxXaAsn]
|
|
|
|
|
* flags:
|
|
|
|
|
* 0 - fill with '0' instead of ' ' if the string length < width
|
|
|
|
|
* # - not implemented
|
|
|
|
|
* - - left-justified -> fill on the right side to reach width
|
|
|
|
|
* + - force using '+' on positive numbers
|
|
|
|
|
* ' ' - add a single space before positive numbers
|
|
|
|
|
*
|
|
|
|
|
* identifiers
|
|
|
|
|
* %f, %F - interpret given number as float, width: the minimal total width (fill with ' ' or '0' if the
|
|
|
|
|
* resulting string is too short, precision: cut more then given decimal places
|
|
|
|
|
* %d, %i, %u - interpret number as integer, decimal places will be cut. width: like float, precision:
|
|
|
|
|
* fill with '0' on right side until length given in precision is reached
|
|
|
|
|
* %e - interpret as float and write as scientifical number, width & precision like in float
|
|
|
|
|
* %E - same es %e but uppercase 'E'
|
|
|
|
|
* %g - use the shortest string of %f or %e
|
|
|
|
|
* %G - use the shortest string of %E or %E
|
|
|
|
|
* %s - simply print a string
|
|
|
|
|
* %o - print the given number in octal notation
|
|
|
|
|
* %x - print the given number in hex notation
|
|
|
|
|
* %X - same as %x but with uppercase characters
|
|
|
|
|
* %a - alias to %x
|
|
|
|
|
* %A - alias to %X
|
|
|
|
|
* %n - just print nothing
|
|
|
|
|
* @type {{}}
|
|
|
|
|
*/
|
|
|
|
|
var known_params = {};
|
|
|
|
|
known_params["f"] = function (format, arg) {
|
|
|
|
|
if (!test_arg(format, arg, "number"))
|
|
|
|
|
return "Ø";
|
|
|
|
|
var tmp = Math.abs(arg);
|
|
|
|
|
var sign = (arg < 0) ? -1 : 1;
|
|
|
|
|
var tmp_result = null;
|
|
|
|
|
if (format.precision !== null) {
|
|
|
|
|
tmp = Math.floor(Math.pow(10, format.precision) * tmp) / Math.pow(10, format.precision);
|
|
|
|
|
var tmp_ = (tmp * sign).toString().split(".");
|
|
|
|
|
if (tmp_.length === 1)
|
|
|
|
|
tmp_.push("");
|
|
|
|
|
tmp_[1] = string_fill(tmp_[1], "0", format.precision, true);
|
|
|
|
|
tmp_result = tmp_.join(".");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
tmp_result = (sign * tmp).toString();
|
|
|
|
|
}
|
|
|
|
|
if ((format.flags.indexOf(" ") >= 0) && (arg >= 0)) {
|
|
|
|
|
tmp_result = " " + tmp;
|
|
|
|
|
}
|
|
|
|
|
else if ((format.flags.indexOf("+") >= 0) && (arg >= 0)) {
|
|
|
|
|
tmp_result = "+" + tmp;
|
|
|
|
|
}
|
|
|
|
|
tmp_result = string_fill(tmp, (format.flags.indexOf("0") >= 0) ? "0" : " ", format.width, (format.flags.indexOf("-") >= 0));
|
|
|
|
|
return tmp_result;
|
|
|
|
|
};
|
|
|
|
|
known_params["F"] = known_params["f"];
|
|
|
|
|
known_params["d"] = function (format, arg) {
|
|
|
|
|
if (!test_arg(format, arg, 'number'))
|
|
|
|
|
return 'Ø';
|
|
|
|
|
var tmp = (((arg < 0 && format.specifier !== 'u') ? -1 : 1) * Math.floor(Math.abs(arg))).toString();
|
|
|
|
|
if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf(' ') >= 0 && arg >= 0) {
|
|
|
|
|
tmp = ' ' + tmp;
|
|
|
|
|
}
|
|
|
|
|
else if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf('+') >= 0 && arg >= 0) {
|
|
|
|
|
tmp = '+' + tmp;
|
|
|
|
|
}
|
|
|
|
|
tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0);
|
|
|
|
|
tmp = string_fill(tmp, '0', format.precision === null ? 0 : format.precision, false);
|
|
|
|
|
return tmp;
|
|
|
|
|
};
|
|
|
|
|
known_params["i"] = known_params["d"];
|
|
|
|
|
known_params["u"] = known_params["d"];
|
|
|
|
|
known_params["e"] = function (format, arg) {
|
|
|
|
|
if (!test_arg(format, arg, 'number'))
|
|
|
|
|
return 'Ø';
|
|
|
|
|
var tmp = arg.toExponential(format.precision === null ? undefined : format.precision).toString();
|
|
|
|
|
if (format.flags.indexOf(' ') >= 0 && arg >= 0) {
|
|
|
|
|
tmp = ' ' + tmp;
|
|
|
|
|
}
|
|
|
|
|
else if (format.flags.indexOf('+') >= 0 && arg >= 0) {
|
|
|
|
|
tmp = '+' + tmp;
|
|
|
|
|
}
|
|
|
|
|
tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0);
|
|
|
|
|
return tmp;
|
|
|
|
|
};
|
|
|
|
|
known_params["E"] = function (format, arg) {
|
|
|
|
|
return known_params["e"](format, arg).toUpperCase();
|
|
|
|
|
};
|
|
|
|
|
known_params["g"] = function (format, arg) {
|
|
|
|
|
if (!test_arg(format, arg, 'number'))
|
|
|
|
|
return 'Ø';
|
|
|
|
|
var tmpf = known_params["f"](format, arg);
|
|
|
|
|
var tmpe = known_params["e"](format, arg);
|
|
|
|
|
if (tmpf.length < tmpe.length) {
|
|
|
|
|
return tmpf;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return tmpe;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
known_params["G"] = function (format, arg) {
|
|
|
|
|
return known_params["g"](format, arg).toUpperCase();
|
|
|
|
|
};
|
|
|
|
|
known_params["s"] = function (format, arg) {
|
|
|
|
|
if (!test_arg(format, arg, 'string'))
|
|
|
|
|
return 'o.O';
|
|
|
|
|
var tmp = format.precision !== null ? arg.substr(0, format.precision) : arg;
|
|
|
|
|
tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0);
|
|
|
|
|
return tmp;
|
|
|
|
|
};
|
|
|
|
|
known_params["o"] = function (format, arg) {
|
|
|
|
|
if (!test_arg(format, arg, 'number'))
|
|
|
|
|
return 'Ø';
|
|
|
|
|
var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1);
|
|
|
|
|
return known_params["s"](format, tmp.toString(8));
|
|
|
|
|
};
|
|
|
|
|
known_params["x"] = function (format, arg) {
|
|
|
|
|
if (!test_arg(format, arg, 'number'))
|
|
|
|
|
return 'Ø';
|
|
|
|
|
var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1);
|
|
|
|
|
return known_params["s"](format, tmp.toString(16));
|
|
|
|
|
};
|
|
|
|
|
known_params["a"] = known_params["x"];
|
|
|
|
|
known_params["X"] = function (format, arg) {
|
|
|
|
|
if (!test_arg(format, arg, 'number'))
|
|
|
|
|
return 'Ø';
|
|
|
|
|
return known_params["x"](format, arg).toUpperCase();
|
|
|
|
|
};
|
|
|
|
|
known_params["A"] = known_params["X"];
|
|
|
|
|
known_params["c"] = function (format, arg) {
|
|
|
|
|
var tmp = "";
|
|
|
|
|
if (typeof arg === "number") {
|
|
|
|
|
tmp = String.fromCharCode(arg);
|
|
|
|
|
}
|
|
|
|
|
else if ((typeof arg === "string") && (arg.length === 1)) {
|
|
|
|
|
tmp = arg[0];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.warn(make_err(format, arg, "number|string") + " and if string it needs to have the length of 1!");
|
|
|
|
|
}
|
|
|
|
|
return known_params["s"](format, tmp);
|
|
|
|
|
};
|
|
|
|
|
known_params["n"] = function () {
|
|
|
|
|
return "";
|
|
|
|
|
};
|
|
|
|
|
var decompose = function (chain, regexp) {
|
|
|
|
|
var result = regexp.exec(chain);
|
|
|
|
|
if (result == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var front = chain.substring(0, result.index);
|
|
|
|
|
var back = chain.substring(result.index + result[0].length);
|
|
|
|
|
return { "front": front, "match": result[0], "back": back };
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* an implementation of c sprintf
|
|
|
|
|
* @param {string} string format string
|
|
|
|
|
* @param {array} args arguments which should be filled into
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
|
|
|
|
string.sprintf = function (input, args = [], original = null) {
|
|
|
|
|
if (original == null)
|
|
|
|
|
original = input;
|
|
|
|
|
var components = decompose(input, pattern);
|
|
|
|
|
if (components == null) {
|
|
|
|
|
if (args.length > 0) {
|
|
|
|
|
console.warn("[sprintf] superfluous arguments while formatting '" + original + "': ", args);
|
|
|
|
|
}
|
|
|
|
|
return input;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var arg;
|
|
|
|
|
var rest;
|
|
|
|
|
if (args.length > 0) {
|
|
|
|
|
arg = args[0];
|
|
|
|
|
rest = args.slice(1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.warn("[sprintf] out of arguments while formatting '" + original + "'");
|
|
|
|
|
arg = null;
|
|
|
|
|
rest = [];
|
|
|
|
|
return input;
|
|
|
|
|
}
|
|
|
|
|
var fmt = split_format(components["match"]);
|
|
|
|
|
return (components["front"]
|
|
|
|
|
+ known_params[fmt.specifier](fmt, arg)
|
|
|
|
|
+ string.sprintf(components["back"], rest, original));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* an implementation of c printf
|
|
|
|
|
* @param {string} string format string
|
|
|
|
|
* @param {array} args arguments which should be filled into
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
|
|
|
|
function printf(format, args) {
|
|
|
|
|
console.log(string.sprintf(format, args));
|
|
|
|
|
}
|
|
|
|
|
string.printf = printf;
|
|
|
|
|
})(string = lib_plankton.string || (lib_plankton.string = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
var sprintf = lib_plankton.string.sprintf;
|
|
|
|
|
var printf = lib_plankton.string.printf;
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:string«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:string« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:string« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:string«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var make_logger = (function () {
|
|
|
|
|
var _loggers = {};
|
|
|
|
|
var make_logger = function (prefix, current_loglevel) {
|
|
|
|
|
var log = [];
|
|
|
|
|
var level = [
|
|
|
|
|
"LOG", "INFO", "WARNING", "DEBUG"
|
|
|
|
|
];
|
|
|
|
|
var logger = function (obj, lvl) {
|
|
|
|
|
var txt = obj.txt || obj;
|
|
|
|
|
if (lvl == void 0)
|
|
|
|
|
lvl = 0;
|
|
|
|
|
var date = new Date();
|
|
|
|
|
log.push({
|
|
|
|
|
"message": sprintf("%s [%s:%s] %s", [date.toString(), level[lvl], prefix, txt]),
|
|
|
|
|
"timeStamp": +(date)
|
|
|
|
|
});
|
|
|
|
|
if (lvl <= current_loglevel) {
|
|
|
|
|
var msg = ["[" + prefix + "]", txt];
|
|
|
|
|
if (obj.arg)
|
|
|
|
|
msg = ["[" + prefix + "]"].concat(Array.prototype.slice.call(obj.arg));
|
|
|
|
|
if (lvl === 0)
|
|
|
|
|
console["_log"].apply(console, msg);
|
|
|
|
|
else if (lvl === 1)
|
|
|
|
|
console["_info"].apply(console, msg);
|
|
|
|
|
else if (lvl === 2)
|
|
|
|
|
console["_warn"].apply(console, msg);
|
|
|
|
|
else if (lvl >= 3)
|
|
|
|
|
console["_log"].apply(console, msg);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
_loggers[prefix] = {
|
|
|
|
|
"logger": logger,
|
|
|
|
|
"log": log
|
|
|
|
|
};
|
|
|
|
|
return logger;
|
|
|
|
|
};
|
|
|
|
|
make_logger["loggers"] = _loggers;
|
|
|
|
|
make_logger["complete_log"] = function () {
|
|
|
|
|
var logs = Object.keys(_loggers)
|
|
|
|
|
.reduce(function (p, c) {
|
|
|
|
|
return [].concat(p, _loggers[c].log);
|
|
|
|
|
}, []);
|
|
|
|
|
logs.sort(function (x, y) {
|
|
|
|
|
return ((x.timeStamp > y.timeStamp) ? -1 : +1);
|
|
|
|
|
});
|
|
|
|
|
return logs.map(function (x, i, a) {
|
|
|
|
|
return x.message;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
if ( /*!track_exports*/true) {
|
|
|
|
|
var _log_all = function (log, lvl, next = function () { }) {
|
|
|
|
|
return function () {
|
|
|
|
|
var msg = [];
|
|
|
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
|
|
|
if (typeof arguments[i] === "string") {
|
|
|
|
|
msg.push(arguments[i]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
msg.push(JSON.stringify(arguments[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var obj = {
|
|
|
|
|
txt: msg.join("\t"),
|
|
|
|
|
arg: arguments
|
|
|
|
|
};
|
|
|
|
|
log(obj, lvl);
|
|
|
|
|
next();
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
{
|
|
|
|
|
var __warn = make_logger("deprecated console.warn", 99);
|
|
|
|
|
var __error = make_logger("deprecated console.error", 99);
|
|
|
|
|
var __log = make_logger("deprecated console.log", 99);
|
|
|
|
|
var __info = make_logger("deprecated console.info", 99);
|
|
|
|
|
// bad ass
|
|
|
|
|
console["_log"] = console.log;
|
|
|
|
|
console["_error"] = console.error;
|
|
|
|
|
console["_warn"] = console.warn;
|
|
|
|
|
console["_info"] = console.info;
|
|
|
|
|
/*
|
|
|
|
|
console["log"] = _log_all(__log, 0);
|
|
|
|
|
console["error"] = _log_all(__error, 2);
|
|
|
|
|
console["warn"] = _log_all(__warn, 2);
|
|
|
|
|
console["info"] = _log_all(__info, 0);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
{
|
|
|
|
|
make_logger["send_log"] = function(){
|
|
|
|
|
eml_log(
|
|
|
|
|
function () {
|
|
|
|
|
alert("fehlerbericht wurde gesendet!");
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
var error_log = make_logger("global.error", 99);
|
|
|
|
|
window.onerror = _log_all(
|
|
|
|
|
error_log,
|
|
|
|
|
1,
|
|
|
|
|
function(){
|
|
|
|
|
if (global_config == undefined) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (global_config.report_error) {
|
|
|
|
|
make_logger["send_log"]();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
return make_logger;
|
|
|
|
|
})();
|
2024-09-09 21:00:52 +02:00
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:complex«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:complex« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:complex« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:complex«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var complex;
|
|
|
|
|
(function (complex) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function _sequence(n) {
|
|
|
|
|
return ((n <= 0) ? [] : _sequence(n - 1).concat([n - 1]));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function _coin(template, arguments_) {
|
|
|
|
|
if (arguments_ === void 0) { arguments_ = {}; }
|
|
|
|
|
var result = template;
|
|
|
|
|
Object.keys(arguments_).forEach(function (key) {
|
|
|
|
|
var pattern = ("{{" + key + "}}");
|
|
|
|
|
var replacement = String(arguments_[key]);
|
|
|
|
|
result = result.replace(new RegExp(pattern, "g"), replacement);
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* erstellt eine komplexe Zahl anhand ihrer kartesianischen Koordinaten
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function make_cartesian(rea_, ima_) {
|
|
|
|
|
return {
|
|
|
|
|
"rea": rea_,
|
|
|
|
|
"ima": ima_
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
complex.make_cartesian = make_cartesian;
|
|
|
|
|
/**
|
|
|
|
|
* erstellt eine komplexe Zahl anhand ihrer Polar-Koordinaten
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function make_polar(abs, arg) {
|
|
|
|
|
return (make_cartesian((abs * Math.cos(arg)), (abs * Math.sin(arg))));
|
|
|
|
|
}
|
|
|
|
|
complex.make_polar = make_polar;
|
|
|
|
|
/**
|
|
|
|
|
* alias zu "make_cartesian"
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function make(rea_, ima_) {
|
|
|
|
|
return (make_cartesian(rea_, ima_));
|
|
|
|
|
}
|
|
|
|
|
complex.make = make;
|
|
|
|
|
/**
|
|
|
|
|
* erstellt die komplexe Null
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function nul() {
|
|
|
|
|
return (make(0, 0));
|
|
|
|
|
}
|
|
|
|
|
complex.nul = nul;
|
|
|
|
|
/**
|
|
|
|
|
* erstellt die komplexe Eins
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function one() {
|
|
|
|
|
return (make(1, 0));
|
|
|
|
|
}
|
|
|
|
|
complex.one = one;
|
|
|
|
|
/**
|
|
|
|
|
* gibt den Real-Teil einer komplexen Zahl zurück
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function rea(x) {
|
|
|
|
|
return (x.rea);
|
|
|
|
|
}
|
|
|
|
|
complex.rea = rea;
|
|
|
|
|
/**
|
|
|
|
|
* gibt den Imaginär-Teil einer komplexen Zahl zurück
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function ima(x) {
|
|
|
|
|
return (x.ima);
|
|
|
|
|
}
|
|
|
|
|
complex.ima = ima;
|
|
|
|
|
/**
|
|
|
|
|
* gibt die konjugierte komplexe Zahl zurück
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function con(x) {
|
|
|
|
|
return (make(+x.rea, -x.ima));
|
|
|
|
|
}
|
|
|
|
|
complex.con = con;
|
|
|
|
|
/**
|
|
|
|
|
* gibt den quadrierten Betrag einer komplexen Zahl zurück
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function sqrabs(x) {
|
|
|
|
|
return (((x.rea * x.rea) + (x.ima * x.ima)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* gibt den Betrag einer komplexen Zahl zurück
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function abs(x) {
|
|
|
|
|
return (Math.sqrt(sqrabs(x)));
|
|
|
|
|
}
|
|
|
|
|
complex.abs = abs;
|
|
|
|
|
/**
|
|
|
|
|
* gibt das Argument einer komplexen Zahl zurück (auf dem Hauptzweig des komplexen Logarithmus)
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function arg(x) {
|
|
|
|
|
return Math.atan2(x.ima, x.rea);
|
|
|
|
|
}
|
|
|
|
|
complex.arg = arg;
|
|
|
|
|
/**
|
|
|
|
|
* gibt eine skalierte komplexe Zahl zurück (das Produkt mit einer reellen Zahl)
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function scl(x, s) {
|
|
|
|
|
return (make((x.rea * s), (x.ima * s)));
|
|
|
|
|
}
|
|
|
|
|
complex.scl = scl;
|
|
|
|
|
/**
|
|
|
|
|
* errechnet die Summe zweier komplexer Zahl
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function add(x, y) {
|
|
|
|
|
return (make((x.rea + y.rea), (x.ima + y.ima)));
|
|
|
|
|
}
|
|
|
|
|
complex.add = add;
|
|
|
|
|
/**
|
|
|
|
|
* gibt die additiv inverse, also negierte komplexe Zahl zurück
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function neg(x) {
|
|
|
|
|
return (make(-x.rea, -x.ima));
|
|
|
|
|
}
|
|
|
|
|
complex.neg = neg;
|
|
|
|
|
/**
|
|
|
|
|
* ermittelt die Differenz zweier komplexer Zahlen
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function sub(x, y) {
|
|
|
|
|
return (add(x, neg(y)));
|
|
|
|
|
}
|
|
|
|
|
complex.sub = sub;
|
|
|
|
|
/**
|
|
|
|
|
* ermittelt das Produkt zweier komplexer Zahlen
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function mul(x, y) {
|
|
|
|
|
return (make(((x.rea * y.rea) - (x.ima * y.ima)), ((x.rea * y.ima) + (x.ima * y.rea))));
|
|
|
|
|
}
|
|
|
|
|
complex.mul = mul;
|
|
|
|
|
/**
|
|
|
|
|
* ermittelt die multiplikativ inverse komplexe Zahl, also den Kehrwert
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function inv(x) {
|
|
|
|
|
var a = sqrabs(x);
|
|
|
|
|
if (a <= 0) {
|
|
|
|
|
var message = "die komplexe Null ist nicht invertiebar";
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return (scl(con(x), (1 / a)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
complex.inv = inv;
|
|
|
|
|
/**
|
|
|
|
|
* ermittelt den Quotienten zweier komplexer Zahlen
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function div(x, y) {
|
|
|
|
|
return (mul(x, inv(y)));
|
|
|
|
|
}
|
|
|
|
|
complex.div = div;
|
|
|
|
|
/**
|
|
|
|
|
* ermittelt die natürliche Potenz einer komplexen Zahl
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function npow(x, n) {
|
|
|
|
|
if (n < 0) {
|
|
|
|
|
var message = "invalid exponent";
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var y_1 = one();
|
|
|
|
|
_sequence(n).forEach(function () { y_1 = mul(y_1, x); });
|
|
|
|
|
return y_1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
complex.npow = npow;
|
|
|
|
|
/**
|
|
|
|
|
* ermittelt die natürliche Potenz einer komplexen Zahl
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @deprecated use "npow" instead
|
|
|
|
|
* @todo remove
|
|
|
|
|
*/
|
|
|
|
|
function exp(x, n) {
|
|
|
|
|
return npow(x, n);
|
|
|
|
|
}
|
|
|
|
|
complex.exp = exp;
|
|
|
|
|
/**
|
|
|
|
|
* ermittelt die Potenz zweier komplexer Zahlen
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo Probleme der komplexen Exponentiation berücksichtigen
|
|
|
|
|
*/
|
|
|
|
|
function pow(x, y) {
|
|
|
|
|
var a = abs(x);
|
|
|
|
|
var b = arg(x);
|
|
|
|
|
var c = y.rea;
|
|
|
|
|
var d = y.ima;
|
|
|
|
|
if (a === 0) {
|
|
|
|
|
throw (new Error("not implemented"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var l = Math.log(a);
|
|
|
|
|
return (make_polar(Math.exp((l * c) - (b * d)), ((l * d) + (b * c))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
complex.pow = pow;
|
|
|
|
|
/**
|
|
|
|
|
* gibt die n-ten komplexen Einheits-Wurzeln zurück ({x ∈ C | x^n = 1})
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function unitroots(n) {
|
|
|
|
|
return (_sequence(n)
|
|
|
|
|
.map(function (k) { return make_polar(1, (k / (n + 0.0)) * (2 * Math.PI)); }));
|
|
|
|
|
}
|
|
|
|
|
complex.unitroots = unitroots;
|
|
|
|
|
/**
|
|
|
|
|
* {x ∈ C | x^n = y}
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function normroots(n, y) {
|
|
|
|
|
var z = make_polar(Math.pow(abs(y), (1.0 / n)), (arg(y) / n));
|
|
|
|
|
return (unitroots(n)
|
|
|
|
|
.map(function (w) { return mul(w, z); }));
|
|
|
|
|
}
|
|
|
|
|
complex.normroots = normroots;
|
|
|
|
|
/**
|
|
|
|
|
* ermittelt ob zwei komplexe Zahlen gleich sind
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function equ(x, y, threshold) {
|
|
|
|
|
if (threshold === void 0) { threshold = 0.005; }
|
|
|
|
|
// return (abs(sub(x, y)) <= threshold);
|
|
|
|
|
return ((Math.abs(x.rea - y.rea) <= threshold)
|
|
|
|
|
&&
|
|
|
|
|
(Math.abs(x.ima - y.ima) <= threshold));
|
|
|
|
|
}
|
|
|
|
|
complex.equ = equ;
|
|
|
|
|
/**
|
|
|
|
|
* gibt eine textuelle Repräsentation einer komplexen Zahl zurück
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function str(x) {
|
|
|
|
|
return _coin(
|
|
|
|
|
// "(({{rea}}) + ({{ima}}·i))",
|
|
|
|
|
"<{{rea}},{{ima}}>", {
|
|
|
|
|
"rea": x.rea.toFixed(4),
|
|
|
|
|
"ima": x.ima.toFixed(4)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
complex.str = str;
|
|
|
|
|
})(complex = lib_plankton.complex || (lib_plankton.complex = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:complex«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:complex« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:complex« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:complex«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var complex;
|
|
|
|
|
(function (complex) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var class_complex = /** @class */ (function () {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function class_complex(subject) {
|
|
|
|
|
this.subject = subject;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex._cram = function (subject) {
|
|
|
|
|
return (new class_complex(subject));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex._tear = function (instance) {
|
|
|
|
|
return instance.subject;
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.make_cartesian = function (rea, ima) {
|
|
|
|
|
return (class_complex._cram(complex.make_cartesian(rea, ima)));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.make_polar = function (abs, arg) {
|
|
|
|
|
return (class_complex._cram(complex.make_polar(abs, arg)));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.make = function (rea, ima) {
|
|
|
|
|
return (class_complex._cram(complex.make(rea, ima)));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.nul = function () {
|
|
|
|
|
return (class_complex._cram(complex.nul()));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.one = function () {
|
|
|
|
|
return (class_complex._cram(complex.one()));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.con = function () {
|
|
|
|
|
return (class_complex._cram(complex.con(class_complex._tear(this))));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.abs = function () {
|
|
|
|
|
return (complex.abs(class_complex._tear(this)));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.arg = function () {
|
|
|
|
|
return (complex.arg(class_complex._tear(this)));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.scl = function (s) {
|
|
|
|
|
return (class_complex._cram(complex.scl(class_complex._tear(this), s)));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.add = function (other) {
|
|
|
|
|
return (class_complex._cram(complex.add(class_complex._tear(this), class_complex._tear(other))));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.neg = function () {
|
|
|
|
|
return (class_complex._cram(complex.neg(class_complex._tear(this))));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.sub = function (other) {
|
|
|
|
|
return (class_complex._cram(complex.sub(class_complex._tear(this), class_complex._tear(other))));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.mul = function (other) {
|
|
|
|
|
return (class_complex._cram(complex.mul(class_complex._tear(this), class_complex._tear(other))));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.inv = function () {
|
|
|
|
|
return (class_complex._cram(complex.inv(class_complex._tear(this))));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.div = function (other) {
|
|
|
|
|
return (class_complex._cram(complex.div(class_complex._tear(this), class_complex._tear(other))));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.exp = function (n) {
|
|
|
|
|
return (class_complex._cram(complex.exp(class_complex._tear(this), n)));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.pow = function (other) {
|
|
|
|
|
return (class_complex._cram(complex.pow(class_complex._tear(this), class_complex._tear(other))));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.equ = function (other) {
|
|
|
|
|
return (complex.equ(class_complex._tear(this), class_complex._tear(other)));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.str = function () {
|
|
|
|
|
return (complex.str(class_complex._tear(this)));
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_complex.prototype.toString = function () {
|
|
|
|
|
return this.str();
|
|
|
|
|
};
|
|
|
|
|
return class_complex;
|
|
|
|
|
}());
|
|
|
|
|
complex.class_complex = class_complex;
|
|
|
|
|
})(complex = lib_plankton.complex || (lib_plankton.complex = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:math«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:math« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:math« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:math«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var math;
|
|
|
|
|
(function (math) {
|
|
|
|
|
/**
|
|
|
|
|
* @desc golden ratio (e.g. for generating colors)
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
math.phi = ((Math.sqrt(5) - 1) / 2);
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
math.e = Math.E;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
math.pi = Math.PI;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
math.tau = (2 * Math.PI);
|
|
|
|
|
})(math = lib_plankton.math || (lib_plankton.math = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:math«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:math« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:math« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:math«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var math;
|
|
|
|
|
(function (math) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function clamp(x, a = 0.0, b = 1.0) {
|
|
|
|
|
return Math.min(Math.max(x, a), b);
|
|
|
|
|
}
|
|
|
|
|
math.clamp = clamp;
|
|
|
|
|
/**
|
|
|
|
|
* @desc the mathematical sign-function
|
|
|
|
|
* @return {int} an element of {-1,0,+1}
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function sgn(x) {
|
|
|
|
|
if (x === 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (x < 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
else /* (x > 0) */ {
|
|
|
|
|
return +1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
math.sgn = sgn;
|
|
|
|
|
/**
|
|
|
|
|
* @desc integer division
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function div(x, y) {
|
|
|
|
|
return Math.floor(x / y);
|
|
|
|
|
}
|
|
|
|
|
math.div = div;
|
|
|
|
|
/**
|
|
|
|
|
* @desc real modulo operator
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function mod(x, y) {
|
|
|
|
|
// return (x - (div(x, y) * y));
|
|
|
|
|
if (y <= 0) {
|
|
|
|
|
throw (new Error("invalid divisor"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return ((x >= 0)
|
|
|
|
|
? (x % y)
|
|
|
|
|
: ((y - ((-x) % y)) % y));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
math.mod = mod;
|
|
|
|
|
/**
|
|
|
|
|
* @desc computes "x^y mod z" via square-and-multiply
|
|
|
|
|
* @param {int} base ("x")
|
|
|
|
|
* @param {int} exponent ("y")
|
|
|
|
|
* @param {int} modulus ("z")
|
|
|
|
|
* @return {int}
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo handle invalid cases (e.g. "z < 1")
|
|
|
|
|
* @todo implement iteratively
|
|
|
|
|
*/
|
|
|
|
|
function modpow(base, exponent, modulus) {
|
|
|
|
|
/*
|
|
|
|
|
The idea is the following:
|
|
|
|
|
|
|
|
|
|
x^y
|
|
|
|
|
= x^((y div 2)·2 + (y mod 2))
|
|
|
|
|
= x^((y div 2)·2) · x^(y mod 2)
|
|
|
|
|
= (x^(y div 2))^2 · x^(y mod 2)
|
|
|
|
|
|
|
|
|
|
For computing (x^(y div 2)) the algorithm is used recursively. Building the square is done without any magic.
|
|
|
|
|
The second factor is either 1 or x, since (y mod 2) is either 0 or 1; in other words: multiplying x to the first
|
|
|
|
|
factor is only necessary if y is odd.
|
|
|
|
|
*/
|
|
|
|
|
if (exponent === 0) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let a = modpow(base, exponent >> 1, modulus);
|
|
|
|
|
a = ((a * a) % modulus);
|
|
|
|
|
if ((exponent & 1) != 0) {
|
|
|
|
|
a = ((a * base) % modulus);
|
|
|
|
|
}
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
math.modpow = modpow;
|
|
|
|
|
/**
|
|
|
|
|
* @desc determines if two integers are coprime, i.e. that they don't have a common divisor greater than 1
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo write function "gcdx" and base on it
|
|
|
|
|
*/
|
|
|
|
|
function coprime(x, y) {
|
|
|
|
|
if (y === 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (y === 1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let z = mod(x, y);
|
|
|
|
|
return coprime(y, z);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
math.coprime = coprime;
|
|
|
|
|
/**
|
|
|
|
|
* @desc extended euclidean algorithm for computing multiplicative inverse elements
|
|
|
|
|
* @param {int} modulus
|
|
|
|
|
* @param {int} element
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo write function "gcdx" and base on it
|
|
|
|
|
* @todo handle more invalid cases
|
|
|
|
|
*/
|
|
|
|
|
function inv(modulus, element, positive = false) {
|
|
|
|
|
if (element === 0) {
|
|
|
|
|
throw (new Error("not invertable"));
|
|
|
|
|
}
|
|
|
|
|
else if (element === 1) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let result = div(1 - (modulus * inv(element, mod(modulus, element), false)), element);
|
|
|
|
|
return (positive ? mod(result, modulus) : result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
math.inv = inv;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function interpolate_linear(x, y, t = 0.5) {
|
|
|
|
|
return ((1 - t) * x + t * y);
|
|
|
|
|
}
|
|
|
|
|
math.interpolate_linear = interpolate_linear;
|
|
|
|
|
/**
|
|
|
|
|
* @desc kind of the inverse of linear interpolation; i.e. to find the coefficient "t" for given values x, y and
|
|
|
|
|
* their presumed interpolation v
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function appoint_linear(x, y, v) {
|
|
|
|
|
return ((v - x) / (y - x));
|
|
|
|
|
}
|
|
|
|
|
math.appoint_linear = appoint_linear;
|
|
|
|
|
/**
|
|
|
|
|
* continued fraction decomposition
|
|
|
|
|
*/
|
|
|
|
|
function cfd(x, n = (1 << 4)) {
|
|
|
|
|
let result = [];
|
|
|
|
|
let m = 0;
|
|
|
|
|
let y = x;
|
|
|
|
|
while (true) {
|
|
|
|
|
if (m >= n) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const a = Math.floor(y);
|
|
|
|
|
result.push(a);
|
|
|
|
|
if (y === a) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
y = (1 / (y - a));
|
|
|
|
|
m += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
math.cfd = cfd;
|
|
|
|
|
})(math = lib_plankton.math || (lib_plankton.math = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:math«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:math« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:math« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:math«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var math;
|
|
|
|
|
(function (math) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_relation {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
check(value, reference) {
|
|
|
|
|
return this.predicate(value, reference);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
/*protected*/ constructor(id, { "symbol": symbol = null, "name": name = null, "predicate": predicate, }) {
|
|
|
|
|
this.id = id;
|
|
|
|
|
this.symbol = symbol;
|
|
|
|
|
this.name = name;
|
|
|
|
|
this.predicate = predicate;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
id_get() {
|
|
|
|
|
return this.id;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
symbol_get() {
|
|
|
|
|
return this.symbol;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
name_get() {
|
|
|
|
|
return this.name;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [implementation]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
_show() {
|
|
|
|
|
return `[${this.symbol}]`;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [implementation]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
_hash() {
|
|
|
|
|
return this.id;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [accessor] [implementation]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
_collate(relation) {
|
|
|
|
|
return (this.id == relation.id);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
toString() {
|
|
|
|
|
return this._show();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static pool() {
|
|
|
|
|
return {
|
|
|
|
|
"eq": {
|
|
|
|
|
"symbol": "=",
|
|
|
|
|
"name": "gleich",
|
|
|
|
|
"predicate": (value, reference) => (value == reference),
|
|
|
|
|
},
|
|
|
|
|
"ne": {
|
|
|
|
|
"symbol": "≠",
|
|
|
|
|
"name": "ungleich",
|
|
|
|
|
"predicate": (value, reference) => (value != reference),
|
|
|
|
|
},
|
|
|
|
|
"gt": {
|
|
|
|
|
"symbol": ">",
|
|
|
|
|
"name": "größer",
|
|
|
|
|
"predicate": (value, reference) => (value > reference),
|
|
|
|
|
},
|
|
|
|
|
"ge": {
|
|
|
|
|
"symbol": "≥",
|
|
|
|
|
"name": "größer oder gleich",
|
|
|
|
|
"predicate": (value, reference) => (value >= reference),
|
|
|
|
|
},
|
|
|
|
|
"lt": {
|
|
|
|
|
"symbol": "<",
|
|
|
|
|
"name": "kleiner",
|
|
|
|
|
"predicate": (value, reference) => (value < reference),
|
|
|
|
|
},
|
|
|
|
|
"le": {
|
|
|
|
|
"symbol": "≤",
|
|
|
|
|
"name": "kleiner oder gleich",
|
|
|
|
|
"predicate": (value, reference) => (value <= reference),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static get(id) {
|
|
|
|
|
let pool = this.pool();
|
|
|
|
|
if (id in pool) {
|
|
|
|
|
return (new class_relation(id, pool[id]));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw (new Error(`no such relation`));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static available() {
|
|
|
|
|
return Object.keys(this.pool());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
math.class_relation = class_relation;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_filtrationitem {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor({ "extract": extract, "relation": relation, "reference": reference, }) {
|
|
|
|
|
this.extract = extract;
|
|
|
|
|
this.relation = relation;
|
|
|
|
|
this.reference = reference;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
check(dataset) {
|
|
|
|
|
let value = this.extract(dataset);
|
|
|
|
|
let result = this.relation.check(value, this.reference);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [implementation]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
_show() {
|
|
|
|
|
return `(${this.relation.symbol_get()} ${instance_show(this.reference)})`;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
toString() {
|
|
|
|
|
return this._show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
math.class_filtrationitem = class_filtrationitem;
|
|
|
|
|
/**
|
|
|
|
|
* @desc disjunctive normal form
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_filtration {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor(clauses) {
|
|
|
|
|
this.clauses = clauses;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
check(dataset) {
|
|
|
|
|
return (this.clauses.some(clause => clause.every(literal => literal.check(dataset))));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
use(datasets) {
|
|
|
|
|
return datasets.filter(dataset => this.check(dataset));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc [implementation]
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
_show() {
|
|
|
|
|
return ("{" + this.clauses.map(clause => ("[" + clause.map(instance_show).join(",") + "]")).join(",") + "}");
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
toString() {
|
|
|
|
|
return this._show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
math.class_filtration = class_filtration;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
function comparator_to_relation(comparator) {
|
|
|
|
|
console.warn("deprecated!");
|
|
|
|
|
return ((x, y) => (comparator(x, y) <= 0));
|
|
|
|
|
}
|
|
|
|
|
math.comparator_to_relation = comparator_to_relation;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
function relation_to_comparator(relation) {
|
|
|
|
|
console.warn("deprecated!");
|
|
|
|
|
return ((x, y) => (relation(x, y) ? (relation(y, x) ? 0 : -1) : 1));
|
|
|
|
|
}
|
|
|
|
|
math.relation_to_comparator = relation_to_comparator;
|
|
|
|
|
})(math = lib_plankton.math || (lib_plankton.math = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:math«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:math« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:math« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:math«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_calculus;
|
|
|
|
|
(function (lib_calculus) {
|
|
|
|
|
/**
|
|
|
|
|
* @class Calculus
|
|
|
|
|
* @desc Ensure precision of mathematical operations
|
|
|
|
|
*/
|
|
|
|
|
class Calculus {
|
|
|
|
|
/**
|
|
|
|
|
* @constructor
|
|
|
|
|
* @þaram {number} norm
|
|
|
|
|
*/
|
|
|
|
|
constructor(norm = 100000) {
|
|
|
|
|
this.NORM = norm;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* normalize
|
|
|
|
|
* @param {number} value
|
|
|
|
|
* @return {number}
|
|
|
|
|
*/
|
|
|
|
|
normalize(value) {
|
|
|
|
|
return (Math.floor(value * this.NORM));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* denormalize
|
|
|
|
|
* @param {number} value
|
|
|
|
|
* @return {number}
|
|
|
|
|
*/
|
|
|
|
|
denormalize(value) {
|
|
|
|
|
return (Math.floor(value) / this.NORM);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lib_calculus.Calculus = Calculus;
|
|
|
|
|
})(lib_calculus || (lib_calculus = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:math«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:math« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:math« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:math«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var math;
|
|
|
|
|
(function (math) {
|
|
|
|
|
/**
|
|
|
|
|
* {x ∈ C | 0 = x³ + px + q}
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function cardano_reduced(p, q) {
|
|
|
|
|
// (p/3)^3 + (q/2)^2
|
|
|
|
|
const determinant = (lib_plankton.complex.add(lib_plankton.complex.exp(lib_plankton.complex.scl(p, 1 / 3.0), 3), lib_plankton.complex.exp(lib_plankton.complex.scl(q, 1 / 2.0), 2)));
|
|
|
|
|
const [u, v] = (lib_plankton.complex.normroots(2, determinant)
|
|
|
|
|
.map(w => lib_plankton.complex.sub(w, lib_plankton.complex.scl(q, 1 / 2.0)))
|
|
|
|
|
.map(z => lib_plankton.complex.normroots(3, z)));
|
|
|
|
|
return [
|
|
|
|
|
/*
|
|
|
|
|
lib_plankton.complex.add(u[0], v[0]),
|
|
|
|
|
lib_plankton.complex.add(u[1], v[2]),
|
|
|
|
|
lib_plankton.complex.add(u[2], v[1]),
|
|
|
|
|
*/
|
|
|
|
|
// (p = -3uv) → (v = p/(-3u)) → (v = (p/(-3))/u)
|
|
|
|
|
lib_plankton.complex.add(u[0], lib_plankton.complex.div(lib_plankton.complex.scl(p, -1 / 3.0), u[0])),
|
|
|
|
|
lib_plankton.complex.add(u[1], lib_plankton.complex.div(lib_plankton.complex.scl(p, -1 / 3.0), u[1])),
|
|
|
|
|
lib_plankton.complex.add(u[2], lib_plankton.complex.div(lib_plankton.complex.scl(p, -1 / 3.0), u[2])),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* {x ∈ C | 0 = x³ + ex² + fx + g}
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function cardano_normalized(e, f, g) {
|
|
|
|
|
// p := (-1/3)·e² + f
|
|
|
|
|
const p = (lib_plankton.complex.add(lib_plankton.complex.scl(lib_plankton.complex.exp(e, 2), -1 / 3.0), f));
|
|
|
|
|
// q := (2/27)·e³ + (-1/3)·e·f + g
|
|
|
|
|
const q = (lib_plankton.complex.add(lib_plankton.complex.add(lib_plankton.complex.scl(lib_plankton.complex.exp(e, 3), +2 / 27.0), lib_plankton.complex.scl(lib_plankton.complex.mul(e, f), -1 / 3.0)), g));
|
|
|
|
|
return (cardano_reduced(p, q)
|
|
|
|
|
.map(y => lib_plankton.complex.sub(y, lib_plankton.complex.scl(e, 1 / 3.0))));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* {x ∈ C | 0 = ax³ + bx² + cx + d}
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function cubic_solve(a, b, c, d) {
|
|
|
|
|
if (lib_plankton.complex.equ(a, lib_plankton.complex.nul())) {
|
|
|
|
|
const message = "Leitkoeffizient ist Null; dadurch sollte sich das Problem eigentlich vereinfachen";
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// e = b/a
|
|
|
|
|
const e = lib_plankton.complex.div(b, a);
|
|
|
|
|
// f = c/a
|
|
|
|
|
const f = lib_plankton.complex.div(c, a);
|
|
|
|
|
// g = d/a
|
|
|
|
|
const g = lib_plankton.complex.div(d, a);
|
|
|
|
|
return cardano_normalized(e, f, g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
math.cubic_solve = cubic_solve;
|
|
|
|
|
/**
|
|
|
|
|
* {x ∈ C | 0 = ax³ + bx² + cx + d}
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function cubic_solve_real(a, b, c, d) {
|
|
|
|
|
return cubic_solve(lib_plankton.complex.make(a, 0), lib_plankton.complex.make(b, 0), lib_plankton.complex.make(c, 0), lib_plankton.complex.make(d, 0));
|
|
|
|
|
}
|
|
|
|
|
math.cubic_solve_real = cubic_solve_real;
|
|
|
|
|
/**
|
|
|
|
|
* gets the coefficients of a polynom by the roots
|
|
|
|
|
*
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
/*export*/ function cubic_construct(solutions) {
|
|
|
|
|
const [x, y, z] = solutions.map(lib_plankton.complex.neg);
|
|
|
|
|
const mix = function (values) {
|
|
|
|
|
return (values
|
|
|
|
|
.map(group => (group
|
|
|
|
|
.reduce(lib_plankton.complex.mul, lib_plankton.complex.one())))
|
|
|
|
|
.reduce(lib_plankton.complex.add, lib_plankton.complex.nul()));
|
|
|
|
|
};
|
|
|
|
|
return {
|
|
|
|
|
"a": mix([[]]),
|
|
|
|
|
"b": mix([[x], [y], [z]]),
|
|
|
|
|
"c": mix([[x, y], [x, z], [y, z]]),
|
|
|
|
|
"d": mix([[x, y, z]]),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
})(math = lib_plankton.math || (lib_plankton.math = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:color«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:color« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:color« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
2024-09-11 17:24:20 +02:00
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:color«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:color«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:color« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:color« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
2024-09-09 21:00:52 +02:00
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:color«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var color;
|
|
|
|
|
(function (color_1) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function make_hsv({ "hue": hue = 0.0, "saturation": saturation = 0.5, "value": value = 0.5 }) {
|
|
|
|
|
const h = lib_plankton.math.clamp(0, 1, hue);
|
|
|
|
|
const s = lib_plankton.math.clamp(0, 1, saturation);
|
|
|
|
|
const v = lib_plankton.math.clamp(0, 1, value);
|
|
|
|
|
const sector = (Math.floor(h * 6) % 6);
|
|
|
|
|
const phase = ((h * 6) - sector);
|
|
|
|
|
const p = (v * (1 - s));
|
|
|
|
|
const q = (v * (1 - (s * phase)));
|
|
|
|
|
const t = (v * (1 - (s * (1 - phase))));
|
|
|
|
|
return make_rgb([
|
|
|
|
|
{ "red": v, "green": t, "blue": p },
|
|
|
|
|
{ "red": q, "green": v, "blue": p },
|
|
|
|
|
{ "red": p, "green": v, "blue": t },
|
|
|
|
|
{ "red": p, "green": q, "blue": v },
|
|
|
|
|
{ "red": t, "green": p, "blue": v },
|
|
|
|
|
{ "red": v, "green": p, "blue": q },
|
|
|
|
|
][sector]);
|
|
|
|
|
}
|
|
|
|
|
color_1.make_hsv = make_hsv;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function make_hsl(model_hsl) {
|
|
|
|
|
const { "hue": h, "saturation": s, "lightness": l } = model_hsl;
|
|
|
|
|
const h_ = h;
|
|
|
|
|
const v = (l + (s * (1 - Math.abs((2 * l) - 1)) / 2));
|
|
|
|
|
const s_ = (2 * (1 - (l / v)));
|
|
|
|
|
return make_hsv({
|
|
|
|
|
"hue": h_,
|
|
|
|
|
"saturation": s_,
|
|
|
|
|
"value": v,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
color_1.make_hsl = make_hsl;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function make_rgb(model_rgb) {
|
|
|
|
|
return {
|
|
|
|
|
"model": {
|
|
|
|
|
"red": lib_plankton.math.clamp(0, 1, model_rgb.red),
|
|
|
|
|
"green": lib_plankton.math.clamp(0, 1, model_rgb.green),
|
|
|
|
|
"blue": lib_plankton.math.clamp(0, 1, model_rgb.blue),
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
color_1.make_rgb = make_rgb;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function to_hsv(color) {
|
|
|
|
|
const { "red": r, "green": g, "blue": b } = color.model;
|
|
|
|
|
const p = Math.min(r, g, b);
|
|
|
|
|
const q = Math.max(r, g, b);
|
|
|
|
|
const c = (q - p);
|
|
|
|
|
let h;
|
|
|
|
|
{
|
|
|
|
|
if (p === q) {
|
|
|
|
|
h = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (q === r) {
|
|
|
|
|
h = ((0 / 3) + ((g - b) / (c * 6)));
|
|
|
|
|
}
|
|
|
|
|
else if (q === g) {
|
|
|
|
|
h = ((1 / 3) + ((b - r) / (c * 6)));
|
|
|
|
|
}
|
|
|
|
|
else if (q === b) {
|
|
|
|
|
h = ((2 / 3) + ((r - g) / (c * 6)));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw (new Error("impossible?"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const s = ((q === 0) ? 0 : c);
|
|
|
|
|
const v = q;
|
|
|
|
|
return {
|
|
|
|
|
"hue": h,
|
|
|
|
|
"saturation": s,
|
|
|
|
|
"value": v,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
color_1.to_hsv = to_hsv;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function to_hsl(color) {
|
|
|
|
|
const { "hue": h, "saturation": s, "value": v } = to_hsv(color);
|
|
|
|
|
const h_ = h;
|
|
|
|
|
const l = (1 / 2 * v * (2 - s));
|
|
|
|
|
const s_ = ((v * s) / (1 - Math.abs((2 * l) - 1)));
|
|
|
|
|
return {
|
|
|
|
|
"hue": h,
|
|
|
|
|
"saturation": s,
|
|
|
|
|
"lightness": l,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
color_1.to_hsl = to_hsl;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function to_rgb(color) {
|
|
|
|
|
return color.model;
|
|
|
|
|
}
|
|
|
|
|
color_1.to_rgb = to_rgb;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function to_cmyk(color) {
|
|
|
|
|
throw (new Error("not implemented"));
|
|
|
|
|
}
|
|
|
|
|
color_1.to_cmyk = to_cmyk;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function add(color1, color2) {
|
|
|
|
|
const rgb1 = to_rgb(color1);
|
|
|
|
|
const rgb2 = to_rgb(color2);
|
|
|
|
|
return make_rgb({
|
|
|
|
|
"red": (rgb1.red + rgb2.red),
|
|
|
|
|
"green": (rgb1.green + rgb2.green),
|
|
|
|
|
"blue": (rgb1.blue + rgb2.blue),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
color_1.add = add;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function multiply(color1, color2) {
|
|
|
|
|
const rgb1 = to_rgb(color1);
|
|
|
|
|
const rgb2 = to_rgb(color2);
|
|
|
|
|
return make_rgb({
|
|
|
|
|
"red": (rgb1.red * rgb2.red),
|
|
|
|
|
"green": (rgb1.green * rgb2.green),
|
|
|
|
|
"blue": (rgb1.blue * rgb2.blue),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
color_1.multiply = multiply;
|
|
|
|
|
/**
|
|
|
|
|
* @todo blend through other model?
|
|
|
|
|
*/
|
|
|
|
|
function blend(color1, color2, strength = 0.5) {
|
|
|
|
|
let rgb1 = to_rgb(color1);
|
|
|
|
|
let rgb2 = to_rgb(color2);
|
|
|
|
|
let t = strength;
|
|
|
|
|
return (make_rgb({
|
|
|
|
|
"red": lib_plankton.math.interpolate_linear(rgb1.red, rgb2.red, t),
|
|
|
|
|
"green": lib_plankton.math.interpolate_linear(rgb1.green, rgb2.green, t),
|
|
|
|
|
"blue": lib_plankton.math.interpolate_linear(rgb1.blue, rgb2.blue, t)
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
color_1.blend = blend;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function mix(color1, color2, { "strength1": option_strength1 = 1, "strength2": option_strength2 = 1, } = {}) {
|
|
|
|
|
return (blend(color1, color2, (option_strength1
|
|
|
|
|
/
|
|
|
|
|
(option_strength1
|
|
|
|
|
+
|
|
|
|
|
option_strength2))));
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
color_1.mix = mix;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function output_rgb(color) {
|
|
|
|
|
const format = (value => Math.round(value * 255).toFixed(0));
|
|
|
|
|
const rgb = to_rgb(color);
|
|
|
|
|
return ("rgb" + "(" + ["red", "green", "blue"].map(key => rgb[key]).map(format).join(",") + ")");
|
|
|
|
|
}
|
|
|
|
|
color_1.output_rgb = output_rgb;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function output_hex(color) {
|
|
|
|
|
const rgb = to_rgb(color);
|
|
|
|
|
const format = function (value) {
|
|
|
|
|
const value_ = Math.round(value * 255);
|
|
|
|
|
// let str : string = lib_plankton.string.pad(value_.toString(16), 2, "0", true);
|
|
|
|
|
let str = value_.toString(16);
|
|
|
|
|
while (str.length < 2)
|
|
|
|
|
str = ("0" + str);
|
|
|
|
|
return str;
|
|
|
|
|
};
|
|
|
|
|
return ("#" + ["red", "green", "blue"].map(key => rgb[key]).map(format).join("") + "");
|
|
|
|
|
}
|
|
|
|
|
color_1.output_hex = output_hex;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function output_dot(color) {
|
2024-09-11 17:24:20 +02:00
|
|
|
|
const hsv = to_hsv(color);
|
2024-09-09 21:00:52 +02:00
|
|
|
|
let format = function (value) {
|
2024-09-11 17:24:20 +02:00
|
|
|
|
return value.toFixed(8);
|
2024-09-09 21:00:52 +02:00
|
|
|
|
};
|
|
|
|
|
return ("" + ["hue", "saturation", "value"].map(key => hsv[key]).map(format).join("+") + "");
|
|
|
|
|
}
|
|
|
|
|
color_1.output_dot = output_dot;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function give_generic(n, { "offset": option_offset = 0, "saturation": option_saturation = undefined, "value": option_value = undefined, }) {
|
|
|
|
|
return make_hsv({
|
|
|
|
|
"hue": (((lib_plankton.math.phi
|
|
|
|
|
*
|
|
|
|
|
n)
|
|
|
|
|
+
|
|
|
|
|
option_offset)
|
|
|
|
|
%
|
|
|
|
|
1),
|
|
|
|
|
"saturation": option_saturation,
|
|
|
|
|
"value": option_value,
|
|
|
|
|
});
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
color_1.give_generic = give_generic;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function give_gray({ "value": option_value = 0.5, }) {
|
|
|
|
|
return make_hsv({ "hue": 0, "saturation": 0, "value": option_value });
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
color_1.give_gray = give_gray;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function give_black() {
|
2024-09-11 17:24:20 +02:00
|
|
|
|
return give_gray({ "value": 0.0 });
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
color_1.give_black = give_black;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function give_white() {
|
2024-09-11 17:24:20 +02:00
|
|
|
|
return give_gray({ "value": 1.0 });
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
color_1.give_white = give_white;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function give_red({ "saturation": option_saturation = undefined, "value": option_value = undefined, } = {}) {
|
|
|
|
|
return make_hsv({
|
|
|
|
|
"hue": (0 / 6),
|
|
|
|
|
"saturation": option_saturation,
|
|
|
|
|
"value": option_value
|
|
|
|
|
});
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
color_1.give_red = give_red;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function give_green({ "saturation": option_saturation = undefined, "value": option_value = undefined, } = {}) {
|
|
|
|
|
return make_hsv({
|
|
|
|
|
"hue": (2 / 6),
|
|
|
|
|
"saturation": option_saturation,
|
|
|
|
|
"value": option_value
|
|
|
|
|
});
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
color_1.give_green = give_green;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function give_blue({ "saturation": option_saturation = undefined, "value": option_value = undefined, } = {}) {
|
|
|
|
|
return make_hsv({
|
|
|
|
|
"hue": (4 / 6),
|
|
|
|
|
"saturation": option_saturation,
|
|
|
|
|
"value": option_value
|
|
|
|
|
});
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
color_1.give_blue = give_blue;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function give_yellow({ "saturation": option_saturation = undefined, "value": option_value = undefined, } = {}) {
|
|
|
|
|
return make_hsv({
|
|
|
|
|
"hue": (1 / 6),
|
|
|
|
|
"saturation": option_saturation,
|
|
|
|
|
"value": option_value
|
|
|
|
|
});
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
color_1.give_yellow = give_yellow;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function give_cyan({ "saturation": option_saturation = undefined, "value": option_value = undefined, } = {}) {
|
|
|
|
|
return make_hsv({
|
|
|
|
|
"hue": (3 / 6),
|
|
|
|
|
"saturation": option_saturation,
|
|
|
|
|
"value": option_value
|
|
|
|
|
});
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
color_1.give_cyan = give_cyan;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
2024-09-11 17:24:20 +02:00
|
|
|
|
function give_magenta({ "saturation": option_saturation = undefined, "value": option_value = undefined, } = {}) {
|
|
|
|
|
return make_hsv({
|
|
|
|
|
"hue": (5 / 6),
|
|
|
|
|
"saturation": option_saturation,
|
|
|
|
|
"value": option_value
|
|
|
|
|
});
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
color_1.give_magenta = give_magenta;
|
|
|
|
|
})(color = lib_plankton.color || (lib_plankton.color = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:color«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:color« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:color« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:color«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var color;
|
|
|
|
|
(function (color_2) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_color {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor(subject) {
|
|
|
|
|
this.subject = subject;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static _cram(subject) {
|
|
|
|
|
return (new class_color(subject));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static _tear(instance) {
|
|
|
|
|
return (instance.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static make_hsv({ "hue": hue = undefined, "saturation": saturation = undefined, "value": value = undefined }) {
|
|
|
|
|
return (class_color._cram(color_2.make_hsv({
|
|
|
|
|
"hue": hue,
|
|
|
|
|
"saturation": saturation,
|
|
|
|
|
"value": value
|
|
|
|
|
})));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
blend(color, strength = 0.5) {
|
|
|
|
|
return (class_color._cram(color_2.blend(class_color._tear(this), class_color._tear(color), strength)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
output_rgb() {
|
|
|
|
|
return (color_2.output_rgb(class_color._tear(this)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
output_hex() {
|
|
|
|
|
return (color_2.output_hex(class_color._tear(this)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
output_dot() {
|
|
|
|
|
return (color_2.output_dot(class_color._tear(this)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static give_generic({ "n": n, "offset": offset = undefined, "saturation": saturation = undefined, "value": value = undefined, }) {
|
2024-09-11 17:24:20 +02:00
|
|
|
|
return (class_color._cram(color_2.give_generic(n, {
|
2024-09-09 21:00:52 +02:00
|
|
|
|
"offset": offset,
|
|
|
|
|
"saturation": saturation,
|
|
|
|
|
"value": value,
|
|
|
|
|
})));
|
|
|
|
|
}
|
|
|
|
|
static generic(x) { return class_color.give_generic(x); }
|
|
|
|
|
;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static give_gray(value = 0.5) {
|
2024-09-11 17:24:20 +02:00
|
|
|
|
return (class_color._cram(color_2.give_gray({ "value": value })));
|
2024-09-09 21:00:52 +02:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static give_black() {
|
|
|
|
|
return (class_color._cram(color_2.give_black()));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static give_white() {
|
|
|
|
|
return (class_color._cram(color_2.give_white()));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static give_red({ "saturation": saturation = undefined, "value": value = undefined, } = {}) {
|
|
|
|
|
return (class_color._cram(color_2.give_red({
|
|
|
|
|
"saturation": saturation,
|
|
|
|
|
"value": value,
|
|
|
|
|
})));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static give_green({ "saturation": saturation = undefined, "value": value = undefined, } = {}) {
|
|
|
|
|
return (class_color._cram(color_2.give_green({
|
|
|
|
|
"saturation": saturation,
|
|
|
|
|
"value": value,
|
|
|
|
|
})));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static give_blue({ "saturation": saturation = undefined, "value": value = undefined, } = {}) {
|
|
|
|
|
return (class_color._cram(color_2.give_blue({
|
|
|
|
|
"saturation": saturation,
|
|
|
|
|
"value": value,
|
|
|
|
|
})));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static give_yellow({ "saturation": saturation = undefined, "value": value = undefined, } = {}) {
|
|
|
|
|
return (class_color._cram(color_2.give_yellow({
|
|
|
|
|
"saturation": saturation,
|
|
|
|
|
"value": value,
|
|
|
|
|
})));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static give_cyan({ "saturation": saturation = undefined, "value": value = undefined, } = {}) {
|
|
|
|
|
return (class_color._cram(color_2.give_cyan({
|
|
|
|
|
"saturation": saturation,
|
|
|
|
|
"value": value,
|
|
|
|
|
})));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static give_magenta({ "saturation": saturation = undefined, "value": value = undefined, } = {}) {
|
|
|
|
|
return (class_color._cram(color_2.give_magenta({
|
|
|
|
|
"saturation": saturation,
|
|
|
|
|
"value": value,
|
|
|
|
|
})));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
color_2.class_color = class_color;
|
|
|
|
|
})(color = lib_plankton.color || (lib_plankton.color = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
var __extends = (this && this.__extends) || (function () {
|
|
|
|
|
var extendStatics = function (d, b) {
|
|
|
|
|
extendStatics = Object.setPrototypeOf ||
|
|
|
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
|
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
|
|
|
return extendStatics(d, b);
|
|
|
|
|
};
|
|
|
|
|
return function (d, b) {
|
|
|
|
|
if (typeof b !== "function" && b !== null)
|
|
|
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
|
|
|
extendStatics(d, b);
|
|
|
|
|
function __() { this.constructor = d; }
|
|
|
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
|
|
|
};
|
|
|
|
|
})();
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:xml«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:xml« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:xml« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:xml«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var xml;
|
|
|
|
|
(function (xml) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function string_repeat(symbol, count) {
|
|
|
|
|
return ((count <= 0) ? "" : (string_repeat(symbol, count - 1) + symbol));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var class_node = /** @class */ (function () {
|
|
|
|
|
function class_node() {
|
|
|
|
|
}
|
|
|
|
|
return class_node;
|
|
|
|
|
}());
|
|
|
|
|
xml.class_node = class_node;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var class_node_text = /** @class */ (function (_super) {
|
|
|
|
|
__extends(class_node_text, _super);
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function class_node_text(content) {
|
|
|
|
|
var _this = _super.call(this) || this;
|
|
|
|
|
_this.content = content;
|
|
|
|
|
return _this;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_node_text.prototype.compile = function (depth) {
|
|
|
|
|
if (depth === void 0) { depth = 0; }
|
|
|
|
|
return (string_repeat("\t", depth) + this.content + "\n");
|
|
|
|
|
};
|
|
|
|
|
return class_node_text;
|
|
|
|
|
}(class_node));
|
|
|
|
|
xml.class_node_text = class_node_text;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var class_node_comment = /** @class */ (function (_super) {
|
|
|
|
|
__extends(class_node_comment, _super);
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function class_node_comment(content) {
|
|
|
|
|
var _this = _super.call(this) || this;
|
|
|
|
|
_this.content = content;
|
|
|
|
|
return _this;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_node_comment.prototype.compile = function (depth) {
|
|
|
|
|
if (depth === void 0) { depth = 0; }
|
|
|
|
|
return (string_repeat("\t", depth) + "<!-- " + this.content + " -->" + "\n");
|
|
|
|
|
};
|
|
|
|
|
return class_node_comment;
|
|
|
|
|
}(class_node));
|
|
|
|
|
xml.class_node_comment = class_node_comment;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
var class_node_complex = /** @class */ (function (_super) {
|
|
|
|
|
__extends(class_node_complex, _super);
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function class_node_complex(name, attributes, children) {
|
|
|
|
|
if (attributes === void 0) { attributes = {}; }
|
|
|
|
|
if (children === void 0) { children = []; }
|
|
|
|
|
var _this = _super.call(this) || this;
|
|
|
|
|
_this.name = name;
|
|
|
|
|
_this.attributes = attributes;
|
|
|
|
|
_this.children = children;
|
|
|
|
|
return _this;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class_node_complex.prototype.compile = function (depth) {
|
|
|
|
|
var _this = this;
|
|
|
|
|
if (depth === void 0) { depth = 0; }
|
|
|
|
|
var output = "";
|
|
|
|
|
var attributes = (Object.keys(this.attributes)
|
|
|
|
|
.filter(function (key) { return (_this.attributes[key] !== null); })
|
|
|
|
|
.map(function (key) { return (" " + key + "=" + ("\"" + _this.attributes[key] + "\"")); })
|
|
|
|
|
.join(""));
|
|
|
|
|
output += (string_repeat("\t", depth) + "<" + this.name + attributes + ">" + "\n");
|
|
|
|
|
this.children.forEach(function (child) { return (output += child.compile(depth + 1)); });
|
|
|
|
|
output += (string_repeat("\t", depth) + "</" + this.name + ">" + "\n");
|
|
|
|
|
return output;
|
|
|
|
|
};
|
|
|
|
|
return class_node_complex;
|
|
|
|
|
}(class_node));
|
|
|
|
|
xml.class_node_complex = class_node_complex;
|
|
|
|
|
})(xml = lib_plankton.xml || (lib_plankton.xml = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
2024-09-10 01:11:51 +02:00
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:date«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:date« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:date« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:date«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_et;
|
|
|
|
|
(function (lib_et) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function div(x, y) {
|
|
|
|
|
return Math.floor(x / y);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function mod(x, y) {
|
|
|
|
|
return (x - (y * div(x, y)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function json_encode(obj) {
|
|
|
|
|
return JSON.stringify(obj);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc the maximum of a regular UNIX-timestamp: 2^31-1; one second is cut
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
const _modulus = 0x7FFFFFFF;
|
|
|
|
|
/**
|
|
|
|
|
* @desc add (e1,s1) (e2,s2) = (e1+e2+((s1+s2) div m),(s1+s2) mod m)
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function add(et1, et2) {
|
|
|
|
|
let era = (et1.era + et2.era + div(et1.stamp + et2.stamp, _modulus));
|
|
|
|
|
let stamp = mod(et1.stamp + et2.stamp, _modulus);
|
|
|
|
|
return { "era": era, "stamp": stamp };
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc neutral = (0,0)
|
|
|
|
|
*/
|
|
|
|
|
function neutral() {
|
|
|
|
|
return { "era": 0, "stamp": 0 };
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc invert (e,s) = (-1-e,m-s)
|
|
|
|
|
*/
|
|
|
|
|
function invert(et) {
|
|
|
|
|
let era = (-1 - et.era);
|
|
|
|
|
let stamp = (_modulus - et.stamp);
|
|
|
|
|
return { "era": era, "stamp": stamp };
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function part(et1, et2) {
|
|
|
|
|
return add(et1, invert(et2));
|
|
|
|
|
}
|
|
|
|
|
lib_et.part = part;
|
|
|
|
|
/**
|
|
|
|
|
* @desc less
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function before(reference, et) {
|
|
|
|
|
let et_ = part(et, reference);
|
|
|
|
|
return ((et_.era >= 0) && (et_.stamp > 0));
|
|
|
|
|
}
|
|
|
|
|
lib_et.before = before;
|
|
|
|
|
/**
|
|
|
|
|
* @desc greater
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function after(reference, et) {
|
|
|
|
|
let et_ = part(reference, et);
|
|
|
|
|
return ((et_.era >= 0) && (et_.stamp > 0));
|
|
|
|
|
}
|
|
|
|
|
lib_et.after = after;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function between(begin, end, et) {
|
|
|
|
|
return (before(begin, et)
|
|
|
|
|
&&
|
|
|
|
|
after(end, et));
|
|
|
|
|
}
|
|
|
|
|
lib_et.between = between;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function intersect(begin1, end1, begin2, end2) {
|
|
|
|
|
return ((between(begin1, end1, begin2)
|
|
|
|
|
||
|
|
|
|
|
between(begin1, end1, end2))
|
|
|
|
|
||
|
|
|
|
|
(between(begin2, end2, begin1)
|
|
|
|
|
||
|
|
|
|
|
between(begin2, end2, end1)));
|
|
|
|
|
}
|
|
|
|
|
lib_et.intersect = intersect;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function move(base, span) {
|
|
|
|
|
return add(base, span);
|
|
|
|
|
}
|
|
|
|
|
lib_et.move = move;
|
|
|
|
|
/**
|
|
|
|
|
* @desc currified version of "move"
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function move_(span) {
|
|
|
|
|
return (base => move(base, span));
|
|
|
|
|
}
|
|
|
|
|
lib_et.move_ = move_;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function from_timestamp(timestamp) {
|
|
|
|
|
let era = div(timestamp, _modulus);
|
|
|
|
|
let stamp = mod(timestamp, _modulus);
|
|
|
|
|
let et = { "era": era, "stamp": stamp };
|
|
|
|
|
return et;
|
|
|
|
|
}
|
|
|
|
|
lib_et.from_timestamp = from_timestamp;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function to_timestamp(et) {
|
|
|
|
|
if (et.era != 0) {
|
|
|
|
|
const message = "case (era <> 0) not properly implemented";
|
|
|
|
|
console.warn(message + "; well ... i'll do my very best ...");
|
|
|
|
|
// throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
let timestamp = ((et.era * _modulus) + et.stamp);
|
|
|
|
|
return timestamp;
|
|
|
|
|
}
|
|
|
|
|
lib_et.to_timestamp = to_timestamp;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function from_jsdate(jsdate) {
|
|
|
|
|
const timestamp = Math.floor(jsdate.getTime() / 1000);
|
|
|
|
|
const et = from_timestamp(timestamp);
|
|
|
|
|
return et;
|
|
|
|
|
}
|
|
|
|
|
lib_et.from_jsdate = from_jsdate;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function to_jsdate(et) {
|
|
|
|
|
const timestamp = to_timestamp(et);
|
|
|
|
|
const jsdate = (new Date(timestamp * 1000));
|
|
|
|
|
return jsdate;
|
|
|
|
|
}
|
|
|
|
|
lib_et.to_jsdate = to_jsdate;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function from_components(components) {
|
|
|
|
|
const timestamp = Math.floor(Date.UTC((components.year), (components.month - 1), (components.day), (components.hour || 0), (components.minute || 0), (components.second || 0))
|
|
|
|
|
/
|
|
|
|
|
1000);
|
|
|
|
|
const et = from_timestamp(timestamp);
|
|
|
|
|
return et;
|
|
|
|
|
}
|
|
|
|
|
lib_et.from_components = from_components;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function to_components(et) {
|
|
|
|
|
const jsdate = to_jsdate(et);
|
|
|
|
|
const components = {
|
|
|
|
|
"year": jsdate.getUTCFullYear(),
|
|
|
|
|
"month": jsdate.getUTCMonth() + 1,
|
|
|
|
|
"day": jsdate.getUTCDate(),
|
|
|
|
|
"hour": jsdate.getUTCHours(),
|
|
|
|
|
"minute": jsdate.getUTCMinutes(),
|
|
|
|
|
"second": jsdate.getUTCSeconds(),
|
|
|
|
|
};
|
|
|
|
|
return components;
|
|
|
|
|
}
|
|
|
|
|
lib_et.to_components = to_components;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function now() {
|
|
|
|
|
let timestamp = Math.floor(Date.now() / 1000);
|
|
|
|
|
let et = from_timestamp(timestamp);
|
|
|
|
|
return et;
|
|
|
|
|
}
|
|
|
|
|
lib_et.now = now;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function to_string(et) {
|
|
|
|
|
// return (json_encode(et) + " ~ " + json_encode(to_components(et)));
|
|
|
|
|
return to_jsdate(et).toUTCString();
|
|
|
|
|
}
|
|
|
|
|
lib_et.to_string = to_string;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function to_string_ywd(et) {
|
|
|
|
|
// return (json_encode(et) + " ~ " + json_encode(to_components(et)));
|
|
|
|
|
return to_jsdate(et).toUTCString();
|
|
|
|
|
}
|
|
|
|
|
lib_et.to_string_ywd = to_string_ywd;
|
|
|
|
|
/**
|
|
|
|
|
* @desc retrieve week of year
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function get_woy(et) {
|
|
|
|
|
let jsdate = to_jsdate(et);
|
|
|
|
|
let begin_of_year = new Date(jsdate.getFullYear(), 0, 1, 12, 0, 0);
|
|
|
|
|
let day_of_week = begin_of_year.getDay();
|
|
|
|
|
let overhang = (day_of_week >= 4);
|
|
|
|
|
let factor = (1000 * 60 * 60 * 24);
|
|
|
|
|
let days = ((jsdate.getTime() - begin_of_year.getTime()) / factor);
|
|
|
|
|
let week = (Math.ceil((days + day_of_week) / 7) - (overhang ? 1 : 0));
|
|
|
|
|
return week;
|
|
|
|
|
}
|
|
|
|
|
lib_et.get_woy = get_woy;
|
|
|
|
|
/**
|
|
|
|
|
* @desc retrieve day of week
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function get_dow(et) {
|
|
|
|
|
let jsdate = to_jsdate(et);
|
|
|
|
|
let dow = (mod(jsdate.getDay() - 1, 7) + 1);
|
|
|
|
|
return dow;
|
|
|
|
|
}
|
|
|
|
|
lib_et.get_dow = get_dow;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function trunc_minute(et = now()) {
|
|
|
|
|
let components = to_components(et);
|
|
|
|
|
let components_ = {
|
|
|
|
|
"year": components.year,
|
|
|
|
|
"month": components.month,
|
|
|
|
|
"day": components.day,
|
|
|
|
|
"hour": components.hour,
|
|
|
|
|
"minute": components.minute,
|
|
|
|
|
"second": 0
|
|
|
|
|
};
|
|
|
|
|
let et_ = from_components(components_);
|
|
|
|
|
return et_;
|
|
|
|
|
}
|
|
|
|
|
lib_et.trunc_minute = trunc_minute;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function trunc_hour(et = now()) {
|
|
|
|
|
let components = to_components(et);
|
|
|
|
|
let components_ = {
|
|
|
|
|
"year": components.year,
|
|
|
|
|
"month": components.month,
|
|
|
|
|
"day": components.day,
|
|
|
|
|
"hour": components.hour,
|
|
|
|
|
"minute": 0,
|
|
|
|
|
"second": 0
|
|
|
|
|
};
|
|
|
|
|
let et_ = from_components(components_);
|
|
|
|
|
return et_;
|
|
|
|
|
}
|
|
|
|
|
lib_et.trunc_hour = trunc_hour;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function trunc_day(et = now()) {
|
|
|
|
|
let components = to_components(et);
|
|
|
|
|
let components_ = {
|
|
|
|
|
"year": components.year,
|
|
|
|
|
"month": components.month,
|
|
|
|
|
"day": components.day,
|
|
|
|
|
"hour": 0,
|
|
|
|
|
"minute": 0,
|
|
|
|
|
"second": 0
|
|
|
|
|
};
|
|
|
|
|
let et_ = from_components(components_);
|
|
|
|
|
return et_;
|
|
|
|
|
}
|
|
|
|
|
lib_et.trunc_day = trunc_day;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function trunc_month(et = now()) {
|
|
|
|
|
let components = to_components(et);
|
|
|
|
|
let components_ = {
|
|
|
|
|
"year": components.year,
|
|
|
|
|
"month": components.month,
|
|
|
|
|
"day": 0,
|
|
|
|
|
"hour": 0,
|
|
|
|
|
"minute": 0,
|
|
|
|
|
"second": 0
|
|
|
|
|
};
|
|
|
|
|
let et_ = from_components(components_);
|
|
|
|
|
return et_;
|
|
|
|
|
}
|
|
|
|
|
lib_et.trunc_month = trunc_month;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function trunc_year(et = now()) {
|
|
|
|
|
let components = to_components(et);
|
|
|
|
|
let components_ = {
|
|
|
|
|
"year": components.year,
|
|
|
|
|
"month": 0,
|
|
|
|
|
"day": 0,
|
|
|
|
|
"hour": 0,
|
|
|
|
|
"minute": 0,
|
|
|
|
|
"second": 0
|
|
|
|
|
};
|
|
|
|
|
let et_ = from_components(components_);
|
|
|
|
|
return et_;
|
|
|
|
|
}
|
|
|
|
|
lib_et.trunc_year = trunc_year;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function trunc_week(et = now()) {
|
|
|
|
|
let et_ = trunc_day(et);
|
|
|
|
|
while (to_jsdate(et_).getDay() > 1) {
|
|
|
|
|
et_ = add(et_, span_day(-1));
|
|
|
|
|
}
|
|
|
|
|
return et_;
|
|
|
|
|
}
|
|
|
|
|
lib_et.trunc_week = trunc_week;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function span_second(seconds = 1) {
|
|
|
|
|
return from_timestamp(seconds);
|
|
|
|
|
}
|
|
|
|
|
lib_et.span_second = span_second;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function span_minute(minutes = 1) {
|
|
|
|
|
return span_second(minutes * 60);
|
|
|
|
|
}
|
|
|
|
|
lib_et.span_minute = span_minute;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function span_hour(hours = 1) {
|
|
|
|
|
return span_minute(hours * 60);
|
|
|
|
|
}
|
|
|
|
|
lib_et.span_hour = span_hour;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function span_day(days = 1) {
|
|
|
|
|
return span_hour(days * 24);
|
|
|
|
|
}
|
|
|
|
|
lib_et.span_day = span_day;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function span_week(weeks = 1) {
|
|
|
|
|
return span_day(weeks * 7);
|
|
|
|
|
}
|
|
|
|
|
lib_et.span_week = span_week;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function span_year(years = 1) {
|
|
|
|
|
return span_second(Math.floor(years * 365.25 * 24 * 60 * 60));
|
|
|
|
|
}
|
|
|
|
|
lib_et.span_year = span_year;
|
|
|
|
|
})(lib_et || (lib_et = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:date«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:date« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:date« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:date«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_et;
|
|
|
|
|
(function (lib_et) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_et {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor(subject) {
|
|
|
|
|
this.subject = subject;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
move(et) {
|
|
|
|
|
return (new class_et(lib_et.move(this.subject, et.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
before(et) {
|
|
|
|
|
return lib_et.before(et.subject, this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
after(et) {
|
|
|
|
|
return lib_et.after(et.subject, this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
between(et1, et2) {
|
|
|
|
|
return lib_et.between(et1.subject, et2.subject, this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
trunc_minute() {
|
|
|
|
|
return (new class_et(lib_et.trunc_minute(this.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
trunc_hour() {
|
|
|
|
|
return (new class_et(lib_et.trunc_hour(this.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
trunc_day() {
|
|
|
|
|
return (new class_et(lib_et.trunc_day(this.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
trunc_month() {
|
|
|
|
|
return (new class_et(lib_et.trunc_month(this.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
trunc_year() {
|
|
|
|
|
return (new class_et(lib_et.trunc_year(this.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
trunc_week() {
|
|
|
|
|
return (new class_et(lib_et.trunc_week(this.subject)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static now() {
|
|
|
|
|
return (new class_et(lib_et.now()));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static span_second(count = 1) {
|
|
|
|
|
return (new class_et(lib_et.span_second(count)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static span_minute(count = 1) {
|
|
|
|
|
return (new class_et(lib_et.span_minute(count)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static span_hour(count = 1) {
|
|
|
|
|
return (new class_et(lib_et.span_hour(count)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static span_day(count = 1) {
|
|
|
|
|
return (new class_et(lib_et.span_day(count)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static span_week(count = 1) {
|
|
|
|
|
return (new class_et(lib_et.span_week(count)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static span_year(count = 1) {
|
|
|
|
|
return (new class_et(lib_et.span_year(count)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static from_timestamp(timestamp) {
|
|
|
|
|
return (new class_et(lib_et.from_timestamp(timestamp)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
to_timestamp() {
|
|
|
|
|
return lib_et.to_timestamp(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static from_jsdate(jsdate) {
|
|
|
|
|
return (new class_et(lib_et.from_jsdate(jsdate)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
to_jsdate() {
|
|
|
|
|
return lib_et.to_jsdate(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
static from_components(components) {
|
|
|
|
|
return (new class_et(lib_et.from_components(components)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
to_components() {
|
|
|
|
|
return lib_et.to_components(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
get_woy() {
|
|
|
|
|
return lib_et.get_woy(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
get_dow() {
|
|
|
|
|
return lib_et.get_dow(this.subject);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
to_string() {
|
|
|
|
|
return lib_et.to_string(this.subject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lib_et.class_et = class_et;
|
|
|
|
|
})(lib_et || (lib_et = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:date«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:date« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:date« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:date«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @author neuc
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var date;
|
|
|
|
|
(function (date_1) {
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
var _days = [
|
|
|
|
|
"Sunday",
|
|
|
|
|
"Monday",
|
|
|
|
|
"Tuesday",
|
|
|
|
|
"Wednesday",
|
|
|
|
|
"Thursday",
|
|
|
|
|
"Friday",
|
|
|
|
|
"Saturday"
|
|
|
|
|
];
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
var _months = [
|
|
|
|
|
"January",
|
|
|
|
|
"February",
|
|
|
|
|
"March",
|
|
|
|
|
"April",
|
|
|
|
|
"May",
|
|
|
|
|
"June",
|
|
|
|
|
"July",
|
|
|
|
|
"August",
|
|
|
|
|
"September",
|
|
|
|
|
"October",
|
|
|
|
|
"November",
|
|
|
|
|
"December"
|
|
|
|
|
];
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
var _segments = {
|
|
|
|
|
"%a": (date => _days[date.getDay()].slice(0, 3)),
|
|
|
|
|
"%A": (date => _days[date.getDay()]),
|
|
|
|
|
"%b": (date => _days[date.getMonth()].slice(0, 3)),
|
|
|
|
|
"%B": (date => _days[date.getMonth()]),
|
|
|
|
|
"%c": (date => date.toLocaleString()),
|
|
|
|
|
"%C": (date => Math.floor((date.getFullYear()) / 100).toString()),
|
|
|
|
|
"%d": (date => lib_plankton.string.sprintf("%02d", [date.getDate()])),
|
|
|
|
|
"%D": (date => parse("%m/%d/%y", date)),
|
|
|
|
|
"%e": (date => lib_plankton.string.sprintf("%2d", [date.getDate()])),
|
|
|
|
|
"%F": (date => parse("%Y-%m-%d", date)),
|
|
|
|
|
"%g": (date => lib_plankton.string.sprintf("%02d", [date.getFullYear() % 1000])),
|
|
|
|
|
"%G": (date => date.getFullYear().toString()),
|
|
|
|
|
"%h": (date => parse("%b", date)),
|
|
|
|
|
"%H": (date => lib_plankton.string.sprintf("%02d", [date.getHours()])),
|
|
|
|
|
"%I": (date => lib_plankton.string.sprintf("%02d", [((date.getHours() > 12) ? (date.getHours() - 12) : date.getHours())])),
|
|
|
|
|
"%j": (date => lib_plankton.string.sprintf("%03d", [helper_dayOfYear(date)])),
|
|
|
|
|
"%m": (date => lib_plankton.string.sprintf("%02d", [date.getMonth() + 1])),
|
|
|
|
|
"%M": (date => lib_plankton.string.sprintf("%02d", [date.getMinutes()])),
|
|
|
|
|
"%n": (date => "\n"),
|
|
|
|
|
"%p": (date => ((date.getHours() > 12) ? "PM" : "AM")),
|
|
|
|
|
"%r": (date => parse("%I:%M:%S %p", date)),
|
|
|
|
|
"%R": (date => parse("%H:%M", date)),
|
|
|
|
|
"%S": (date => date.getSeconds().toString()),
|
|
|
|
|
"%t": (date => "\t"),
|
|
|
|
|
"%T": (date => parse("%H:%M:%S", date)),
|
|
|
|
|
"%u": (date => lib_plankton.string.sprintf("%02d", [((date.getDay() === 0) ? 7 : date.getDay())])),
|
|
|
|
|
"%U": (date => lib_plankton.string.sprintf("%02d", [helper_englishWeekOfYear(date)])),
|
|
|
|
|
"%V": (date => lib_plankton.string.sprintf("%02d", [helper_weekOfYear(date)])),
|
|
|
|
|
"%w": (date => lib_plankton.string.sprintf("%02d", [date.getDay().toString()])),
|
|
|
|
|
"%W": (date => parse("%w", date)),
|
|
|
|
|
"%x": (date => parse("%m/%d/%G", date)),
|
|
|
|
|
"%X": (date => parse("%T", date)),
|
|
|
|
|
"%y": (date => parse("%g", date)),
|
|
|
|
|
"%Y": (date => parse("%G", date)),
|
|
|
|
|
"%z": (date => date.getTimezoneOffset().toString()),
|
|
|
|
|
"%Z": (date => date.toUTCString().split(' ').pop()),
|
|
|
|
|
"%%": (date => "%"),
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
var _currentDate = (new Date(Date.now()));
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_days(day_names) {
|
|
|
|
|
_days = day_names;
|
|
|
|
|
}
|
|
|
|
|
date_1.set_days = set_days;
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_months(month_names) {
|
|
|
|
|
_months = month_names;
|
|
|
|
|
}
|
|
|
|
|
date_1.set_months = set_months;
|
|
|
|
|
/**
|
|
|
|
|
* @desc source: https://stackoverflow.com/questions/8619879/javascript-calculate-the-day-of-the-year-1-366
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
function helper_dayOfYear(date) {
|
|
|
|
|
let start = new Date(date.getFullYear(), 0, 0);
|
|
|
|
|
let diff = (date.getTime() - start.getTime());
|
|
|
|
|
let oneDay = (1000 * 60 * 60 * 24);
|
|
|
|
|
return Math.floor(diff / oneDay);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc source: http://weeknumber.net/how-to/javascript
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
function helper_weekOfYear(date_) {
|
|
|
|
|
let date = new Date(date_.getTime());
|
|
|
|
|
date.setHours(0, 0, 0, 0);
|
|
|
|
|
// Thursday in current week decides the year.
|
|
|
|
|
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
|
|
|
|
|
// January 4 is always in week 1.
|
|
|
|
|
let week1 = new Date(date.getFullYear(), 0, 4);
|
|
|
|
|
// Adjust to Thursday in week 1 and count number of weeks from date to week1.
|
|
|
|
|
return (1
|
|
|
|
|
+
|
|
|
|
|
Math.round((((date.getTime() - week1.getTime()) / 86400000)
|
|
|
|
|
-
|
|
|
|
|
3
|
|
|
|
|
+
|
|
|
|
|
(week1.getDay() + 6) % 7)
|
|
|
|
|
/
|
|
|
|
|
7));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
function helper_englishWeekOfYear(date) {
|
|
|
|
|
let nr = helper_weekOfYear(date);
|
|
|
|
|
if (date.getDay() === 0) {
|
|
|
|
|
nr = nr - 1;
|
|
|
|
|
}
|
|
|
|
|
return nr;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @desc week of year
|
|
|
|
|
* @param {Date} date
|
|
|
|
|
* @return {int}
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function get_week(date) {
|
|
|
|
|
let begin_of_year = new Date(date.getFullYear(), 0, 1, 12, 0, 0);
|
|
|
|
|
let day_of_week = begin_of_year.getDay();
|
|
|
|
|
let overhang = (day_of_week >= 4);
|
|
|
|
|
let factor = (1000 * 60 * 60 * 24);
|
|
|
|
|
let days = ((date.getTime() - begin_of_year.getTime()) / factor);
|
|
|
|
|
let week = (Math.ceil((days + day_of_week) / 7) - (overhang ? 1 : 0));
|
|
|
|
|
return week;
|
|
|
|
|
}
|
|
|
|
|
date_1.get_week = get_week;
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
function set_currentDate(date) {
|
|
|
|
|
_currentDate = date;
|
|
|
|
|
}
|
|
|
|
|
date_1.set_currentDate = set_currentDate;
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
function parse(format, date = _currentDate) {
|
|
|
|
|
let ret = format;
|
|
|
|
|
let re = new RegExp("%[a-z]", "gi");
|
|
|
|
|
let match;
|
|
|
|
|
while (match = re.exec(format)) {
|
|
|
|
|
ret = ret.replace(match[0], parse_segment(match[0], date));
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
date_1.parse = parse;
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
function parse_segment(segment, date = _currentDate) {
|
|
|
|
|
if (!(segment in _segments)) {
|
|
|
|
|
let message = ("unknown format argument '" + segment + "'");
|
|
|
|
|
throw (new Error(message));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return _segments[segment](date);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author neu3no, fenris
|
|
|
|
|
*/
|
|
|
|
|
function locale_date(date = new Date(), ignore_error = false) {
|
|
|
|
|
if (!(date instanceof Date)) {
|
|
|
|
|
if (!ignore_error) {
|
|
|
|
|
throw new SyntaxError("date must be instance of Date");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.warn("'" + date + "' seems not to be instance of Date; try to force convert.");
|
|
|
|
|
let tmp = date;
|
|
|
|
|
date = new Date(tmp);
|
|
|
|
|
if ((date.toString() === "Invalid Date")
|
|
|
|
|
||
|
|
|
|
|
(!(date < new Date(0)) && !(date > new Date(0)))) {
|
|
|
|
|
console.warn("conversion didn't work, returning default value");
|
|
|
|
|
return "Ø";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let conf = (
|
|
|
|
|
/*
|
|
|
|
|
global_config.get_value("date")
|
|
|
|
|
||
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
"use_locale_date": true,
|
|
|
|
|
"format_string": "%d.%m.%Y"
|
|
|
|
|
});
|
|
|
|
|
if (conf.use_locale_date) {
|
|
|
|
|
return date.toLocaleDateString();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return strftime.parse(conf.format_string, date);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
date_1.locale_date = locale_date;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function now() {
|
|
|
|
|
return Math.floor(Date.now() / 1000);
|
|
|
|
|
}
|
|
|
|
|
date_1.now = now;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function from_components(components) {
|
|
|
|
|
return Math.floor(new Date(Date.parse(lib_string.coin("{{year}}-{{month}}-{{day}}T{{hour}}:{{minute}}:{{second}}.{{milliseconds}}{{timezone_offset}}", {
|
|
|
|
|
"year": components.year.toFixed(0).padStart(4, "0"),
|
|
|
|
|
"month": components.month.toFixed(0).padStart(2, "0"),
|
|
|
|
|
"day": components.day.toFixed(0).padStart(2, "0"),
|
|
|
|
|
"hour": components.hour.toFixed(0).padStart(2, "0"),
|
|
|
|
|
"minute": components.minute.toFixed(0).padStart(2, "0"),
|
|
|
|
|
"second": components.second.toFixed(0).padStart(2, "0"),
|
|
|
|
|
"milliseconds": (0).toFixed(0).padStart(3, "0"),
|
|
|
|
|
"timezone_offset": lib_string.coin("{{sign}}{{amount}}:00", {
|
|
|
|
|
"sign": ((components.timezone_offset < 0) ? "-" : "+"),
|
|
|
|
|
"amount": Math.abs(components.timezone_offset).toFixed(0).padStart(2, "0"),
|
|
|
|
|
}),
|
|
|
|
|
}))).getTime()
|
|
|
|
|
/
|
|
|
|
|
1000);
|
|
|
|
|
}
|
|
|
|
|
date_1.from_components = from_components;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function to_components(unixtimestamp) {
|
|
|
|
|
const date_object = new Date(unixtimestamp * 1000);
|
|
|
|
|
const date_string = date_object.toISOString();
|
|
|
|
|
return {
|
|
|
|
|
"timezone_offset": 0,
|
|
|
|
|
"year": parseInt(date_string.slice(0, 4)),
|
|
|
|
|
"month": parseInt(date_string.slice(5, 7)),
|
|
|
|
|
"day": parseInt(date_string.slice(8, 10)),
|
|
|
|
|
"hour": parseInt(date_string.slice(11, 13)),
|
|
|
|
|
"minute": parseInt(date_string.slice(14, 16)),
|
|
|
|
|
"second": parseInt(date_string.slice(17, 19)),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
date_1.to_components = to_components;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function get_timestamp_from_year_and_week_and_day(year, week, day) {
|
|
|
|
|
const d = (1 + ((week - 1) * 7));
|
|
|
|
|
const date_raw = new Date(year, 0, d);
|
|
|
|
|
return (Math.round(date_raw.getTime() / 1000)
|
|
|
|
|
+
|
|
|
|
|
(60 * 60 * 24 * (day - date_raw.getDay() + 1)));
|
|
|
|
|
}
|
|
|
|
|
date_1.get_timestamp_from_year_and_week_and_day = get_timestamp_from_year_and_week_and_day;
|
|
|
|
|
})(date = lib_plankton.date || (lib_plankton.date = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
var strftime = lib_plankton.date;
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:ical«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:ical« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:ical« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:ical«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var ical;
|
|
|
|
|
(function (ical) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
// type type_timestamp = string;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
let enum_class;
|
|
|
|
|
(function (enum_class) {
|
|
|
|
|
enum_class["public"] = "public";
|
|
|
|
|
enum_class["private"] = "private";
|
|
|
|
|
enum_class["confidential"] = "confidential";
|
|
|
|
|
})(enum_class = ical.enum_class || (ical.enum_class = {}));
|
|
|
|
|
;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
let enum_event_status;
|
|
|
|
|
(function (enum_event_status) {
|
|
|
|
|
enum_event_status["tentative"] = "tentative";
|
|
|
|
|
enum_event_status["confirmed"] = "confirmed";
|
|
|
|
|
enum_event_status["cancelled"] = "cancelled";
|
|
|
|
|
})(enum_event_status = ical.enum_event_status || (ical.enum_event_status = {}));
|
|
|
|
|
;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
let enum_transp;
|
|
|
|
|
(function (enum_transp) {
|
|
|
|
|
enum_transp["opaque"] = "opaque";
|
|
|
|
|
enum_transp["transparent"] = "transparent";
|
|
|
|
|
})(enum_transp = ical.enum_transp || (ical.enum_transp = {}));
|
|
|
|
|
;
|
|
|
|
|
})(ical = lib_plankton.ical || (lib_plankton.ical = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:ical«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:ical« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:ical« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:ical«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var ical;
|
|
|
|
|
(function (ical) {
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function date_decode(date_encoded) {
|
|
|
|
|
return {
|
|
|
|
|
"year": parseInt(date_encoded.slice(0, 4)),
|
|
|
|
|
"month": parseInt(date_encoded.slice(4, 6)),
|
|
|
|
|
"day": parseInt(date_encoded.slice(6, 8)),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function time_decode(time_encoded) {
|
|
|
|
|
return {
|
|
|
|
|
"hour": parseInt(time_encoded.slice(0, 2)),
|
|
|
|
|
"minute": parseInt(time_encoded.slice(2, 4)),
|
|
|
|
|
"second": parseInt(time_encoded.slice(4, 6)),
|
|
|
|
|
"utc": ((time_encoded.length >= 7) && (time_encoded[6] === "Z"))
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function datetime_decode(datetime_encoded) {
|
|
|
|
|
const parts = datetime_encoded.split("T", 2);
|
|
|
|
|
return {
|
|
|
|
|
"date": date_decode(parts[0]),
|
|
|
|
|
"time": ((parts.length >= 2) ? time_decode(parts[1]) : null),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
let enum_decode_state_label;
|
|
|
|
|
(function (enum_decode_state_label) {
|
|
|
|
|
enum_decode_state_label["expect_vcalendar_begin"] = "expect_vcalendar_begin";
|
|
|
|
|
enum_decode_state_label["expect_vcalendar_property"] = "expect_vcalendar_property";
|
|
|
|
|
enum_decode_state_label["expect_vevent_property"] = "expect_vevent_property";
|
|
|
|
|
enum_decode_state_label["done"] = "done";
|
|
|
|
|
})(enum_decode_state_label || (enum_decode_state_label = {}));
|
|
|
|
|
;
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function class_encode(class_) {
|
|
|
|
|
switch (class_) {
|
|
|
|
|
case ical.enum_class.private: {
|
|
|
|
|
return "PRIVATE";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ical.enum_class.public: {
|
|
|
|
|
return "PUBLIC";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ical.enum_class.confidential: {
|
|
|
|
|
return "CONFIDENTIAL";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function class_decode(class_encoded) {
|
|
|
|
|
return {
|
|
|
|
|
"PRIVATE": ical.enum_class.private,
|
|
|
|
|
"PUBLIC": ical.enum_class.public,
|
|
|
|
|
"CONFIDENTIAL": ical.enum_class.confidential,
|
|
|
|
|
}[class_encoded];
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function event_status_encode(event_status) {
|
|
|
|
|
switch (event_status) {
|
|
|
|
|
case ical.enum_event_status.tentative: {
|
|
|
|
|
return "TENTATIVE";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ical.enum_event_status.confirmed: {
|
|
|
|
|
return "CONFIRMED";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ical.enum_event_status.cancelled: {
|
|
|
|
|
return "CANCELLED";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function event_status_decode(event_status_encoded) {
|
|
|
|
|
return {
|
|
|
|
|
"TENTATIVE": ical.enum_event_status.tentative,
|
|
|
|
|
"CONFIRMED": ical.enum_event_status.confirmed,
|
|
|
|
|
"CANCELLED": ical.enum_event_status.cancelled,
|
|
|
|
|
}[event_status_encoded];
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function transp_encode(transp) {
|
|
|
|
|
switch (transp) {
|
|
|
|
|
case ical.enum_transp.opaque: {
|
|
|
|
|
return "OPAQUE";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ical.enum_transp.transparent: {
|
|
|
|
|
return "TRANSPARENT";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function transp_decode(transp_encoded) {
|
|
|
|
|
return {
|
|
|
|
|
"OPAQUE": ical.enum_transp.opaque,
|
|
|
|
|
"TRANSPARENT": ical.enum_transp.transparent,
|
|
|
|
|
}[transp_encoded];
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function datetime_to_unixtimestamp(datetime) {
|
|
|
|
|
if ((datetime.time !== null) && (!datetime.time.utc)) {
|
|
|
|
|
throw (new Error("can not convert not utc time values"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return lib_plankton.date.from_components({
|
|
|
|
|
"timezone_offset": 0,
|
|
|
|
|
"year": datetime.date.year,
|
|
|
|
|
"month": datetime.date.month,
|
|
|
|
|
"day": datetime.date.day,
|
|
|
|
|
"hour": ((datetime.time === null) ? 0 : datetime.time.hour),
|
|
|
|
|
"minute": ((datetime.time === null) ? 0 : datetime.time.minute),
|
|
|
|
|
"second": ((datetime.time === null) ? 0 : datetime.time.second),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ical.datetime_to_unixtimestamp = datetime_to_unixtimestamp;
|
|
|
|
|
/**
|
|
|
|
|
* @see https://www.rfc-editor.org/rfc/rfc5545
|
|
|
|
|
* @see https://icalendar.org/iCalendar-RFC-5545/
|
|
|
|
|
* @todo implement edge cases
|
|
|
|
|
*/
|
|
|
|
|
function ics_decode(ics, options = {}) {
|
|
|
|
|
options = Object.assign({
|
|
|
|
|
"debug": false,
|
|
|
|
|
}, options);
|
|
|
|
|
// preprocessing
|
|
|
|
|
const lines = ics.split("\r\n");
|
|
|
|
|
let content_lines = [];
|
|
|
|
|
let content_line_buffer = null;
|
|
|
|
|
lines.forEach(line => {
|
|
|
|
|
if (line.trim() === "") {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const is_folding = ((line.length >= 2)
|
|
|
|
|
&&
|
|
|
|
|
((line[0] === " ")
|
|
|
|
|
||
|
|
|
|
|
(line[0] === "\t"))
|
|
|
|
|
/*
|
|
|
|
|
&&
|
|
|
|
|
! (
|
|
|
|
|
(line[1] === " ")
|
|
|
|
|
||
|
|
|
|
|
(line[1] === "\t")
|
|
|
|
|
)
|
|
|
|
|
*/
|
|
|
|
|
);
|
|
|
|
|
if (is_folding) {
|
|
|
|
|
content_line_buffer += line.slice(1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (content_line_buffer === null) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
content_lines.push(content_line_buffer);
|
|
|
|
|
}
|
|
|
|
|
content_line_buffer = line;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
const instructions = content_lines.map((content_line) => {
|
|
|
|
|
const parts = content_line.split(":");
|
|
|
|
|
const parts_left = parts[0].split(";");
|
|
|
|
|
return {
|
|
|
|
|
"command": parts_left[0],
|
|
|
|
|
"parameters": Object.fromEntries(parts_left.slice(1).map(x => x.split("=", 2))),
|
|
|
|
|
"value": (parts.slice(1).join(":")
|
|
|
|
|
.split(";")
|
|
|
|
|
.map(x => x.replace(new RegExp("\\\\,", "g"), ","))),
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
// core
|
|
|
|
|
let state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vcalendar_begin,
|
|
|
|
|
"vcalendar": null,
|
|
|
|
|
"vevent": null,
|
|
|
|
|
};
|
|
|
|
|
instructions.forEach((instruction) => {
|
|
|
|
|
if (options.debug) {
|
|
|
|
|
console.info(JSON.stringify({ "instruction": instruction, "state": state }, undefined, "\t"));
|
|
|
|
|
}
|
|
|
|
|
switch (state.label) {
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unhandled state label: " + state.label));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case enum_decode_state_label.expect_vcalendar_begin: {
|
|
|
|
|
switch (instruction.command) {
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unexpected instruction key: " + instruction.command));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "BEGIN": {
|
|
|
|
|
switch (instruction.value[0]) {
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unexpected instruction value: " + instruction.value[0]));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "VCALENDAR": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vcalendar_property,
|
|
|
|
|
"vcalendar": {
|
|
|
|
|
"version": "",
|
|
|
|
|
"prodid": "",
|
|
|
|
|
"vevents": [],
|
|
|
|
|
},
|
|
|
|
|
"vevent": null,
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case enum_decode_state_label.expect_vcalendar_property: {
|
|
|
|
|
switch (instruction.command) {
|
|
|
|
|
case "VERSION": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vcalendar_property,
|
|
|
|
|
"vcalendar": Object.assign(state.vcalendar, Object.fromEntries([["version", instruction.value[0]]])),
|
|
|
|
|
"vevent": state.vevent,
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "PRODID": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vcalendar_property,
|
|
|
|
|
"vcalendar": Object.assign(state.vcalendar, Object.fromEntries([["prodid", instruction.value[0]]])),
|
|
|
|
|
"vevent": state.vevent,
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "METHOD": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vcalendar_property,
|
|
|
|
|
"vcalendar": Object.assign(state.vcalendar, Object.fromEntries([["method", instruction.value[0]]])),
|
|
|
|
|
"vevent": state.vevent,
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "BEGIN": {
|
|
|
|
|
const object = instruction.value[0];
|
|
|
|
|
switch (object) {
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unhandled object: " + object));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "VCALENDAR": {
|
|
|
|
|
throw (new Error("unexpected object: " + object));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "VEVENT": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": {
|
|
|
|
|
"uid": "",
|
|
|
|
|
"dtstamp": {
|
|
|
|
|
"date": { "year": 2000, "month": 0, "day": 0 },
|
|
|
|
|
"time": { "hour": 0, "minute": 0, "second": 0, "utc": true },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "END": {
|
|
|
|
|
const object = instruction.value[0];
|
|
|
|
|
switch (object) {
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unhandled object: " + object));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "VCALENDAR": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.done,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": state.vevent,
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
if (instruction.command.startsWith("X-")) {
|
|
|
|
|
const key = instruction.command.slice(2).toLowerCase();
|
|
|
|
|
const value = instruction.value.join(";");
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vcalendar_property,
|
|
|
|
|
"vcalendar": Object.assign(state.vcalendar, {
|
|
|
|
|
"x_props": Object.assign((state.vcalendar.x_props ?? {}), Object.fromEntries([[key, value]]))
|
|
|
|
|
}),
|
|
|
|
|
"vevent": state.vevent,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.info({ "instruction": instruction, "state": state });
|
|
|
|
|
throw (new Error("unhandled instruction key: " + instruction.command));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case enum_decode_state_label.expect_vevent_property: {
|
|
|
|
|
switch (instruction.command) {
|
|
|
|
|
case "UID": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([["uid", instruction.value[0]]])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "DTSTART": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([
|
|
|
|
|
[
|
|
|
|
|
"dtstart",
|
|
|
|
|
{
|
|
|
|
|
"tzid": instruction.parameters["tzid"],
|
|
|
|
|
"value": datetime_decode(instruction.value[0]),
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "DTEND": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([
|
|
|
|
|
[
|
|
|
|
|
"dtend",
|
|
|
|
|
{
|
|
|
|
|
"tzid": instruction.parameters["tzid"],
|
|
|
|
|
"value": datetime_decode(instruction.value[0]),
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "DTSTAMP": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([
|
|
|
|
|
[
|
|
|
|
|
"dtstamp",
|
|
|
|
|
datetime_decode(instruction.value[0])
|
|
|
|
|
]
|
|
|
|
|
])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "SEQUENCE": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([["sequence", parseInt(instruction.value[0])]])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "TRANSP": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([["transp", transp_decode(instruction.value[0])]])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "SUMMARY": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([["summary", instruction.value[0]]])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "CLASS": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([["class", class_decode(instruction.value[0])]])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "STATUS": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([["status", event_status_decode(instruction.value[0])]])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "DESCRIPTION": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([["description", instruction.value[0]]])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "CATEGORIES": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([["categories", instruction.value[0].split(",")]])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "CREATED": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([
|
|
|
|
|
[
|
|
|
|
|
"created",
|
|
|
|
|
{
|
|
|
|
|
"value": datetime_decode(instruction.value[0]),
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "LOCATION": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([["location", instruction.value[0]]])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "URL": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([["url", instruction.value[0]]])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "LAST-MODIFIED": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([
|
|
|
|
|
[
|
|
|
|
|
"last_modified",
|
|
|
|
|
{
|
|
|
|
|
"value": datetime_decode(instruction.value[0]),
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "ATTENDEE": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, Object.fromEntries([["attendee", instruction.value[0]]])),
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "BEGIN": {
|
|
|
|
|
const object = instruction.value[0];
|
|
|
|
|
switch (object) {
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unhandled object: " + object));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "VCALENDAR": {
|
|
|
|
|
throw (new Error("unexpected object: " + object));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "VEVENT": {
|
|
|
|
|
throw (new Error("unexpected object: " + object));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "END": {
|
|
|
|
|
const object = instruction.value[0];
|
|
|
|
|
switch (object) {
|
|
|
|
|
default: {
|
|
|
|
|
throw (new Error("unhandled value: " + object));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "VEVENT": {
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vcalendar_property,
|
|
|
|
|
"vcalendar": Object.assign(state.vcalendar, {
|
|
|
|
|
"vevents": state.vcalendar.vevents.concat([state.vevent]),
|
|
|
|
|
}),
|
|
|
|
|
"vevent": null,
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
if (instruction.command.startsWith("X-")) {
|
|
|
|
|
const key = instruction.command.slice(2).toLowerCase();
|
|
|
|
|
const value = instruction.value.join(";");
|
|
|
|
|
state = {
|
|
|
|
|
"label": enum_decode_state_label.expect_vevent_property,
|
|
|
|
|
"vcalendar": state.vcalendar,
|
|
|
|
|
"vevent": Object.assign(state.vevent, {
|
|
|
|
|
"x_props": Object.assign((state.vevent.x_props ?? {}), Object.fromEntries([[key, value]]))
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.info({ "instruction": instruction, "state": state });
|
|
|
|
|
throw (new Error("unhandled instruction key: " + instruction.command));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case enum_decode_state_label.done: {
|
|
|
|
|
console.info({ "instruction": instruction, "state": state });
|
|
|
|
|
throw (new Error("end expected"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return state.vcalendar;
|
|
|
|
|
}
|
|
|
|
|
ical.ics_decode = ics_decode;
|
|
|
|
|
/**
|
|
|
|
|
* @see https://www.rfc-editor.org/rfc/rfc5545
|
|
|
|
|
* @see https://icalendar.org/iCalendar-RFC-5545/
|
|
|
|
|
*/
|
|
|
|
|
function date_encode(date) {
|
|
|
|
|
return lib_plankton.string.coin("{{year}}{{month}}{{day}}", {
|
|
|
|
|
"year": date.year.toFixed(0).padStart(4, "0"),
|
|
|
|
|
"month": date.month.toFixed(0).padStart(2, "0"),
|
|
|
|
|
"day": date.day.toFixed(0).padStart(2, "0"),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function time_encode(time) {
|
|
|
|
|
return lib_plankton.string.coin("{{hour}}{{minute}}{{second}}{{utc}}", {
|
|
|
|
|
"hour": time.hour.toFixed(0).padStart(2, "0"),
|
|
|
|
|
"minute": time.minute.toFixed(0).padStart(2, "0"),
|
|
|
|
|
"second": time.second.toFixed(0).padStart(2, "0"),
|
|
|
|
|
"utc": (time.utc ? "Z" : ""),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
function datetime_encode(datetime) {
|
|
|
|
|
return lib_plankton.string.coin("{{date}}T{{time}}", {
|
|
|
|
|
"date": date_encode(datetime.date),
|
|
|
|
|
"time": time_encode(datetime.time),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @todo method
|
|
|
|
|
* @todo add missing fields
|
|
|
|
|
*/
|
|
|
|
|
function ics_encode(vcalendar) {
|
|
|
|
|
let content_lines = [];
|
|
|
|
|
content_lines.push("BEGIN:VCALENDAR");
|
|
|
|
|
content_lines.push(lib_plankton.string.coin("VERSION:{{version}}", { "version": vcalendar.version }));
|
|
|
|
|
content_lines.push(lib_plankton.string.coin("PRODID:{{prodid}}", { "prodid": vcalendar.prodid }));
|
|
|
|
|
content_lines.push(lib_plankton.string.coin("METHOD:{{method}}", { "method": vcalendar.method }));
|
|
|
|
|
vcalendar.vevents.forEach((vevent) => {
|
|
|
|
|
content_lines.push("BEGIN:VEVENT");
|
|
|
|
|
{
|
|
|
|
|
// uid
|
|
|
|
|
content_lines.push(lib_plankton.string.coin("UID:{{uid}}", {
|
|
|
|
|
"uid": vevent.uid,
|
|
|
|
|
}));
|
|
|
|
|
// dtstart
|
|
|
|
|
content_lines.push(lib_plankton.string.coin(
|
|
|
|
|
// "DTSTART;TZID={{tzid}}:{{value}}",
|
|
|
|
|
"DTSTART:{{value}}", {
|
|
|
|
|
"tzid": vevent.dtstart.tzid,
|
|
|
|
|
"value": datetime_encode(vevent.dtstart.value),
|
|
|
|
|
}));
|
|
|
|
|
// dtend
|
|
|
|
|
if (vevent.dtend !== undefined) {
|
|
|
|
|
content_lines.push(lib_plankton.string.coin(
|
|
|
|
|
// "DTEND;TZID={{tzid}}:{{value}}",
|
|
|
|
|
"DTEND:{{value}}", {
|
|
|
|
|
"tzid": vevent.dtend.tzid,
|
|
|
|
|
"value": datetime_encode(vevent.dtend.value),
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
// dtstamp
|
|
|
|
|
content_lines.push(lib_plankton.string.coin("DTSTAMP:{{value}}", {
|
|
|
|
|
"value": datetime_encode(vevent.dtstamp),
|
|
|
|
|
}));
|
|
|
|
|
// class
|
|
|
|
|
if (vevent.class !== undefined) {
|
|
|
|
|
content_lines.push(lib_plankton.string.coin("CLASS:{{class}}", {
|
|
|
|
|
"class": vevent.class,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
// summary
|
|
|
|
|
content_lines.push(lib_plankton.string.coin("SUMMARY:{{summary}}", {
|
|
|
|
|
"summary": vevent.summary,
|
|
|
|
|
}));
|
|
|
|
|
// description
|
|
|
|
|
if (vevent.description !== undefined) {
|
|
|
|
|
content_lines.push(lib_plankton.string.coin("DESCRIPTION:{{description}}", {
|
|
|
|
|
"description": vevent.description,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
// location
|
|
|
|
|
if (vevent.location !== undefined) {
|
|
|
|
|
content_lines.push(lib_plankton.string.coin("LOCATION:{{location}}", {
|
|
|
|
|
"location": vevent.location,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
// geo
|
|
|
|
|
if (vevent.geo !== undefined) {
|
|
|
|
|
content_lines.push(lib_plankton.string.coin("GEO:{{geo_latitude}};{{geo_longitude}}", {
|
|
|
|
|
"geo_latitude": vevent.geo.latitude.toFixed(4),
|
|
|
|
|
"geo_longitude": vevent.geo.longitude.toFixed(4),
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
// url
|
|
|
|
|
if (vevent.url !== undefined) {
|
|
|
|
|
content_lines.push(lib_plankton.string.coin("URL:{{url}}", {
|
|
|
|
|
"url": vevent.url,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
content_lines.push("END:VEVENT");
|
|
|
|
|
});
|
|
|
|
|
content_lines.push("END:VCALENDAR");
|
|
|
|
|
let lines = [];
|
|
|
|
|
content_lines.forEach((content_line) => {
|
|
|
|
|
const slices = lib_plankton.string.slice(content_line, 75 - 1);
|
|
|
|
|
lines.push(slices[0]);
|
|
|
|
|
slices.slice(1).forEach((slice) => { lines.push(" " + slice); });
|
|
|
|
|
});
|
|
|
|
|
return lines.join("\r\n");
|
|
|
|
|
}
|
|
|
|
|
ical.ics_encode = ics_encode;
|
|
|
|
|
})(ical = lib_plankton.ical || (lib_plankton.ical = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:http«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:http« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:http« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:http«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var http;
|
|
|
|
|
(function (http) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris <frass@greenscale.de>
|
|
|
|
|
*/
|
|
|
|
|
let enum_method;
|
|
|
|
|
(function (enum_method) {
|
|
|
|
|
enum_method["options"] = "options";
|
|
|
|
|
enum_method["head"] = "head";
|
|
|
|
|
enum_method["get"] = "get";
|
|
|
|
|
enum_method["delete"] = "delete";
|
|
|
|
|
enum_method["post"] = "post";
|
|
|
|
|
enum_method["put"] = "put";
|
|
|
|
|
enum_method["patch"] = "patch";
|
|
|
|
|
})(enum_method = http.enum_method || (http.enum_method = {}));
|
|
|
|
|
})(http = lib_plankton.http || (lib_plankton.http = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:http«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:http« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:http« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:http«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var http;
|
|
|
|
|
(function (http) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris <frass@greenscale.de>
|
|
|
|
|
*/
|
|
|
|
|
const linebreak = "\r\n";
|
|
|
|
|
/**
|
|
|
|
|
* @todo outsource to string module
|
|
|
|
|
*/
|
|
|
|
|
function capitalize(str) {
|
|
|
|
|
return (str[0].toUpperCase() + str.slice(1));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @todo outsource to string module
|
|
|
|
|
*/
|
|
|
|
|
function capitalize_all(str) {
|
|
|
|
|
return str.split("-").map(x => capitalize(x)).join("-");
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris <frass@greenscale.de>
|
|
|
|
|
*/
|
|
|
|
|
function encode_method(method) {
|
|
|
|
|
switch (method) {
|
|
|
|
|
case http.enum_method.get: return "GET";
|
|
|
|
|
case http.enum_method.post: return "POST";
|
|
|
|
|
case http.enum_method.patch: return "PATCH";
|
|
|
|
|
case http.enum_method.put: return "PUT";
|
|
|
|
|
case http.enum_method.delete: return "DELETE";
|
|
|
|
|
case http.enum_method.options: return "OPTIONS";
|
|
|
|
|
case http.enum_method.head: return "HEAD";
|
|
|
|
|
default: throw (new Error("impossible"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
http.encode_method = encode_method;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris <frass@greenscale.de>
|
|
|
|
|
*/
|
|
|
|
|
function decode_method(method_raw) {
|
|
|
|
|
switch (method_raw) {
|
|
|
|
|
case "GET": return http.enum_method.get;
|
|
|
|
|
case "POST": return http.enum_method.post;
|
|
|
|
|
case "PATCH": return http.enum_method.patch;
|
|
|
|
|
case "PUT": return http.enum_method.put;
|
|
|
|
|
case "DELETE": return http.enum_method.delete;
|
|
|
|
|
case "OPTIONS": return http.enum_method.options;
|
|
|
|
|
case "HEAD": return http.enum_method.head;
|
|
|
|
|
default: throw (new Error("unhandled method: " + method_raw));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris <frass@greenscale.de>
|
|
|
|
|
*/
|
|
|
|
|
function get_statustext(statuscode) {
|
|
|
|
|
switch (statuscode) {
|
|
|
|
|
case 100: return "Continue";
|
|
|
|
|
case 101: return "Switching Protocols";
|
|
|
|
|
case 103: return "Early Hints";
|
|
|
|
|
case 200: return "OK";
|
|
|
|
|
case 201: return "Created";
|
|
|
|
|
case 202: return "Accepted";
|
|
|
|
|
case 203: return "Non-Authoritative Information";
|
|
|
|
|
case 204: return "No Content";
|
|
|
|
|
case 205: return "Reset Content";
|
|
|
|
|
case 206: return "Partial Content";
|
|
|
|
|
case 300: return "Multiple Choices";
|
|
|
|
|
case 301: return "Moved Permanently";
|
|
|
|
|
case 302: return "Found";
|
|
|
|
|
case 303: return "See Other";
|
|
|
|
|
case 304: return "Not Modified";
|
|
|
|
|
case 307: return "Temporary Redirect";
|
|
|
|
|
case 308: return "Permanent Redirect";
|
|
|
|
|
case 400: return "Bad Request";
|
|
|
|
|
case 401: return "Unauthorized";
|
|
|
|
|
case 402: return "Payment Required";
|
|
|
|
|
case 403: return "Forbidden";
|
|
|
|
|
case 404: return "Not Found";
|
|
|
|
|
case 405: return "Method Not Allowed";
|
|
|
|
|
case 406: return "Not Acceptable";
|
|
|
|
|
case 407: return "Proxy Authentication Required";
|
|
|
|
|
case 408: return "Request Timeout";
|
|
|
|
|
case 409: return "Conflict";
|
|
|
|
|
case 410: return "Gone";
|
|
|
|
|
case 411: return "Length Required";
|
|
|
|
|
case 412: return "Precondition Failed";
|
|
|
|
|
case 413: return "Payload Too Large";
|
|
|
|
|
case 414: return "URI Too Long";
|
|
|
|
|
case 415: return "Unsupported Media Type";
|
|
|
|
|
case 416: return "Range Not Satisfiable";
|
|
|
|
|
case 417: return "Expectation Failed";
|
|
|
|
|
case 418: return "I'm a teapot";
|
|
|
|
|
case 422: return "Unprocessable Entity";
|
|
|
|
|
case 425: return "Too Early";
|
|
|
|
|
case 426: return "Upgrade Required";
|
|
|
|
|
case 428: return "Precondition Required";
|
|
|
|
|
case 429: return "Too Many Requests";
|
|
|
|
|
case 431: return "Request Header Fields Too Large";
|
|
|
|
|
case 451: return "Unavailable For Legal Reasons";
|
|
|
|
|
case 500: return "Internal Server Error";
|
|
|
|
|
case 501: return "Not Implemented";
|
|
|
|
|
case 502: return "Bad Gateway";
|
|
|
|
|
case 503: return "Service Unavailable";
|
|
|
|
|
case 504: return "Gateway Timeout";
|
|
|
|
|
case 505: return "HTTP Version Not Supported";
|
|
|
|
|
case 506: return "Variant Also Negotiates";
|
|
|
|
|
case 507: return "Insufficient Storage";
|
|
|
|
|
case 508: return "Loop Detected";
|
|
|
|
|
case 510: return "Not Extended";
|
|
|
|
|
case 511: return "Network Authentication";
|
|
|
|
|
default: throw (new Error("unhandled statuscode: " + statuscode.toFixed(0)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris <frass@greenscale.de>
|
|
|
|
|
*/
|
|
|
|
|
function encode_request(request) {
|
|
|
|
|
let request_raw = "";
|
|
|
|
|
request_raw += (encode_method(request.method)
|
|
|
|
|
+
|
|
|
|
|
" "
|
|
|
|
|
+
|
|
|
|
|
request.path
|
|
|
|
|
+
|
|
|
|
|
((request.query === null) ? "" : request.query)
|
|
|
|
|
+
|
|
|
|
|
" "
|
|
|
|
|
+
|
|
|
|
|
request.version
|
|
|
|
|
+
|
|
|
|
|
linebreak);
|
|
|
|
|
if (request.host === null) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
request_raw += ("Host: " + request.host + linebreak);
|
|
|
|
|
}
|
|
|
|
|
for (const [key, value] of Object.entries(request.headers)) {
|
|
|
|
|
request_raw += (capitalize_all(key) + ": " + value + linebreak);
|
|
|
|
|
}
|
|
|
|
|
request_raw += linebreak;
|
|
|
|
|
if (request.body === null) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
request_raw += request.body.toString();
|
|
|
|
|
}
|
|
|
|
|
return request_raw;
|
|
|
|
|
}
|
|
|
|
|
http.encode_request = encode_request;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris <frass@greenscale.de>
|
|
|
|
|
*/
|
|
|
|
|
function decode_request(request_raw) {
|
|
|
|
|
const lines = request_raw.split(linebreak);
|
|
|
|
|
const first = lines.shift();
|
|
|
|
|
const parts = first.split(" ");
|
|
|
|
|
const method = decode_method(parts[0]);
|
|
|
|
|
const path_and_query = parts[1];
|
|
|
|
|
const parts_ = path_and_query.split("?");
|
|
|
|
|
const path = parts_[0];
|
|
|
|
|
const query = ((parts_.length <= 1) ? null : ("?" + parts_.slice(1).join("?")));
|
|
|
|
|
const version = parts[2];
|
|
|
|
|
let headers = {};
|
|
|
|
|
while (true) {
|
|
|
|
|
const line = lines.shift();
|
|
|
|
|
if (line === "") {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const [key, value] = line.split(": ", 2);
|
|
|
|
|
headers[key.toLowerCase()] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const body = ([http.enum_method.post, http.enum_method.put, http.enum_method.patch].includes(method)
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
? Buffer.from(lines.join(linebreak))
|
|
|
|
|
: null);
|
|
|
|
|
const request = {
|
|
|
|
|
// TODO
|
|
|
|
|
"scheme": "http",
|
|
|
|
|
"host": (headers["host"] ?? null),
|
|
|
|
|
"path": path,
|
|
|
|
|
"version": version,
|
|
|
|
|
"method": method,
|
|
|
|
|
"query": query,
|
|
|
|
|
"headers": headers,
|
|
|
|
|
"body": body,
|
|
|
|
|
};
|
|
|
|
|
return request;
|
|
|
|
|
}
|
|
|
|
|
http.decode_request = decode_request;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris <frass@greenscale.de>
|
|
|
|
|
*/
|
|
|
|
|
function encode_response(response) {
|
|
|
|
|
let response_raw = "";
|
|
|
|
|
response_raw += (response.version
|
|
|
|
|
+
|
|
|
|
|
" "
|
|
|
|
|
+
|
|
|
|
|
response.status_code.toFixed(0)
|
|
|
|
|
+
|
|
|
|
|
" "
|
|
|
|
|
+
|
|
|
|
|
get_statustext(response.status_code)
|
|
|
|
|
+
|
|
|
|
|
linebreak);
|
|
|
|
|
for (const [key, value] of Object.entries(response.headers)) {
|
|
|
|
|
response_raw += (capitalize_all(key) + ": " + value + linebreak);
|
|
|
|
|
}
|
|
|
|
|
response_raw += linebreak;
|
|
|
|
|
response_raw += response.body;
|
|
|
|
|
return response_raw;
|
|
|
|
|
}
|
|
|
|
|
http.encode_response = encode_response;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris <frass@greenscale.de>
|
|
|
|
|
*/
|
|
|
|
|
function decode_response(response_raw) {
|
|
|
|
|
const lines = response_raw.split(linebreak);
|
|
|
|
|
const first = lines.shift();
|
|
|
|
|
const first_parts = first.split(" ");
|
|
|
|
|
const version = first_parts[0];
|
|
|
|
|
const status_code = parseInt(first_parts[1]);
|
|
|
|
|
// first_parts.slice(2) ? probably irrelevant
|
|
|
|
|
let headers = {};
|
|
|
|
|
while (true) {
|
|
|
|
|
const line = lines.shift();
|
|
|
|
|
if (line === "") {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const [key, value] = line.split(": ", 2);
|
|
|
|
|
headers[key.toLowerCase()] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
const body = Buffer.from(lines.join(linebreak));
|
|
|
|
|
const response = {
|
|
|
|
|
// TODO
|
|
|
|
|
"version": version,
|
|
|
|
|
"status_code": status_code,
|
|
|
|
|
"headers": headers,
|
|
|
|
|
"body": body,
|
|
|
|
|
};
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
http.decode_response = decode_response;
|
|
|
|
|
/**
|
|
|
|
|
* executes an HTTP request
|
|
|
|
|
*
|
|
|
|
|
* @todo define type_signal
|
|
|
|
|
*/
|
|
|
|
|
async function call(request, options = {}) {
|
|
|
|
|
options = Object.assign({
|
|
|
|
|
"timeout": 5.0,
|
|
|
|
|
"follow_redirects": false,
|
|
|
|
|
"implementation": "fetch",
|
|
|
|
|
}, options);
|
|
|
|
|
const target = (request.scheme
|
|
|
|
|
+
|
|
|
|
|
"://"
|
|
|
|
|
+
|
|
|
|
|
request.host
|
|
|
|
|
+
|
|
|
|
|
request.path
|
|
|
|
|
+
|
|
|
|
|
((request.query === null)
|
|
|
|
|
? ""
|
|
|
|
|
: request.query));
|
|
|
|
|
switch (options.implementation) {
|
|
|
|
|
default: {
|
|
|
|
|
return Promise.reject("invalid implementation: " + options.implementation);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "fetch": {
|
|
|
|
|
function core(signal) {
|
|
|
|
|
return (fetch(target, Object.assign({
|
|
|
|
|
"method": ((method => {
|
|
|
|
|
switch (method) {
|
|
|
|
|
case http.enum_method.head: return "HEAD";
|
|
|
|
|
case http.enum_method.options: return "OPTIONS";
|
|
|
|
|
case http.enum_method.get: return "GET";
|
|
|
|
|
case http.enum_method.delete: return "DELETE";
|
|
|
|
|
case http.enum_method.post: return "POST";
|
|
|
|
|
case http.enum_method.put: return "PUT";
|
|
|
|
|
case http.enum_method.patch: return "PATCH";
|
|
|
|
|
}
|
|
|
|
|
})(request.method)),
|
|
|
|
|
"headers": request.headers,
|
|
|
|
|
/*
|
|
|
|
|
"redirect": (
|
|
|
|
|
options.follow_redirects
|
|
|
|
|
?
|
|
|
|
|
"follow"
|
|
|
|
|
:
|
|
|
|
|
"manual"
|
|
|
|
|
),
|
|
|
|
|
*/
|
|
|
|
|
"signal": (signal
|
|
|
|
|
??
|
|
|
|
|
undefined),
|
|
|
|
|
// "keepalive": false,
|
|
|
|
|
}, ((((method => {
|
|
|
|
|
switch (method) {
|
|
|
|
|
case http.enum_method.head: return false;
|
|
|
|
|
case http.enum_method.options: return false;
|
|
|
|
|
case http.enum_method.get: return false;
|
|
|
|
|
case http.enum_method.delete: return false;
|
|
|
|
|
case http.enum_method.post: return true;
|
|
|
|
|
case http.enum_method.put: return true;
|
|
|
|
|
case http.enum_method.patch: return true;
|
|
|
|
|
}
|
|
|
|
|
})(request.method))
|
|
|
|
|
&&
|
|
|
|
|
(request.body !== null))
|
|
|
|
|
? {
|
|
|
|
|
"body": request.body.toString(),
|
|
|
|
|
}
|
|
|
|
|
: {})))
|
|
|
|
|
.catch((reason) => {
|
|
|
|
|
// console.info(reason);
|
|
|
|
|
return Promise.reject(reason);
|
|
|
|
|
})
|
|
|
|
|
.then((response_raw) => (response_raw.text()
|
|
|
|
|
.then((body) => Promise.resolve({
|
|
|
|
|
// TODO
|
|
|
|
|
"version": null,
|
|
|
|
|
"status_code": response_raw.status,
|
|
|
|
|
"headers": ((headers_raw => {
|
|
|
|
|
let headers = {};
|
|
|
|
|
headers_raw.forEach((value, key) => {
|
|
|
|
|
headers[key] = value;
|
|
|
|
|
});
|
|
|
|
|
return headers;
|
|
|
|
|
})(response_raw.headers)),
|
|
|
|
|
"body": body,
|
|
|
|
|
})))));
|
|
|
|
|
}
|
|
|
|
|
function timeout(controller) {
|
|
|
|
|
return (new Promise((resolve, reject) => {
|
|
|
|
|
if (options.timeout === null) {
|
|
|
|
|
// do nothing (neither resolve nor reject ever)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
controller.abort();
|
|
|
|
|
resolve(null);
|
|
|
|
|
}, (options.timeout * 1000));
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
|
const signal = controller.signal;
|
|
|
|
|
const response = await Promise.race([
|
|
|
|
|
timeout(controller),
|
|
|
|
|
core(signal),
|
|
|
|
|
]);
|
|
|
|
|
if (response === null) {
|
|
|
|
|
throw (new Error("http_request_timeout"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "http_module": {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
const nm_http = require("http");
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
const nm_https = require("https");
|
|
|
|
|
return (new Promise((resolve, reject) => {
|
|
|
|
|
const req = ((request.scheme === "https")
|
|
|
|
|
? nm_https
|
|
|
|
|
: nm_http)
|
|
|
|
|
.request(target, {
|
|
|
|
|
"method": request.method,
|
|
|
|
|
"headers": request.headers,
|
|
|
|
|
}, (res) => {
|
|
|
|
|
try {
|
|
|
|
|
let response_body = "";
|
|
|
|
|
res.setEncoding("utf8");
|
|
|
|
|
res.on("data", (chunk) => {
|
|
|
|
|
response_body += chunk;
|
|
|
|
|
});
|
|
|
|
|
res.on("end", () => {
|
|
|
|
|
resolve({
|
|
|
|
|
// TODO
|
|
|
|
|
"version": null,
|
|
|
|
|
"status_code": res.statusCode,
|
|
|
|
|
"headers": res.headers,
|
|
|
|
|
"body": response_body,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (error) {
|
|
|
|
|
reject(error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
req.on("error", (error) => {
|
|
|
|
|
reject(error);
|
|
|
|
|
});
|
|
|
|
|
req.write(request.body);
|
|
|
|
|
req.end();
|
|
|
|
|
}));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
http.call = call;
|
|
|
|
|
})(http = lib_plankton.http || (lib_plankton.http = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:http«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:http« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:http« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:http«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var http;
|
|
|
|
|
(function (http) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_http_request {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor() {
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
encode(x) {
|
|
|
|
|
return http.encode_request(x);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
decode(x) {
|
|
|
|
|
return http.decode_request(x);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
http.class_http_request = class_http_request;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_http_response {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor() {
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
encode(x) {
|
|
|
|
|
return http.encode_response(x);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
decode(x) {
|
|
|
|
|
return http.decode_response(x);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
http.class_http_response = class_http_response;
|
|
|
|
|
})(http = lib_plankton.http || (lib_plankton.http = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:url«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:url« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:url« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:url«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:url«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:url« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:url« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:url«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var url;
|
|
|
|
|
(function (url_1) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function encode(url) {
|
|
|
|
|
let result = "";
|
|
|
|
|
// scheme
|
|
|
|
|
{
|
|
|
|
|
if (url.scheme !== null) {
|
|
|
|
|
result += (url.scheme + ":");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// host
|
|
|
|
|
{
|
|
|
|
|
if (url.host !== null) {
|
|
|
|
|
result += "//";
|
|
|
|
|
// username
|
|
|
|
|
{
|
|
|
|
|
if (url.username !== null) {
|
|
|
|
|
result += url.username;
|
|
|
|
|
// password
|
|
|
|
|
{
|
|
|
|
|
if (url.password !== null) {
|
|
|
|
|
result += (":" + url.password);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result += "@";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result += url.host;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// port
|
|
|
|
|
{
|
|
|
|
|
if (url.port !== null) {
|
|
|
|
|
result += (":" + url.port.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// path
|
|
|
|
|
{
|
|
|
|
|
if (url.path !== null) {
|
2024-09-11 17:24:20 +02:00
|
|
|
|
result += url.path;
|
2024-09-10 01:11:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// query
|
|
|
|
|
{
|
|
|
|
|
if (url.query !== null) {
|
|
|
|
|
result += ("?" + encodeURI(url.query));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// hash
|
|
|
|
|
{
|
|
|
|
|
if (url.hash !== null) {
|
|
|
|
|
result += ("#" + url.hash);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
url_1.encode = encode;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
* @todo arguments
|
|
|
|
|
*/
|
|
|
|
|
function decode(url_raw) {
|
|
|
|
|
const builtin_url = new URL(url_raw);
|
|
|
|
|
return {
|
|
|
|
|
"scheme": builtin_url.protocol.slice(0, -1),
|
|
|
|
|
"host": builtin_url.hostname,
|
|
|
|
|
"username": ((builtin_url.username !== "")
|
|
|
|
|
?
|
|
|
|
|
builtin_url.username
|
|
|
|
|
:
|
|
|
|
|
null),
|
|
|
|
|
"password": ((builtin_url.password !== "")
|
|
|
|
|
?
|
|
|
|
|
builtin_url.password
|
|
|
|
|
:
|
|
|
|
|
null),
|
|
|
|
|
"port": ((builtin_url.port !== "")
|
|
|
|
|
?
|
|
|
|
|
parseInt(builtin_url.port)
|
|
|
|
|
:
|
|
|
|
|
null),
|
|
|
|
|
"path": builtin_url.pathname,
|
|
|
|
|
"query": builtin_url.search.slice(1),
|
|
|
|
|
"hash": ((builtin_url.hash !== "")
|
|
|
|
|
?
|
|
|
|
|
builtin_url.hash.slice(1)
|
|
|
|
|
:
|
|
|
|
|
null),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
url_1.decode = decode;
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
function implementation_code() {
|
|
|
|
|
return {
|
|
|
|
|
"encode": encode,
|
|
|
|
|
"decode": decode,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
url_1.implementation_code = implementation_code;
|
|
|
|
|
})(url = lib_plankton.url || (lib_plankton.url = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|
|
|
|
|
/*
|
|
|
|
|
This file is part of »bacterio-plankton:url«.
|
|
|
|
|
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:url« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»bacterio-plankton:url« is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with »bacterio-plankton:url«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
var lib_plankton;
|
|
|
|
|
(function (lib_plankton) {
|
|
|
|
|
var url;
|
|
|
|
|
(function (url) {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
class class_url {
|
|
|
|
|
/**
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
constructor() {
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
encode(x) {
|
|
|
|
|
return url.encode(x);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @implementation
|
|
|
|
|
* @author fenris
|
|
|
|
|
*/
|
|
|
|
|
decode(x) {
|
|
|
|
|
return url.decode(x);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
url.class_url = class_url;
|
|
|
|
|
})(url = lib_plankton.url || (lib_plankton.url = {}));
|
|
|
|
|
})(lib_plankton || (lib_plankton = {}));
|