From 43183ef9b9c0d64bfa8ce6236c5639d97296e957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Jab=C5=82o=C5=84ski?= Date: Sun, 10 Aug 2025 11:28:34 +0200 Subject: [PATCH] style: apply wider print width for all files --- .arcconfig | 17 ++++----- .prettierrc | 27 ++++---------- src/browser.ts | 4 +-- src/index.test.ts | 36 ++++++------------- src/index.ts | 91 +++++++++++------------------------------------ src/utils.ts | 6 +--- 6 files changed, 45 insertions(+), 136 deletions(-) diff --git a/.arcconfig b/.arcconfig index 29fbdca..9364130 100644 --- a/.arcconfig +++ b/.arcconfig @@ -1,12 +1,7 @@ { - "phabricator.uri": "https://hub.sealcode.org/", - "arc.land.onto.default": "hotwire", - "load": [ - "arcanist-linters", - "arc-unit-mocha/src" - ], - "unit.engine": "MochaEngine", - "unit.mocha.include": [ - ".test/**/*.ts" - ] -} \ No newline at end of file + "phabricator.uri": "https://hub.sealcode.org/", + "arc.land.onto.default": "hotwire", + "load": ["arcanist-linters", "arc-unit-mocha/src"], + "unit.engine": "MochaEngine", + "unit.mocha.include": [".test/**/*.ts"] +} diff --git a/.prettierrc b/.prettierrc index 01534ca..ad21c0d 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,22 +1,7 @@ { - "useTabs": true, - "tabWidth": 4, - "trailingComma": "es5", - "printWidth": 100, - "overrides": [ - { - "files": "*.yml", - "options": { - "tabWidth": 2, - "useTabs": false - } - }, - { - "files": "*.html", - "options": { - "printWidth": 120, - "htmlWhitespaceSensitivity": "ignore" - } - } - ] -} \ No newline at end of file + "useTabs": true, + "tabWidth": 4, + "trailingComma": "es5", + "printWidth": 120, + "htmlWhitespaceSensitivity": "ignore" +} diff --git a/src/browser.ts b/src/browser.ts index 2f18e68..995b372 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -30,9 +30,7 @@ async function handle() { const result = convert(string); download( result.output, - `raport-${result.range.date_start.getFullYear()}-${( - result.range.date_start.getMonth() + 1 - ) + `raport-${result.range.date_start.getFullYear()}-${(result.range.date_start.getMonth() + 1) .toString() .padStart(2, "0")}.mt940`, "text" diff --git a/src/index.test.ts b/src/index.test.ts index e979186..76f3d18 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -7,47 +7,31 @@ import * as Diff from "diff"; describe("mt940 converter", () => { it("converts properly", async () => { - const content = await fs.readFile( - path.resolve(__dirname, "../tests/real_csv.csv"), - { - encoding: null, - } - ); + const content = await fs.readFile(path.resolve(__dirname, "../tests/real_csv.csv"), { + encoding: null, + }); const result = convert(iconv.decode(content, "cp1250")); - const expected_result = await fs.readFile( - path.resolve(__dirname, "../tests/real_mt940.txt"), - "utf-8" - ); + const expected_result = await fs.readFile(path.resolve(__dirname, "../tests/real_mt940.txt"), "utf-8"); try { assert.strictEqual(result.output, expected_result); } catch (e) { console.error("There was a difference. Fixes to apply:"); - console.log( - Diff.createPatch("mt940", result.output, expected_result) - ); + console.log(Diff.createPatch("mt940", result.output, expected_result)); throw new Error("Texts differ"); } }); it.only("converts properly", async () => { - const content = await fs.readFile( - path.resolve(__dirname, "../tests/real_csv_2.csv"), - { - encoding: null, - } - ); + const content = await fs.readFile(path.resolve(__dirname, "../tests/real_csv_2.csv"), { + encoding: null, + }); const result = convert(iconv.decode(content, "cp1250")); - const expected_result = await fs.readFile( - path.resolve(__dirname, "../tests/real_mt940_2.txt"), - "utf-8" - ); + const expected_result = await fs.readFile(path.resolve(__dirname, "../tests/real_mt940_2.txt"), "utf-8"); try { assert.strictEqual(result.output, expected_result); } catch (e) { console.error("There was a difference. Fixes to apply:"); - console.log( - Diff.createPatch("mt940", result.output, expected_result) - ); + console.log(Diff.createPatch("mt940", result.output, expected_result)); throw new Error("Texts differ"); } }); diff --git a/src/index.ts b/src/index.ts index 8ec5bbe..61266f6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,4 @@ -import { - addLineNumbers, - chunks, - fillWithEmpty, - removeRepeatingSpace, -} from "./utils"; +import { addLineNumbers, chunks, fillWithEmpty, removeRepeatingSpace } from "./utils"; class Account { constructor( @@ -35,18 +30,12 @@ class Transaction { })(); formatTitle() { - return addLineNumbers( - fillWithEmpty(chunks(this.title.trim(), 27), 9), - 20 - ).join("\n"); + return addLineNumbers(fillWithEmpty(chunks(this.title.trim(), 27), 9), 20).join("\n"); } formatPerson() { const ret = addLineNumbers( - fillWithEmpty( - chunks(removeRepeatingSpace(this.person).trim(), 27), - 2 - ).slice(0, 2), + fillWithEmpty(chunks(removeRepeatingSpace(this.person).trim(), 27), 2).slice(0, 2), 32 ).join("\n"); return ret; @@ -55,26 +44,11 @@ class Transaction { toMT940() { // just a bunch of heuristics const prefix_fns = [ - () => - this.description.includes("OPŁATA-PRZELEW WEWN.") - ? "169" - : false, - () => - this.description.includes("PRZELEW WEWNĘTRZNY PRZY") - ? "160" - : false, - () => - this.description.includes("OPŁATA-PRZELEW WEWN. DO") - ? "755" - : false, - () => - this.description.includes("PRZELEW ZEWNĘTRZNY WYCH") - ? "152" - : false, - () => - this.description.includes("OPŁATA PRZELEW ZEW.DOWO") - ? "771" - : false, + () => (this.description.includes("OPŁATA-PRZELEW WEWN.") ? "169" : false), + () => (this.description.includes("PRZELEW WEWNĘTRZNY PRZY") ? "160" : false), + () => (this.description.includes("OPŁATA-PRZELEW WEWN. DO") ? "755" : false), + () => (this.description.includes("PRZELEW ZEWNĘTRZNY WYCH") ? "152" : false), + () => (this.description.includes("OPŁATA PRZELEW ZEW.DOWO") ? "771" : false), () => (this.amount > 0 ? "150" : false), () => "169", ]; @@ -86,11 +60,9 @@ class Transaction { break; } } - const result = `:61:${mtDate(this.acc_date)}${mtDate( - this.op_date - ).slice(2)}${this.amount > 0 ? "C" : "D"}${mtAmount( - this.amount - )}S${prefix}${Transaction.counter.next().value} + const result = `:61:${mtDate(this.acc_date)}${mtDate(this.op_date).slice(2)}${ + this.amount > 0 ? "C" : "D" + }${mtAmount(this.amount)}S${prefix}${Transaction.counter.next().value} :86:${prefix} :86:${prefix}~00B${prefix}${this.description.slice(0, 23)} ${this.formatTitle()} @@ -135,10 +107,7 @@ class mBankParser extends CSVParser { this.parseAmount(lines[last - 2][7]), lines[18][0] ); - const range = new Range( - this.parseDate(lines[14][0]), - this.parseDate(lines[14][1]) - ); + const range = new Range(this.parseDate(lines[14][0]), this.parseDate(lines[14][1])); const transactions = []; for (let i = 38; i <= last - 5; i++) { const line = lines[i]; @@ -148,29 +117,14 @@ class mBankParser extends CSVParser { } if (line.length != 9) { console.log({ line }); - throw new Error( - "Wrong amount of columns! maybe a semicolon got stuck in a transaction description?" - ); + throw new Error("Wrong amount of columns! maybe a semicolon got stuck in a transaction description?"); } const date_acc = new Date(line[0]); const date_op = new Date(line[1]); - const [description, title, person, account_number] = line - .slice(2) - .map(this.trimString); - const [amount, balance_after] = line - .slice(6) - .map((s) => this.parseAmount(s)); + const [description, title, person, account_number] = line.slice(2).map(this.trimString); + const [amount, balance_after] = line.slice(6).map((s) => this.parseAmount(s)); transactions.push( - new Transaction( - date_acc, - date_op, - description, - title, - person, - account_number, - amount, - balance_after - ) + new Transaction(date_acc, date_op, description, title, person, account_number, amount, balance_after) ); } return { account, range, transactions }; @@ -200,9 +154,10 @@ class mBankParser extends CSVParser { } function mtDate(d: Date) { - return `${d.getFullYear() - 2000}${(d.getMonth() + 1) + return `${d.getFullYear() - 2000}${(d.getMonth() + 1).toString().padStart(2, "0")}${d + .getDate() .toString() - .padStart(2, "0")}${d.getDate().toString().padStart(2, "0")}`; + .padStart(2, "0")}`; } function mtAmount(n: number) { @@ -215,12 +170,8 @@ export function convert(csv_utf8: string): { output: string; range: Range } { const string = `:20:MT940 :25:/PL${account.number.replaceAll(/[^0-9]/g, "")} :28C:${mtDate(range.date_start)} -:60F:D${mtDate(range.date_start)}${account.currency}${mtAmount( - account.initial_balance - )} +:60F:D${mtDate(range.date_start)}${account.currency}${mtAmount(account.initial_balance)} ${transactions.map((t) => t.toMT940()).join("\n")} -:62F:D${mtDate(range.date_end)}${account.currency}${mtAmount( - account.closing_balance - )}`; +:62F:D${mtDate(range.date_end)}${account.currency}${mtAmount(account.closing_balance)}`; return { output: string, range }; } diff --git a/src/utils.ts b/src/utils.ts index 41e3d3b..b21e1ba 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -15,11 +15,7 @@ export function fillWithEmpty(array: string[], target_length: number) { return a; } -export function addLineNumbers( - s: string[], - start_num: number, - prefix = "~" -): string[] { +export function addLineNumbers(s: string[], start_num: number, prefix = "~"): string[] { return s.map((l, i) => `${prefix}${start_num + i}${l}`); }