UNPKG

@ts-common/azure-js-dev-tools

Version:

Developer dependencies for TypeScript related projects

80 lines 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.repeatText = exports.create = exports.TextBuilder = void 0; var tslib_1 = require("tslib"); /** * A TextBuilder that can be used to build up a large string. */ var TextBuilder = /** @class */ (function () { function TextBuilder(text) { this.text = text || ""; } /** * Append the provided value to this TextBuilder's text. * @param value The value to append. */ TextBuilder.prototype.append = function (value) { this.text += value; return this; }; TextBuilder.prototype.appendLine = function (value) { if (value) { this.append(value); } return this.append("\n"); }; /** * Get the text that this TextBuilder has been building. */ TextBuilder.prototype.toString = function () { return this.text; }; return TextBuilder; }()); exports.TextBuilder = TextBuilder; /** * Create an element using the provided builder and actions. * @param builder The builder to create. * @param actions The actions to use to create the builder's element. */ function create(builder, actions) { var e_1, _a; builder.start(); if (actions) { if (typeof actions === "string" || typeof actions === "function") { actions = [actions]; } try { for (var actions_1 = tslib_1.__values(actions), actions_1_1 = actions_1.next(); !actions_1_1.done; actions_1_1 = actions_1.next()) { var action = actions_1_1.value; if (action) { if (typeof action === "string") { builder.content(action); } else if (typeof action === "function") { action(builder); } } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1); } finally { if (e_1) throw e_1.error; } } } builder.end(); return builder.toString(); } exports.create = create; function repeatText(text, count) { var result = ""; for (var i = 0; i < count; ++i) { result += text; } return result; } exports.repeatText = repeatText; //# sourceMappingURL=textBuilder.js.map