50 lines
736 B
JavaScript
50 lines
736 B
JavaScript
|
import { chars } from '../utils.ts';
|
||
|
|
||
|
export class Row {
|
||
|
chars: string[] = [];
|
||
|
|
||
|
constructor(s: string = '') {
|
||
|
this.chars = chars(s);
|
||
|
}
|
||
|
|
||
|
public toString(): string {
|
||
|
return this.chars.join('');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export class Document {
|
||
|
#rows: Row[];
|
||
|
|
||
|
private constructor() {
|
||
|
this.#rows = [];
|
||
|
}
|
||
|
|
||
|
get numrows(): number {
|
||
|
return this.#rows.length;
|
||
|
}
|
||
|
|
||
|
public static empty(): Document {
|
||
|
return new Document();
|
||
|
}
|
||
|
|
||
|
public static open(): Document {
|
||
|
const doc = new Document();
|
||
|
const line = 'Hello, World!';
|
||
|
const row = new Row(line);
|
||
|
|
||
|
doc.#rows.push(row);
|
||
|
|
||
|
return doc;
|
||
|
}
|
||
|
|
||
|
public getRow(i: number): Row | null {
|
||
|
if (this.#rows[i] !== undefined) {
|
||
|
return this.#rows[i];
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default Document;
|