UNPKG

functions-tools

Version:
21 lines (18 loc) 630 B
const {name, version} = require("../../package.json"); module.exports = { error }; function error(str, option = {}, correction) { if (!str) str = "undefined"; str = "\n[Package Name] - "+ name +"@"+ version +"\n\x1b[31m" + str + "\x1b[0m"; if (option && typeof(option) === "object") { for (const [key, value] of Object.entries(option)){ const regexp = new RegExp(`{${key}}`, "g"); str = str.replace(regexp, value); } } if (correction) { str += "\n\x1b[32mCorrect usage: "+ correction +"\x1b[0m\n" } return new Error(str) }