UNPKG

r3bl-ts-utils

Version:

The `r3bl-ts-utils` package is a set of useful TypeScript functions and classes that can be used in Node.js and browser environments. They are inspired by Kotlin stdlib, and Rust to write code as expressions rather than statements, colorized text, powerfu

144 lines 5.86 kB
"use strict"; /* * Copyright (c) 2022 R3BL LLC. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TextColor = void 0; const lodash_1 = __importDefault(require("lodash")); const kotlin_lang_utils_1 = require("../lang-utils/kotlin-lang-utils"); const colors_1 = require("./colors"); class TextColor { formatFns = new Array(); static get builder() { return new TextColor(); } build = () => Object.assign((text) => this.applyFormatting(text), // Callable via FormatFn signature. this); applyFormatting = (input) => { let copy = input.slice(); this.formatFns.forEach((fn) => (copy = fn(copy))); return copy; }; toString = () => `${this.formatFns.length}`; // From colors.ts. get stripColors() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.stripColors)); } get black() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.black)); } get red() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.red)); } get green() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.green)); } get yellow() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.yellow)); } get blue() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.blue)); } get magenta() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.magenta)); } get cyan() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.cyan)); } get white() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.white)); } get gray() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.gray)); } get grey() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.grey)); } get bgBlack() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.bgBlack)); } get bgRed() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.bgRed)); } get bgGreen() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.bgGreen)); } get bgYellow() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.bgYellow)); } get bgBlue() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.bgBlue)); } get bgMagenta() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.bgMagenta)); } get bgCyan() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.bgCyan)); } get bgWhite() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.bgWhite)); } get reset() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.reset)); } get bold() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.bold)); } get dim() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.dim)); } get italic() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.italic)); } get underline() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.underline)); } get inverse() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.inverse)); } get hidden() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.hidden)); } get strikethrough() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.strikethrough)); } get rainbow() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.rainbow)); } get redwhiteblue() { return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(colors_1.colors.redwhiteblue)); } get randomFgColor() { const randomColor = lodash_1.default.sample([ colors_1.colors.black, colors_1.colors.red, colors_1.colors.green, colors_1.colors.yellow, colors_1.colors.blue, colors_1.colors.magenta, colors_1.colors.cyan, colors_1.colors.white, colors_1.colors.gray, colors_1.colors.grey, ]); return (0, kotlin_lang_utils_1._also)(this, (it) => it.formatFns.push(randomColor)); } } exports.TextColor = TextColor; //# sourceMappingURL=style-builder.js.map