All files parsable_file.ts

100% Statements 43/43
100% Branches 8/8
100% Functions 10/10
100% Lines 24/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 361x   1x 18x 18x 18x     1x 2x 1x   1x 1x     1x 9x   1x 5x 5x   1x 2x 1x   1x 1x 1x   1x 11x   1x  
import {File} from './file';
 
export class ParseableFile<T = string> extends File {
  get parsedContent(): Promise<T> {
    return (async () => {
      return this.parse(await this.content);
    })();
  }
  stringify(content?: T): string {
    if (typeof content === 'string') return content;
    throw new Error('Unimplemented default stringify.');
  }
  parse(content: string): T {
    return (content as unknown) as T;
  }
  // eslint-disable-next-line
  finalize(content: T, rawContent: string): string {
    return this.stringify(content);
  }
  async write(content?: T): Promise<T> {
    this.readonlyError;
    return this.parse(await super.writeFromString(this.stringify(content)));
  }
  async create(content?: T): Promise<T> {
    this.readonlyError;
    return this.parse(await super.createFromString(this.stringify(content)));
  }
  async upsert(content?: T): Promise<T> {
    this.readonlyError;
    return this.parse(await super.upsertFromString(this.stringify(content)));
  }
  async update(content: T): Promise<T> {
    return this.parse(await this.writeFromString(this.finalize(content, await this.content)));
  }
}