public getUpdatedContent()

in src/Updater.ts [135:159]


  public getUpdatedContent(dumpOptions = this.dumpOptions): string | Buffer {
    if (this.content === undefined) {
      throw new NotLoadedMetadataError();
    }

    let markdown: string;
    let isBuffer = true;
    if (typeof this.content !== "string") {
      markdown = this.content.toString();
    } else {
      markdown = this.content;
      isBuffer = false;
    }

    const regex = /(---)[\S\s\w\W]*?(---)/;
    const replacedMarkdown = markdown.replace(
      regex,
      `$1\n${this.dump(dumpOptions)}$2`
    );

    if (isBuffer) {
      return Buffer.from(replacedMarkdown);
    }
    return replacedMarkdown;
  }