@6thbridge/utils 0.3.1-5 → 0.3.3
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.
|
@@ -8,9 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.FileAction = exports.FileSourceOrDestination = exports.FileType = void 0;
|
|
13
16
|
const sync_1 = require("csv-parse/sync");
|
|
17
|
+
const xlsx_1 = __importDefault(require("xlsx"));
|
|
14
18
|
var FileType;
|
|
15
19
|
(function (FileType) {
|
|
16
20
|
FileType["csv"] = "csv";
|
|
@@ -40,11 +44,20 @@ class FileAction {
|
|
|
40
44
|
}
|
|
41
45
|
if (payload.fileType == FileType.csv && payload.destination === FileSourceOrDestination.json) {
|
|
42
46
|
return {
|
|
43
|
-
data: (0, sync_1.parse)(Buffer.from(file).toString(), payload.destinationFileParams)
|
|
47
|
+
data: (0, sync_1.parse)(Buffer.from(file).toString(), payload.destinationFileParams),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if ([FileType.xlsx, FileType.xls].includes(payload.fileType) && payload.destination === FileSourceOrDestination.json) {
|
|
51
|
+
const workbook = xlsx_1.default.read(file);
|
|
52
|
+
const sheetName = workbook.SheetNames[0];
|
|
53
|
+
const worksheet = workbook.Sheets[sheetName];
|
|
54
|
+
const json = xlsx_1.default.utils.sheet_to_json(worksheet, Object.assign({ raw: false, defval: '', blankrows: false }, payload.destinationFileParams));
|
|
55
|
+
return {
|
|
56
|
+
data: json
|
|
44
57
|
};
|
|
45
58
|
}
|
|
46
59
|
return {
|
|
47
|
-
data: file
|
|
60
|
+
data: file,
|
|
48
61
|
};
|
|
49
62
|
});
|
|
50
63
|
}
|
|
@@ -53,14 +66,14 @@ exports.FileAction = FileAction;
|
|
|
53
66
|
// FileAction.convertFile({
|
|
54
67
|
// clientId: 'payfusion',
|
|
55
68
|
// source: FileSourceOrDestination.url,
|
|
56
|
-
// fileType: FileType.
|
|
57
|
-
// sourceFile:
|
|
69
|
+
// fileType: FileType.xlsx,
|
|
70
|
+
// sourceFile: 'https://files.6thbridge.com/public/v1/files/payfusion/content/681ce33e53c13d99a56de437',
|
|
58
71
|
// destination: FileSourceOrDestination.json,
|
|
59
72
|
// destinationFileParams: {
|
|
60
73
|
// columns: true,
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
// }
|
|
74
|
+
// from_line: 6,
|
|
75
|
+
// skip_empty_lines: true,
|
|
76
|
+
// },
|
|
64
77
|
// }).then(console.log)
|
|
65
78
|
// .catch(console.error);
|
|
66
79
|
//# sourceMappingURL=file.action.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.action.js","sourceRoot":"","sources":["../../src/actions/file.action.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file.action.js","sourceRoot":"","sources":["../../src/actions/file.action.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,yCAAuC;AACvC,gDAAwB;AAExB,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,uBAAW,CAAA;IACX,yBAAa,CAAA;IACb,uBAAW,CAAA;AACb,CAAC,EAJW,QAAQ,wBAAR,QAAQ,QAInB;AAED,IAAY,uBAIX;AAJD,WAAY,uBAAuB;IACjC,sCAAW,CAAA;IACX,sCAAW,CAAA;IACX,wCAAa,CAAA;AACf,CAAC,EAJW,uBAAuB,uCAAvB,uBAAuB,QAIlC;AAWD,MAAa,UAAU;IACrB,MAAM,CAAO,cAAc,CAAC,GAAW;;YACrC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;Y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