consys
Version:
consys is a flexible tool to evaluate models using generic and readable constraints.
50 lines (49 loc) • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Log = void 0;
/**
* Utility class.
*/
class Util {
/**
* Flatten an object and inserting 0 as each value.
*
* @param object object to be flattened
* @param count initial count
* @param parent parent key
* @param res resulting map
*/
static initCounts(object, count, parent, res = {}) {
for (let key in object) {
let propertyName = parent ? parent + '.' + key : key;
if (typeof object[key] == 'object' && !Array.isArray(object[key])) {
Util.initCounts(object[key], count, propertyName, res);
}
else {
res[propertyName] = count;
}
}
return res;
}
}
exports.default = Util;
/**
* Utility log class.
*/
class Log {
/**
* Throw an error.
*
* @param msg error message
*/
static error(msg) {
return Error('[consys]: Error: ' + msg);
}
static reportError(what, where, message, position) {
const prefix = `[consys]:`;
const heading = `${what} error in:`;
const whitespace = ' '.repeat(position + 1);
console.error(`${prefix} ${heading}\n${prefix} ${where}\n${prefix}${whitespace}^~~~~~ ${message}.`);
}
}
exports.Log = Log;