sm-utility 2.2.11 → 2.2.12
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.
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { IExcelParserData } from "../interfaces";
|
|
2
2
|
export declare class ExcelParser {
|
|
3
|
+
/**
|
|
4
|
+
* Parse an excel table into JS objects
|
|
5
|
+
* uploadFolderPath refers to the absolute path of the folder, from the root, that will store the excel file temporarily.
|
|
6
|
+
* This need is a result of the middleware logic stored in the file Upload.middleware.ts of the core api
|
|
7
|
+
* @param data - refers to the data necessary to parse.
|
|
8
|
+
* @returns returns js objects
|
|
9
|
+
*/
|
|
3
10
|
parse<T = any>(data: IExcelParserData): Promise<T[][]>;
|
|
4
11
|
private deleteFile;
|
|
5
12
|
}
|
|
@@ -10,10 +10,17 @@ const path_1 = __importDefault(require("path"));
|
|
|
10
10
|
const sheetExcelParser_1 = require("./sheetExcelParser");
|
|
11
11
|
const logger_1 = require("../../logger");
|
|
12
12
|
class ExcelParser {
|
|
13
|
+
/**
|
|
14
|
+
* Parse an excel table into JS objects
|
|
15
|
+
* uploadFolderPath refers to the absolute path of the folder, from the root, that will store the excel file temporarily.
|
|
16
|
+
* This need is a result of the middleware logic stored in the file Upload.middleware.ts of the core api
|
|
17
|
+
* @param data - refers to the data necessary to parse.
|
|
18
|
+
* @returns returns js objects
|
|
19
|
+
*/
|
|
13
20
|
async parse(data) {
|
|
14
21
|
try {
|
|
15
22
|
logger_1.logger.info("ExcelParser initiated", { context: data });
|
|
16
|
-
const filePath = path_1.default.resolve(data.
|
|
23
|
+
const filePath = path_1.default.resolve(data.uploadFolderPath, `${data.filename}`);
|
|
17
24
|
const sheets = node_xlsx_1.default.parse(filePath);
|
|
18
25
|
const parsedResult = sheets.map((sheet) => new sheetExcelParser_1.SheetExcelParser().parse(sheet));
|
|
19
26
|
await this.deleteFile(filePath);
|
package/excel/interfaces.d.ts
CHANGED