UNPKG

ts-budgie

Version:

Converts TypeScript code to Budgie.

60 lines 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var escapeSpecialCharacters = function (arg) { return arg.replace(/\r/g, "\\r").replace(/\n/g, "\\n"); }; var escapeParenthesis = function (arg) { return arg.replace(/\)/g, "\\)"); }; var textWrapIndicators = new Set(["{", "}", "(", ")", " ", ":"]); /** * Wraps a command argument if it has any spaces. * * @param arg Argument to a GLS command. * @returns The argument, wrapped if necessary. */ var wrapArg = function (arg) { for (var _i = 0, _a = Array.from(textWrapIndicators); _i < _a.length; _i++) { var indicator = _a[_i]; if (arg.indexOf(indicator) !== -1) { return "(" + escapeParenthesis(arg) + ")"; } } return arg; }; /** * Formats a string or recursive GLS command argument. * * @param arg String or recursive GLS command argument. * @returns The formatted argument. */ var formatArg = function (arg) { return (typeof arg === "string" ? escapeSpecialCharacters(wrapArg(arg)) : "{ " + arg + " }"); }; /** * A single line of output GLS. */ var GlsLine = /** @class */ (function () { /** * Initializes a new instance of the GlsLine class. * * @param command GLS command name. * @param args Arguments for the command. */ function GlsLine(command) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } this.command = command; this.args = args; } /** * Creates the GLS syntax equivalent for this line. * * @returns The GLS syntax equivalent for this line. */ GlsLine.prototype.toString = function () { if (this.args.length === 0) { return this.command; } return this.command + " : " + this.args.map(formatArg).join(" "); }; return GlsLine; }()); exports.GlsLine = GlsLine; //# sourceMappingURL=glsLine.js.map