UNPKG

@microsoft.azure/autorest.incubator

Version:
75 lines 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const initializer_1 = require("../common/initializer"); const text_manipulation_1 = require("../common/text-manipulation"); function isText(object) { return object.text ? true : false; } exports.isText = isText; function isTextEdit(object) { return object.edit ? true : false; } exports.isTextEdit = isTextEdit; class Text extends initializer_1.Initializer { constructor(content, objectIntializer) { super(); this.content = new Array(); this.toString = () => { return this.text; }; if (content) { this.add(content); } this.apply(objectIntializer); } get count() { return this.content.length; } add(text) { if (typeof (text) === 'string') { this.content.push(text); return this; } if (text instanceof Text) { this.content.push(text); return this; } if (isText(text) || isTextEdit(text)) { this.content.push(text); return this; } if (typeof (text) === 'function') { return this.add(text()); } for (const each of text) { this.add(each); } return this; } get text() { let output = ''; for (const each of this.content) { if (typeof (each) === 'string') { output = output + text_manipulation_1.EOL + each; continue; } if (isTextEdit(each)) { output = each.edit(output) + text_manipulation_1.EOL; continue; } output = output + text_manipulation_1.EOL + each.text; } return output; } removeRegion(region) { this.add({ edit: (s) => text_manipulation_1.setRegion(s, region, '') }); } setRegion(region, content, prepend = true) { this.add({ edit: (s) => text_manipulation_1.setRegion(s, region, content, prepend) }); } trim() { this.add({ edit: (s) => s.trim() }); } } exports.Text = Text; //# sourceMappingURL=file-generator.js.map