8 lines
13 KiB
Plaintext
8 lines
13 KiB
Plaintext
{
|
|
"version": 3,
|
|
"sources": ["../src/utils.ts", "../src/index.ts", "../src/browser.ts"],
|
|
"sourcesContent": ["export function chunks(s: string, chunkSize: number): string[] {\n\tconst result = [];\n\tfor (let i = 0; i < s.length; i += chunkSize) {\n\t\tconst chunk = s.slice(i, i + chunkSize);\n\t\tresult.push(chunk);\n\t}\n\treturn result;\n}\n\nexport function fillWithEmpty(array: string[], target_length: number) {\n\tconst a = [...array];\n\twhile (a.length < target_length) {\n\t\ta.push(\"\");\n\t}\n\treturn a;\n}\n\nexport function addLineNumbers(\n\ts: string[],\n\tstart_num: number,\n\tprefix = \"~\"\n): string[] {\n\treturn s.map((l, i) => `${prefix}${start_num + i}${l}`);\n}\n\nexport function removeRepeatingSpace(s: string) {\n\treturn s.replace(/ +/g, \" \");\n}\n", "import {\n\taddLineNumbers,\n\tchunks,\n\tfillWithEmpty,\n\tremoveRepeatingSpace,\n} from \"./utils\";\n\nclass Account {\n\tconstructor(\n\t\tpublic number: string,\n\t\tpublic initial_balance: number,\n\t\tpublic closing_balance: number,\n\t\tpublic currency: string\n\t) {}\n}\n\nclass Transaction {\n\tconstructor(\n\t\tpublic acc_date: Date,\n\t\tpublic op_date: Date,\n\t\tpublic description: string,\n\t\tpublic title: string,\n\t\tpublic person: string,\n\t\tpublic account_number: string,\n\t\tpublic amount: number,\n\t\tpublic balance_after: number\n\t) {}\n\n\tpublic static counter = (function* () {\n\t\tlet c = 1;\n\t\twhile (true) {\n\t\t\tyield c.toString().padStart(11, \"0\");\n\t\t\tc++;\n\t\t}\n\t})();\n\n\tformatTitle() {\n\t\treturn addLineNumbers(\n\t\t\tfillWithEmpty(chunks(this.title.trim(), 27), 9),\n\t\t\t20\n\t\t).join(\"\\n\");\n\t}\n\n\tformatPerson() {\n\t\treturn addLineNumbers(\n\t\t\tfillWithEmpty(\n\t\t\t\tchunks(removeRepeatingSpace(this.person).trim(), 27),\n\t\t\t\t2\n\t\t\t).slice(0, 2),\n\t\t\t32\n\t\t).join(\"\\n\");\n\t}\n\n\ttoMT940() {\n\t\tconst prefixes = { incoming: \"150\", outcoming: \"169\" };\n\t\tconst prefix = this.amount > 0 ? prefixes.incoming : prefixes.outcoming;\n\t\treturn `:61:${mtDate(this.acc_date)}${mtDate(this.op_date).slice(\n\t\t\t2\n\t\t)}C${mtAmount(this.amount)}S${prefix}${Transaction.counter.next().value}\n:86:${prefix}\n:86:${prefix}~00B${prefix}${this.description.slice(0, 23)}\n${this.formatTitle()}\n~29${this.account_number}\n~30${this.account_number.slice(2, 10)}\n~31${this.account_number.slice(10)}\n${this.formatPerson()}\n~34${prefix}\n~38PL${this.account_number}\n~62\n~63`;\n\t}\n}\n\nclass Range {\n\tconstructor(public date_start: Date, public date_end: Date) {}\n}\n\nabstract class CSVParser {\n\tabstract read_csv(content_utf8: string): {\n\t\taccount: Account;\n\t\trange: Range;\n\t\ttransactions: Transaction[];\n\t};\n}\n\nclass mBankParser extends CSVParser {\n\tread_csv(content_utf8: string): {\n\t\taccount: Account;\n\t\trange: Range;\n\t\ttransactions: Transaction[];\n\t} {\n\t\tconst lines = content_utf8.split(\"\\r\\n\").map((line) => line.split(\";\"));\n\t\tlet last = 0;\n\t\twhile (!lines[last][0].startsWith(\"Niniejszy dokument sporz\u0105dzono\")) {\n\t\t\tlast++;\n\t\t}\n\t\tconst account = new Account(\n\t\t\tlines[20][0],\n\t\t\tthis.parseAmount(lines[35][1]),\n\t\t\tthis.parseAmount(lines[last - 2][7]),\n\t\t\tlines[18][0]\n\t\t);\n\t\tconst range = new Range(\n\t\t\tthis.parseDate(lines[14][0]),\n\t\t\tthis.parseDate(lines[14][1])\n\t\t);\n\t\tconst transactions = [];\n\t\tfor (let i = 38; i <= last - 5; i++) {\n\t\t\tconst line = lines[i];\n\t\t\tif (line.length != 9) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Wrong amount of columns! maybe a semicolon got stuck in a transaction description?\"\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst date_acc = new Date(line[0]);\n\t\t\tconst date_op = new Date(line[1]);\n\t\t\tconst [description, title, person, account_number] = line\n\t\t\t\t.slice(2)\n\t\t\t\t.map(this.trimString);\n\t\t\tconst [amount, balance_after] = line\n\t\t\t\t.slice(6)\n\t\t\t\t.map((s) => this.parseAmount(s));\n\t\t\ttransactions.push(\n\t\t\t\tnew Transaction(\n\t\t\t\t\tdate_acc,\n\t\t\t\t\tdate_op,\n\t\t\t\t\tdescription,\n\t\t\t\t\ttitle,\n\t\t\t\t\tperson,\n\t\t\t\t\taccount_number,\n\t\t\t\t\tamount,\n\t\t\t\t\tbalance_after\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn { account, range, transactions };\n\t}\n\n\tparseAmount(s: string): number {\n\t\treturn parseFloat(s.replace(/[^0-9,-]/g, \"\").replace(\",\", \".\"));\n\t}\n\n\tparseDate(s: string): Date {\n\t\tconst [day, month, year] = s.split(\".\").map((s) => parseInt(s));\n\t\tconst d = new Date();\n\t\td.setHours(0);\n\t\td.setMinutes(0);\n\t\td.setSeconds(0);\n\t\td.setMilliseconds(0);\n\t\td.setDate(day);\n\t\td.setMonth(month - 1);\n\t\td.setFullYear(year);\n\t\treturn d;\n\t}\n\n\ttrimString(s: string): string {\n\t\t//removes redundant quotes at the beginning or end of the transaction\n\t\treturn s.replaceAll(/(^[\"']|[\"']$)/g, \"\");\n\t}\n}\n\nfunction mtDate(d: Date) {\n\treturn `${d.getFullYear() - 2000}${(d.getMonth() + 1)\n\t\t.toString()\n\t\t.padStart(2, \"0\")}${d.getDate().toString().padStart(2, \"0\")}`;\n}\n\nfunction mtAmount(n: number) {\n\treturn Math.abs(n).toString().replace(\".\", \",\");\n}\n\nexport function convert(csv_utf8: string): { output: string; range: Range } {\n\tconst result = new mBankParser().read_csv(csv_utf8);\n\tconst { account, transactions, range } = result;\n\tconst string = `:20:MT940\n:25:/PL${account.number.replaceAll(/[^0-9]/g, \"\")}\n:28C:${mtDate(range.date_start)}\n:60F:D${mtDate(range.date_start)}${account.currency}${mtAmount(\n\t\taccount.initial_balance\n\t)}\n${transactions.map((t) => t.toMT940()).join(\"\\n\")}\n:62F:D${mtDate(range.date_end)}${account.currency}${mtAmount(\n\t\taccount.closing_balance\n\t)}`;\n\treturn { output: string, range };\n}\n", "import { convert } from \".\";\n\nfunction download(data: string, filename: string, type: string) {\n\tvar file = new Blob([data], { type: type });\n\tvar a = document.createElement(\"a\"),\n\t\turl = URL.createObjectURL(file);\n\ta.href = url;\n\ta.download = filename;\n\tdocument.body.appendChild(a);\n\ta.click();\n\tsetTimeout(function () {\n\t\tdocument.body.removeChild(a);\n\t\twindow.URL.revokeObjectURL(url);\n\t}, 0);\n}\n\nasync function handle() {\n\tconsole.log(\"browser.ts:2\");\n\tconst csv_input = document.getElementById(\"csv\");\n\tif (!csv_input || !(csv_input instanceof HTMLInputElement)) {\n\t\tconsole.log(\"browser.ts:5\");\n\t\tthrow new Error(\"coudl not find the csv input\");\n\t}\n\tvar fileName = csv_input.value.replace(\"C:\\\\fakepath\\\\\", \"\");\n\tconst files = csv_input.files;\n\tif (!files) {\n\t\tthrow new Error(\"no files in the input\");\n\t}\n\tconst buffer = await files[0].arrayBuffer();\n\tconst string = new TextDecoder(\"windows-1250\").decode(buffer);\n\tconst result = convert(string);\n\tdownload(\n\t\tresult.output,\n\t\t`raport-${result.range.date_start.getFullYear()}-${(\n\t\t\tresult.range.date_start.getMonth() + 1\n\t\t)\n\t\t\t.toString()\n\t\t\t.padStart(2, \"0\")}.mt940`,\n\t\t\"text\"\n\t);\n}\n\ndocument.querySelector(\"#submit\")?.addEventListener(\"click\", handle);\nconsole.log(\"added handler to\", document.querySelector(\"#submit\"));\n"],
|
|
"mappings": "MAAO,SAASA,EAAOC,EAAWC,EAA6B,CAC9D,IAAMC,EAAS,CAAC,EAChB,QAASC,EAAI,EAAGA,EAAIH,EAAE,OAAQG,GAAKF,EAAW,CAC7C,IAAMG,EAAQJ,EAAE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ACxC,cAAQ,IAAI,cAAc,EACpB,IAAI,MAAM,8BAA8B,EAE/C,IAAIC,EAAWD,EAAU,MAAM,QAAQ,iBAAkB,EAAE,EAC3D,IAAME,EAAQF,EAAU,MACxB,GAAI,CAACE,EACJ,MAAM,IAAI,MAAM,uBAAuB,EAExC,IAAMC,EAAS,MAAMD,EAAM,CAAC,EAAE,YAAY,EACpCE,EAAS,IAAI,YAAY,cAAc,EAAE,OAAOD,CAAM,EACtDE,EAASC,EAAQF,CAAM,EAC7BZ,EACCa,EAAO,OACP,UAAUA,EAAO,MAAM,WAAW,YAAY,CAAC,KAC9CA,EAAO,MAAM,WAAW,SAAS,EAAI,GAEpC,SAAS,EACT,SAAS,EAAG,GAAG,CAAC,SAClB,MACD,CACD,CAEA,SAAS,cAAc,SAAS,GAAG,iBAAiB,QAASN,CAAM,EACnE,QAAQ,IAAI,mBAAoB,SAAS,cAAc,SAAS,CAAC",
|
|
"names": ["chunks", "s", "chunkSize", "result", "i", "chunk", "fillWithEmpty", "array", "target_length", "a", "addLineNumbers", "start_num", "prefix", "l", "removeRepeatingSpace", "Account", "number", "initial_balance", "closing_balance", "currency", "Transaction", "_Transaction", "acc_date", "op_date", "description", "title", "person", "account_number", "amount", "balance_after", "c", "addLineNumbers", "fillWithEmpty", "chunks", "removeRepeatingSpace", "prefixes", "prefix", "mtDate", "mtAmount", "Range", "date_start", "date_end", "CSVParser", "mBankParser", "content_utf8", "lines", "line", "last", "account", "range", "transactions", "i", "date_acc", "date_op", "s", "day", "month", "year", "d", "n", "convert", "csv_utf8", "result", "t", "download", "data", "filename", "type", "file", "a", "url", "handle", "csv_input", "fileName", "files", "buffer", "string", "result", "convert"]
|
|
}
|