UNPKG

gcash-pdf-parser

Version:

Extract GCash transaction data from PDF statements

64 lines (63 loc) 3.01 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GCashPDFParser = void 0; exports.parseGCashPDF = parseGCashPDF; exports.parseGCashPDFtoCSV = parseGCashPDFtoCSV; exports.parseGCashPDFtoFile = parseGCashPDFtoFile; const GCashPDFParser_1 = require("./parsers/GCashPDFParser"); Object.defineProperty(exports, "GCashPDFParser", { enumerable: true, get: function () { return GCashPDFParser_1.GCashPDFParser; } }); /** * Parses a GCash Transaction History statement in PDF and extracts transaction data * * @param pdfData - The PDF file data as an ArrayBuffer * @param password - The password to decrypt the PDF * @param options - Configuration options (optional) * @returns Promise resolving to parsed transactions */ function parseGCashPDF(pdfData, password, options) { return __awaiter(this, void 0, void 0, function* () { const parser = new GCashPDFParser_1.GCashPDFParser(pdfData, password, options); yield parser.parse(); return parser.getTransactions(); }); } /** * Parses a GCash Transaction History statement in PDF and returns the data as CSV * * @param pdfData - The PDF file data as an ArrayBuffer * @param password - The password to decrypt the PDF * @param options - Configuration options (optional) * @returns Promise resolving to a CSV string containing all extracted transactions */ function parseGCashPDFtoCSV(pdfData, password, options) { return __awaiter(this, void 0, void 0, function* () { const parser = new GCashPDFParser_1.GCashPDFParser(pdfData, password, options); yield parser.parse(); return parser.toCSV(); }); } /** * Parses a GCash Transaction History statement in PDF and saves the results to CSV * * @param pdfData - The PDF file data as an ArrayBuffer * @param password - The password to decrypt the PDF * @param outputPath - Path to save the CSV file (optional) * @param options - Configuration options (optional) * @returns Promise resolving to the path of the saved CSV file */ function parseGCashPDFtoFile(pdfData, password, filename, options) { return __awaiter(this, void 0, void 0, function* () { const parser = new GCashPDFParser_1.GCashPDFParser(pdfData, password, options); yield parser.parse(); return parser.saveCSV(filename); }); }