tstosc
Version:
A transpiler that convert TypeScript to SuperCollider's SCLang.
47 lines (44 loc) • 1.34 kB
JavaScript
import ansis from 'ansis';
String.prototype.indent = function(level, char = " ") {
if (this.length == 0 || level == 0) {
return this + "";
}
const indentation = char.repeat(level);
return this.split("\n").map((s) => indentation + s).join("\n");
};
if (!("ansi_length" in String.prototype)) {
Object.defineProperty(String.prototype, "ansi_length", {
get: function() {
return ansis.strip(this.toString()).length;
}
});
}
String.prototype.padANSIStart = function(max_length, char = " ") {
if (char.length > 1) {
throw TypeError(`Padding char ("${char}") should be a char, not a string with length over 1.`);
}
const text = this.toString();
const length = this.ansi_length;
if (length >= max_length) {
return text;
} else {
return `${char.repeat(max_length - length)}${text}`;
}
};
String.prototype.padANSIEnd = function(max_length, char = " ") {
if (char.length > 1) {
throw TypeError(`Padding char ("${char}") should be a char, not a string with length over 1.`);
}
const text = this.toString();
const length = this.ansi_length;
if (length >= max_length) {
return text;
} else {
return `${text}${char.repeat(max_length - length)}`;
}
};
Array.prototype.deduplicated = function() {
return [...new Set(this)];
};
const version = "0.0.1";
export { version };