Modifier.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const colorette_1 = __importDefault(require("colorette"));
  7. const utils_1 = require("./utils");
  8. function modifier(ansiModifier, ...children) {
  9. return new Modifier(ansiModifier, utils_1.toArray(children));
  10. }
  11. exports.modifier = modifier;
  12. class Modifier {
  13. constructor(ansiModifier, children) {
  14. this.modifier = ansiModifier;
  15. this.children = children;
  16. }
  17. build() {
  18. const children = utils_1.buildChildren(this.children);
  19. if (this.modifier === 'none') {
  20. return children;
  21. }
  22. else if (this.modifier in colorette_1.default) {
  23. // tslint:disable-next-line: no-unsafe-any no-any
  24. return colorette_1.default[this.modifier](children);
  25. }
  26. throw new Error(`Modifier ${this.modifier} not found`);
  27. }
  28. }
  29. exports.Modifier = Modifier;
  30. //# sourceMappingURL=Modifier.js.map