@iobroker/adapter-dev
Version:
All developer dependencies an ioBroker adapter developer needs
46 lines • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.escapeRegExp = escapeRegExp;
exports.padRight = padRight;
exports.error = error;
exports.die = die;
exports.getIndentation = getIndentation;
exports.interceptErrors = interceptErrors;
const ansi_colors_1 = require("ansi-colors");
function escapeRegExp(value) {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
}
function padRight(text, totalLength) {
return text.padEnd(totalLength, " ");
}
function error(message) {
console.error(ansi_colors_1.bold.red(message));
console.error();
}
function die(message) {
console.error((0, ansi_colors_1.red)(message));
process.exit(1);
}
function getIndentation(text) {
const lines = text.split(/\r?\n/);
const fileStartLine = lines.findIndex((line) => line.startsWith("{"));
if (fileStartLine !== -1 && lines.length > fileStartLine) {
const matches = lines[fileStartLine + 1].match(/^[ ]+/);
console.log(matches);
if (matches && matches.length >= 1) {
return matches[0].length;
}
}
return 4;
}
function interceptErrors(func) {
return async () => {
try {
await func();
}
catch (error) {
die(error.stack || error);
}
};
}
//# sourceMappingURL=util.js.map