@mdgf11/filesystem-lib 2.2.15 → 2.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,10 @@ import { JurisprudenciaDocument, PartialJurisprudenciaDocument } from "@stjiris/
2
2
  import { ContentType, FilesystemDocument } from "./types.js";
3
3
  export declare function writeFilesystemDocument(filesystem_document: FilesystemDocument): void;
4
4
  export declare function loadFilesystemDocument(jsonPath: string): FilesystemDocument;
5
+ export type DocumentFileType = "nlp" | "details" | "pdf" | "docx" | "txt";
6
+ export declare function loadDocumentFile(doc: PartialJurisprudenciaDocument, type: "nlp" | "details"): string;
7
+ export declare function loadDocumentFile(doc: PartialJurisprudenciaDocument, type: "pdf" | "docx" | "txt"): Buffer;
8
+ /** @deprecated use loadDocumentFile(doc, "nlp") instead */
5
9
  export declare function loadNlpDocument(jurisprudencia_document: JurisprudenciaDocument): string;
6
10
  export declare function hasSelectableText(buffer: Buffer): Promise<boolean>;
7
11
  export declare function generateFilePath(jurisprudencia_document: PartialJurisprudenciaDocument): string;
@@ -54,8 +54,19 @@ export function loadFilesystemDocument(jsonPath) {
54
54
  }))
55
55
  };
56
56
  }
57
+ export function loadDocumentFile(doc, type) {
58
+ const dirPath = `${ROOT_PATH}${FILESYSTEM_PATH}${generateFilePath(doc)}`;
59
+ if (type === "nlp") {
60
+ return fs.readFileSync(`${dirPath}/${ORIGINAL_NAME}.json`, "utf-8");
61
+ }
62
+ if (type === "details") {
63
+ return fs.readFileSync(`${dirPath}/${DETAILS_NAME}.json`, "utf-8");
64
+ }
65
+ return fs.readFileSync(`${dirPath}/${ORIGINAL_NAME}.${type}`);
66
+ }
67
+ /** @deprecated use loadDocumentFile(doc, "nlp") instead */
57
68
  export function loadNlpDocument(jurisprudencia_document) {
58
- return fs.readFileSync(`${generateFilePath(jurisprudencia_document)}/${ORIGINAL_NAME}.json`, 'utf-8');
69
+ return loadDocumentFile(jurisprudencia_document, "nlp");
59
70
  }
60
71
  export async function hasSelectableText(buffer) {
61
72
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdgf11/filesystem-lib",
3
- "version": "2.2.15",
3
+ "version": "2.2.17",
4
4
  "description": "Library to extend usage of jurisprudencia-document",
5
5
  "license": "ISC",
6
6
  "author": "Miguel Fonseca",
@@ -63,10 +63,24 @@ export function loadFilesystemDocument(jsonPath: string): FilesystemDocument {
63
63
  };
64
64
  }
65
65
 
66
- export function loadNlpDocument(jurisprudencia_document: JurisprudenciaDocument): string {
67
-
68
- return fs.readFileSync(`${generateFilePath(jurisprudencia_document)}/${ORIGINAL_NAME}.json`, 'utf-8');
66
+ export type DocumentFileType = "nlp" | "details" | "pdf" | "docx" | "txt";
67
+
68
+ export function loadDocumentFile(doc: PartialJurisprudenciaDocument, type: "nlp" | "details"): string;
69
+ export function loadDocumentFile(doc: PartialJurisprudenciaDocument, type: "pdf" | "docx" | "txt"): Buffer;
70
+ export function loadDocumentFile(doc: PartialJurisprudenciaDocument, type: DocumentFileType): string | Buffer {
71
+ const dirPath = `${ROOT_PATH}${FILESYSTEM_PATH}${generateFilePath(doc)}`;
72
+ if (type === "nlp") {
73
+ return fs.readFileSync(`${dirPath}/${ORIGINAL_NAME}.json`, "utf-8");
74
+ }
75
+ if (type === "details") {
76
+ return fs.readFileSync(`${dirPath}/${DETAILS_NAME}.json`, "utf-8");
77
+ }
78
+ return fs.readFileSync(`${dirPath}/${ORIGINAL_NAME}.${type}`);
79
+ }
69
80
 
81
+ /** @deprecated use loadDocumentFile(doc, "nlp") instead */
82
+ export function loadNlpDocument(jurisprudencia_document: JurisprudenciaDocument): string {
83
+ return loadDocumentFile(jurisprudencia_document, "nlp");
70
84
  }
71
85
 
72
86
  export async function hasSelectableText(buffer: Buffer): Promise<boolean> {