From de17c8b440cc65f5aae8978ede1d6089b30ef813 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sun, 14 May 2023 15:12:33 +0000 Subject: [PATCH] Added JSON-serialization logic to `FileInfo` --- src/utils/io/file-info.ts | 9 +++++++++ tests/unit/utils/io/file-info.spec.ts | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/utils/io/file-info.ts b/src/utils/io/file-info.ts index 4608555..c8b23d8 100644 --- a/src/utils/io/file-info.ts +++ b/src/utils/io/file-info.ts @@ -134,6 +134,15 @@ export class FileInfo { toString() { return this._path; } + + /** + * Returns the file path. + * + * @returns The file path. + */ + toJSON() { + return this._path; + } } /** diff --git a/tests/unit/utils/io/file-info.spec.ts b/tests/unit/utils/io/file-info.spec.ts index ab71814..3318a41 100644 --- a/tests/unit/utils/io/file-info.spec.ts +++ b/tests/unit/utils/io/file-info.spec.ts @@ -166,6 +166,12 @@ describe("FileInfo", () => { expect(info.toString()).toBe("path/to/test.txt"); }); }); + + test("should be converted to JSON as a file path string", () => { + const info = new FileInfo("path/to/test.txt"); + + expect(JSON.stringify(info)).toBe("\"path/to/test.txt\""); + }); }); describe("fileEquals", () => {