kaven-utils
Version:
Utils for Node.js.
41 lines (40 loc) • 1.37 kB
JavaScript
/********************************************************************
* @author: Kaven
* @email: kaven@wuwenkai.com
* @website: http://blog.kaven.xyz
* @file: [Kaven-Utils] /src/KavenMarkdown.ts
* @create: 2021-08-31 18:19:54.534
* @modify: 2023-11-25 22:38:33.047
* @version: 5.0.7
* @times: 21
* @lines: 52
* @copyright: Copyright © 2021-2023 Kaven. All Rights Reserved.
* @description: [description]
* @license: [license]
********************************************************************/
import { MarkdownSection } from "kaven-basic";
import { GetFileLines, SaveStringToFile } from "./KavenUtility.FileSystem.js";
export class KavenMarkdown {
File;
EndOfLineSequence;
Section;
constructor(file) {
this.File = file;
}
async Load() {
if (this.Section !== undefined) {
return this.Section;
}
const { endOfLineSequence, lines } = await GetFileLines(this.File);
this.EndOfLineSequence = endOfLineSequence;
this.Section = MarkdownSection.Parse(lines);
return this.Section;
}
async Save(path, ms) {
ms = ms ?? this.Section;
if (ms !== undefined) {
const lines = ms.GetLines();
await SaveStringToFile(lines.join(this.EndOfLineSequence), path);
}
}
}