bigassfans
Version:
A library for discovering and controlling BigAssFans
71 lines (70 loc) • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEBUG = exports.DEBUG_APIMessage = exports.printAPIMessage = exports.type = void 0;
const util_1 = require("util");
function type(indents, content) {
let indent = "";
for (let i = 0; i < indents; i++) {
indent += " ";
}
let final = indent;
let stringified = content.toString();
for (let i = 0; i < stringified.length; i++) {
let letter = stringified.charAt(i);
if (stringified.charCodeAt(i) !== 0x0A) {
final += letter;
}
else {
final += "\n";
final += indent;
}
}
console.log(final);
}
exports.type = type;
function printAPIMessage(msg) {
type(0, "API Message");
if (msg.inner?.job !== undefined) {
type(1, "Type: Job");
}
else if (msg.inner?.query !== undefined) {
type(1, "Type: Query");
}
else if (msg.inner?.update !== undefined) {
// Update Type Code
type(1, "Type: Update");
type(2, "Properties:");
if (msg.inner.update.properties.length == 0) {
type(3, "None");
}
else {
msg.inner.update.properties.forEach(p => printProperty(2, p));
}
if (msg.inner.update.scheduleJob !== undefined) {
type(2, "Schedules:");
type(3, (0, util_1.inspect)(msg.inner.update.scheduleJob, { depth: null }));
}
}
function printProperty(indents, property) {
let p = property;
for (let key of Object.keys(property)) {
if (p[key] !== undefined) {
type(indents, `${key}: ${(0, util_1.inspect)(p[key], { depth: null })}`);
}
}
}
}
exports.printAPIMessage = printAPIMessage;
function DEBUG_APIMessage(m) {
if (process.env.DEBUG === "1") {
console.log("Debug:");
printAPIMessage(m);
}
}
exports.DEBUG_APIMessage = DEBUG_APIMessage;
function DEBUG(msg) {
if (process.env.DEBUG === "1") {
console.log("Debug: " + (0, util_1.inspect)(msg, { depth: null }));
}
}
exports.DEBUG = DEBUG;