UNPKG

@log-rush/log-formatter

Version:

Parse/Format/Style colored logs

114 lines 3.89 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { DefaultSGREffects, EmptySGREffects } from './types'; var SGRAstNode = /** @class */ (function () { function SGRAstNode(effect, content, next, previous) { this.effect = __assign({}, effect); this.content = content; this.nextNode = next; this.previousNode = previous; } SGRAstNode.prototype.setEffect = function (key, value) { if (key in DefaultSGREffects) { this.effect[key] = value; } return this.clone(); }; SGRAstNode.prototype.setEffects = function (effects) { for (var _i = 0, _a = Object.keys(DefaultSGREffects); _i < _a.length; _i++) { var key = _a[_i]; if (key in effects) { // @ts-ignore this.effect[key] = effects[key]; } } return this.clone(); }; SGRAstNode.prototype.setContent = function (value) { this.content = value; return this.clone(); }; SGRAstNode.prototype.appendContent = function (value) { this.content += value; return this.clone(); }; SGRAstNode.prototype.insertBefore = function (node) { node.nextNode = this; node.previousNode = this.previousNode; this.previousNode = node; return node; }; SGRAstNode.prototype.insertAfter = function (node) { node.previousNode = this; node.nextNode = this.nextNode; this.nextNode = node; return node; }; SGRAstNode.prototype.removeBefore = function () { var _a; var removed = this.previousNode; var temp = (_a = this.previousNode) === null || _a === void 0 ? void 0 : _a.previousNode; this.previousNode = temp; if (this.previousNode) { this.previousNode.nextNode = this; } if (removed) { removed.nextNode = undefined; removed.previousNode = undefined; } return removed; }; SGRAstNode.prototype.removeAfter = function () { var _a; var removed = this.nextNode; var temp = (_a = this.nextNode) === null || _a === void 0 ? void 0 : _a.nextNode; this.nextNode = temp; if (this.nextNode) { this.nextNode.previousNode = this; } if (removed) { removed.nextNode = undefined; removed.previousNode = undefined; } return removed; }; SGRAstNode.prototype.clone = function () { return new SGRAstNode({ weight: this.effect.weight, italic: this.effect.italic, underline: this.effect.underline, foreground: this.effect.foreground, foregroundMode: this.effect.foregroundMode, background: this.effect.background, backgroundMode: this.effect.backgroundMode, blink: this.effect.blink, inverted: this.effect.inverted, crossedOut: this.effect.crossedOut, concealed: this.effect.concealed, }, this.content); }; SGRAstNode.New = function () { return new SGRAstNode(EmptySGREffects, ''); }; SGRAstNode.prototype.New = function () { return SGRAstNode.New(); }; SGRAstNode.Default = function () { return new SGRAstNode(DefaultSGREffects, ''); }; SGRAstNode.prototype.Default = function () { return SGRAstNode.Default(); }; return SGRAstNode; }()); export { SGRAstNode }; //# sourceMappingURL=ast.js.map