xstate-plantuml
Version:
Visualize a xstate or react-automata statechart as a plantuml state diagram
40 lines (30 loc) • 641 B
JavaScript
class Buffer {
constructor() {
this.value = '';
this.indentation = 0;
}
get whitespace() {
return new Array(this.indentation + 1).join(' ');
}
indent() {
this.indentation++;
}
dedent() {
this.indentation--;
}
newline() {
this.value += '\n';
}
append(value) {
this.value += this.whitespace + value + '\n';
}
appendf(strings, ...values) {
const sanitize = (value = '') =>
value.replace(/[\(\)]/g, '').replace(/-/g, '_');
const value = strings
.map((str, i) => str + sanitize(values[i]))
.join('');
this.append(value);
}
}
module.exports = Buffer;