@trap_stevo/loml
Version:
Unleash the power of a language crafted for dynamic text styling. Loml transforms your words into code—bold, italic, colorful, and linkable. Turn plain text into expressive, richly formatted messages with simple, elegant commands. Loml empowers you with a
213 lines • 8.16 kB
JavaScript
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var LomlLog = /*#__PURE__*/function () {
function LomlLog() {
_classCallCheck(this, LomlLog);
}
return _createClass(LomlLog, null, [{
key: "disableLogging",
value: function disableLogging() {
LomlLog.loggingEnabled = false;
}
}, {
key: "enableLogging",
value: function enableLogging() {
LomlLog.loggingEnabled = true;
}
}, {
key: "setLogHistoryLimit",
value: function setLogHistoryLimit(limit) {
LomlLog.logHistoryLimit = limit;
}
}, {
key: "addTimestamp",
value: function addTimestamp(message) {
return "[".concat(new Date().toLocaleTimeString(), "] ").concat(message);
}
}, {
key: "setFilter",
value: function setFilter() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$level = _ref.level,
level = _ref$level === void 0 ? null : _ref$level,
_ref$keyword = _ref.keyword,
keyword = _ref$keyword === void 0 ? null : _ref$keyword;
LomlLog.filters.level = level;
LomlLog.filters.keyword = keyword;
}
}, {
key: "filtered",
value: function filtered(message, level) {
if (LomlLog.filters.level && LomlLog.filters.level !== level) {
return true;
}
if (LomlLog.filters.keyword && !message.includes(LomlLog.filters.keyword)) {
return true;
}
return false;
}
}, {
key: "logToDestination",
value: function logToDestination(message, cssString) {
var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
if (LomlLog.outputDestinations.includes("console")) {
console.info("%c".concat(message), cssString);
if (data) {
console.log(JSON.stringify(data, null, 2));
}
}
}
}, {
key: "manageLogHistory",
value: function manageLogHistory() {
if (LomlLog.logHistory.length > LomlLog.logHistoryLimit) {
LomlLog.logHistory.shift();
}
}
}, {
key: "output",
value: function output(message) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
var customStyles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
_ref2$showTimestamp = _ref2.showTimestamp,
showTimestamp = _ref2$showTimestamp === void 0 ? false : _ref2$showTimestamp,
_ref2$data = _ref2.data,
data = _ref2$data === void 0 ? null : _ref2$data;
if (!LomlLog.loggingEnabled) {
return;
}
if (LomlLog.filtered(message, type)) {
return;
}
var predefinedStyles = LomlLog.styles[type] || LomlLog.styles["default"];
var combinedStyles = _objectSpread(_objectSpread({}, predefinedStyles), customStyles);
var cssString = Object.entries(combinedStyles).map(function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
key = _ref4[0],
value = _ref4[1];
return "".concat(key, ": ").concat(value, ";");
}).join(" ");
var finalMessage = showTimestamp ? LomlLog.addTimestamp(message) : message;
LomlLog.logHistory.push({
message: finalMessage,
type: type,
data: data
});
LomlLog.manageLogHistory();
LomlLog.logToDestination(finalMessage, cssString, data);
}
}, {
key: "replayLogs",
value: function replayLogs() {
LomlLog.logHistory.forEach(function (log) {
var message = log.message,
type = log.type,
data = log.data;
var predefinedStyles = LomlLog.styles[type] || LomlLog.styles["default"];
var cssString = Object.entries(predefinedStyles).map(function (_ref5) {
var _ref6 = _slicedToArray(_ref5, 2),
key = _ref6[0],
value = _ref6[1];
return "".concat(key, " : ").concat(value, ";");
}).join(" ");
LomlLog.logToDestination(message, cssString, data);
});
}
}, {
key: "setOutputDestinations",
value: function setOutputDestinations() {
var destinations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ["console"];
LomlLog.outputDestinations = destinations;
}
}]);
}();
_defineProperty(LomlLog, "styles", {
error: {
transition: "all 0.369s ease",
"font-weight": "bold",
"font-size": "0.69rem",
"box-shadow": "0px 4px 15px rgba(255, 0, 0, 0.569)",
border: "1.169px solid #ff4b2b",
"border-radius": "3.69px",
"background": "linear-gradient(135deg, rgba(255, 69, 0, 0.169), rgba(255, 27, 0, 0.169))",
color: "rgba(255, 69, 0, 1)",
padding: "1.69px 12.69px"
},
info: {
transition: "all 0.369s ease",
"font-weight": "bold",
"font-size": "0.69rem",
"box-shadow": "0px 4px 15px rgba(30, 60, 114, 0.569)",
"border-radius": "3.69px",
"background": "transparent",
color: "rgba(0, 169, 237, 1)",
padding: "1.69px 12.69px"
},
warning: {
transition: "all 0.369s ease",
"font-weight": "bold",
"font-size": "0.69rem",
"box-shadow": "0px 4px 15px rgba(255, 180, 71, 0.569)",
border: "1.169px solid #ffcc33",
"border-radius": "3.69px",
"background": "linear-gradient(135deg, rgba(255, 179, 71, 0.269), rgba(255, 204, 51, 0.269))",
color: "rgba(255, 204, 51, 1)",
padding: "1.69px 12.69px"
},
success: {
transition: "all 0.369s ease",
"font-size": "0.69rem",
"font-weight": "bold",
"border-radius": "3.69px",
"box-shadow": "0px 4px 15px rgba(56, 171, 47, 0.569)",
border: "1.169px solid #a8e063",
"background": "linear-gradient(135deg, rgba(86, 171, 47, 0.269), rgba(168, 224, 99, 0.269))",
color: "#a8e063",
padding: "1.69px 12.69px"
},
debug: {
transition: "all 0.369s ease",
"font-size": "0.6269rem",
"font-weight": "normal",
"box-shadow": "0px 4px 15px rgba(0, 0, 0, 0.269)",
border: "1.169px solid #444",
"border-radius": "3.69px",
"background-color": "#333",
color: "#ccc",
padding: "1.69px 12.69px"
},
"default": {
transition: "all 0.369s ease",
"font-size": "0.569rem",
"font-weight": "normal",
"box-shadow": "0px 4px 15px rgba(0, 0, 0, 0.169)",
border: "1.169px solid #ddd",
"border-radius": "3.69px",
"background-color": "#f7f7f7",
color: "#333",
padding: "1.69px 12.69px"
}
});
_defineProperty(LomlLog, "logLevel", ["debug", "info", "warn", "error", "success"]);
_defineProperty(LomlLog, "loggingEnabled", true);
_defineProperty(LomlLog, "logHistoryLimit", 50);
_defineProperty(LomlLog, "logHistory", []);
_defineProperty(LomlLog, "filters", {
level: null,
keyword: null
});
_defineProperty(LomlLog, "outputDestinations", ["console"]);
;
function lomlLog(message) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
var customStyles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
LomlLog.output(message, type, customStyles, options);
}
;
export { LomlLog, lomlLog };