export type ICell = number | string | String | Cell;
export type Direction = "left" | "right" | "center";
export interface ICellOptions { border?: boolean; colSpan?: number; rowSpan?: number; align?: Direction;}
export class Cell { protected options: ICellOptions = {};
public get length(): number { return this.toString().length; }
public static from(value: ICell): Cell { const cell = new this(value); if (value instanceof Cell) { cell.options = { ...value.options }; } return cell; }
public constructor(private value: ICell) {}
public toString(): string { return this.value.toString(); }
public setValue(value: ICell): this { this.value = value; return this; }
public clone(value?: ICell): Cell { const cell = new Cell(value ?? this); cell.options = { ...this.options }; return cell; }
public border(enable: boolean, override = true): this { if (override || typeof this.options.border === "undefined") { this.options.border = enable; } return this; }
public colSpan(span: number, override = true): this { if (override || typeof this.options.colSpan === "undefined") { this.options.colSpan = span; } return this; }
public rowSpan(span: number, override = true): this { if (override || typeof this.options.rowSpan === "undefined") { this.options.rowSpan = span; } return this; }
public align(direction: Direction, override = true): this { if (override || typeof this.options.align === "undefined") { this.options.align = direction; } return this; }
public getBorder(): boolean { return this.options.border === true; }
public getColSpan(): number { return typeof this.options.colSpan === "number" && this.options.colSpan > 0 ? this.options.colSpan : 1; }
public getRowSpan(): number { return typeof this.options.rowSpan === "number" && this.options.rowSpan > 0 ? this.options.rowSpan : 1; }
public getAlign(): Direction { return this.options.align ?? "left"; }}