@tasenor/common-plugins 1.9.16

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.
Files changed (114) hide show
  1. package/.eslintrc.js +4 -0
  2. package/.turbo/turbo-fix.log +4 -0
  3. package/.turbo/turbo-lint.log +4 -0
  4. package/.turbo/turbo-version.log +5 -0
  5. package/LICENSE +21 -0
  6. package/README.md +15 -0
  7. package/data/FinnishBalanceSheetReport.mjs +9 -0
  8. package/data/FinnishBalanceSheetReportInvestment.mjs +11 -0
  9. package/data/FinnishBalanceSheetReportLite.mjs +9 -0
  10. package/data/FinnishIncomeStatementReport.mjs +9 -0
  11. package/data/FinnishIncomeStatementReportInvestment.mjs +11 -0
  12. package/data/FinnishIncomeStatementReportLite.mjs +9 -0
  13. package/data/FinnishInvestmentCompany.mjs +5 -0
  14. package/data/FinnishLimitedCompanyComplete.mjs +5 -0
  15. package/data/FinnishLimitedCompanyLite.mjs +9 -0
  16. package/data/IncomeAndExpenses.mjs +64 -0
  17. package/data/README.md +8 -0
  18. package/data/VATFinland.mjs +22 -0
  19. package/data/bin/build_all +11 -0
  20. package/data/lib/utils.mjs +314 -0
  21. package/data/src/Assets Tree - Definitions.tsv +101 -0
  22. package/data/src/Expense Tree - Definitions.tsv +99 -0
  23. package/data/src/Finland VAT - Definitions.tsv +22 -0
  24. package/data/src/FinnishBalanceSheetReport - balance-sheet-detailed-fi.tsv +215 -0
  25. package/data/src/FinnishBalanceSheetReport - balance-sheet-fi.tsv +93 -0
  26. package/data/src/FinnishBalanceSheetReportInvestment - balance-sheet-detailed-fi.tsv +100 -0
  27. package/data/src/FinnishBalanceSheetReportInvestment - balance-sheet-fi.tsv +52 -0
  28. package/data/src/FinnishBalanceSheetReportLite - balance-sheet-en.tsv +21 -0
  29. package/data/src/FinnishBalanceSheetReportLite - balance-sheet-fi.tsv +21 -0
  30. package/data/src/FinnishBalanceSheetReportLite - balance-sheet-lite-en.tsv +21 -0
  31. package/data/src/FinnishBalanceSheetReportLite - balance-sheet-lite-fi.tsv +21 -0
  32. package/data/src/FinnishIncomeStatementReport - income-statement-detailed-fi.tsv +118 -0
  33. package/data/src/FinnishIncomeStatementReport - income-statement-fi.tsv +45 -0
  34. package/data/src/FinnishIncomeStatementReportInvestment - income-statement-detailed-fi.tsv +96 -0
  35. package/data/src/FinnishIncomeStatementReportInvestment - income-statement-fi.tsv +39 -0
  36. package/data/src/FinnishIncomeStatementReportLite - income-statement-lite-en.tsv +23 -0
  37. package/data/src/FinnishIncomeStatementReportLite - income-statement-lite-fi.tsv +23 -0
  38. package/data/src/FinnishInvestmentCompany - fi-EUR.tsv +722 -0
  39. package/data/src/FinnishLimitedCompanyComplete - fi-EUR.tsv +1086 -0
  40. package/data/src/FinnishLimitedCompanyLite - en-EUR.tsv +97 -0
  41. package/data/src/FinnishLimitedCompanyLite - fi-EUR.tsv +99 -0
  42. package/data/src/Income Tree - Definitions.tsv +60 -0
  43. package/data/src/Tax Types - Definitions.tsv +11 -0
  44. package/package.json +51 -0
  45. package/src/CoinAPI/backend/index.ts +102 -0
  46. package/src/CoinbaseImport/backend/CoinbaseHandler.ts +35 -0
  47. package/src/CoinbaseImport/backend/index.ts +24 -0
  48. package/src/CoinbaseImport/backend/rules.json +64 -0
  49. package/src/DocumentCleaner/ui/index.tsx +165 -0
  50. package/src/Euro/ui/index.tsx +27 -0
  51. package/src/Finnish/ui/finnish.json +341 -0
  52. package/src/Finnish/ui/index.tsx +54 -0
  53. package/src/FinnishBalanceSheetReport/backend/balance-sheet-detailed-fi.tsv +215 -0
  54. package/src/FinnishBalanceSheetReport/backend/balance-sheet-fi.tsv +93 -0
  55. package/src/FinnishBalanceSheetReport/backend/index.ts +107 -0
  56. package/src/FinnishBalanceSheetReportInvestment/backend/balance-sheet-investment-detailed-fi.tsv +100 -0
  57. package/src/FinnishBalanceSheetReportInvestment/backend/balance-sheet-investment-fi.tsv +52 -0
  58. package/src/FinnishBalanceSheetReportInvestment/backend/index.ts +107 -0
  59. package/src/FinnishBalanceSheetReportLite/backend/balance-sheet-lite-en.tsv +21 -0
  60. package/src/FinnishBalanceSheetReportLite/backend/balance-sheet-lite-fi.tsv +21 -0
  61. package/src/FinnishBalanceSheetReportLite/backend/index.ts +121 -0
  62. package/src/FinnishIncomeStatementReport/backend/income-statement-detailed-fi.tsv +118 -0
  63. package/src/FinnishIncomeStatementReport/backend/income-statement-fi.tsv +45 -0
  64. package/src/FinnishIncomeStatementReport/backend/index.ts +212 -0
  65. package/src/FinnishIncomeStatementReportInvestment/backend/income-statement-detailed-fi.tsv +118 -0
  66. package/src/FinnishIncomeStatementReportInvestment/backend/income-statement-fi.tsv +45 -0
  67. package/src/FinnishIncomeStatementReportInvestment/backend/income-statement-investment-detailed-fi.tsv +96 -0
  68. package/src/FinnishIncomeStatementReportInvestment/backend/income-statement-investment-fi.tsv +39 -0
  69. package/src/FinnishIncomeStatementReportInvestment/backend/index.ts +212 -0
  70. package/src/FinnishIncomeStatementReportLite/backend/income-statement-lite-en.tsv +23 -0
  71. package/src/FinnishIncomeStatementReportLite/backend/income-statement-lite-fi.tsv +23 -0
  72. package/src/FinnishIncomeStatementReportLite/backend/index.ts +210 -0
  73. package/src/FinnishInvestmentCompany/backend/fi-EUR.tsv +722 -0
  74. package/src/FinnishInvestmentCompany/backend/index.ts +46 -0
  75. package/src/FinnishInvestmentCompany/ui/index.tsx +26 -0
  76. package/src/FinnishLimitedCompanyComplete/backend/fi-EUR.tsv +1086 -0
  77. package/src/FinnishLimitedCompanyComplete/backend/index.ts +46 -0
  78. package/src/FinnishLimitedCompanyComplete/ui/index.tsx +26 -0
  79. package/src/FinnishLimitedCompanyLite/backend/en-EUR.tsv +97 -0
  80. package/src/FinnishLimitedCompanyLite/backend/fi-EUR.tsv +99 -0
  81. package/src/FinnishLimitedCompanyLite/backend/index.ts +53 -0
  82. package/src/FinnishLimitedCompanyLite/ui/index.tsx +28 -0
  83. package/src/GitBackup/backend/index.ts +109 -0
  84. package/src/GitBackup/ui/index.tsx +127 -0
  85. package/src/IncomeAndExpenses/backend/assetCodes.json +126 -0
  86. package/src/IncomeAndExpenses/backend/expense.json +190 -0
  87. package/src/IncomeAndExpenses/backend/income.json +120 -0
  88. package/src/IncomeAndExpenses/backend/index.ts +354 -0
  89. package/src/IncomeAndExpenses/backend/taxTypes.json +12 -0
  90. package/src/JournalReport/backend/index.ts +157 -0
  91. package/src/KrakenImport/backend/KrakenHandler.ts +88 -0
  92. package/src/KrakenImport/backend/index.ts +24 -0
  93. package/src/KrakenImport/backend/rules.json +52 -0
  94. package/src/LedgerReport/backend/index.ts +161 -0
  95. package/src/LynxImport/backend/LynxHandler.ts +389 -0
  96. package/src/LynxImport/backend/index.ts +24 -0
  97. package/src/LynxImport/backend/rules.json +412 -0
  98. package/src/NordeaImport/backend/NordeaHandler.ts +44 -0
  99. package/src/NordeaImport/backend/index.ts +24 -0
  100. package/src/NordeaImport/backend/rules.json +4 -0
  101. package/src/NordnetImport/backend/NordnetHandler.ts +78 -0
  102. package/src/NordnetImport/backend/index.ts +24 -0
  103. package/src/NordnetImport/backend/rules.json +271 -0
  104. package/src/Rand/ui/index.tsx +27 -0
  105. package/src/RapidAPI/backend/index.ts +133 -0
  106. package/src/TITOImport/backend/TITOHandler.ts +268 -0
  107. package/src/TITOImport/backend/index.ts +24 -0
  108. package/src/TITOImport/backend/rules.json +4 -0
  109. package/src/TagEditor/ui/index.tsx +510 -0
  110. package/src/USDollar/ui/index.tsx +27 -0
  111. package/src/VAT/ui/index.tsx +572 -0
  112. package/src/VATFinland/backend/index.ts +22 -0
  113. package/src/VATFinland/backend/vat.json +23 -0
  114. package/tsconfig.json +13 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['tasenor']
4
+ }
@@ -0,0 +1,4 @@
1
+
2
+ > @dataplug/tasenor-common-plugins@1.9.16 fix /home/wigy/project/tasenor-bookkeeper/packages/tasenor-common-plugins
3
+ > eslint --fix 'src/**/*.{ts,tsx}' 'data/**/*.mjs'
4
+
@@ -0,0 +1,4 @@
1
+
2
+ > @dataplug/tasenor-common-plugins@1.9.16 lint /home/wigy/project/tasenor-bookkeeper/packages/tasenor-common-plugins
3
+ > eslint 'src/**/*.{ts,tsx}' 'data/**/*.mjs'
4
+
@@ -0,0 +1,5 @@
1
+
2
+ > @dataplug/tasenor-common-plugins@1.9.16 version /home/wigy/project/tasenor-bookkeeper/packages/tasenor-common-plugins
3
+ > jq .version < package.json
4
+
5
+ "1.9.16"
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Tommi Ronkainen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Tasenor Common Plugins
2
+
3
+ This is a collection of commonly used plugins for Tasenor Bookkeeper.
4
+
5
+ ## Source data
6
+
7
+ Original data for many tables are stored in Google Sheets. If you want an access, please email the
8
+ package author (see `package.json`). From the Google Sheets data is downloaded as `.tsv` file and
9
+ stored under `./data/src`. Then corresponding script under `./data`can be ran to generate the latest
10
+ data in plugins and/or in some cases code definitions.
11
+
12
+ To regenerate all data, you can run
13
+ ```
14
+ pnpm run tsv
15
+ ```
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { readFile, saveText, trimCRLF } from './lib/utils.mjs'
3
+
4
+ let tsv
5
+ tsv = trimCRLF(readFile('FinnishBalanceSheetReport - balance-sheet-fi.tsv'))
6
+ saveText('FinnishBalanceSheetReport', 'balance-sheet-fi.tsv', tsv)
7
+
8
+ tsv = trimCRLF(readFile('FinnishBalanceSheetReport - balance-sheet-detailed-fi.tsv'))
9
+ saveText('FinnishBalanceSheetReport', 'balance-sheet-detailed-fi.tsv', tsv)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { cleanFlagDuplicates, readFile, saveText, trimCRLF } from './lib/utils.mjs'
3
+
4
+ let tsv
5
+ tsv = trimCRLF(readFile('FinnishBalanceSheetReportInvestment - balance-sheet-fi.tsv'))
6
+ tsv = cleanFlagDuplicates(tsv)
7
+ saveText('FinnishBalanceSheetReportInvestment', 'balance-sheet-investment-fi.tsv', tsv)
8
+
9
+ tsv = trimCRLF(readFile('FinnishBalanceSheetReportInvestment - balance-sheet-detailed-fi.tsv'))
10
+ tsv = cleanFlagDuplicates(tsv)
11
+ saveText('FinnishBalanceSheetReportInvestment', 'balance-sheet-investment-detailed-fi.tsv', tsv)
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { readFile, saveText, trimCRLF } from './lib/utils.mjs'
3
+
4
+ let tsv
5
+
6
+ tsv = trimCRLF(readFile('FinnishBalanceSheetReportLite - balance-sheet-lite-fi.tsv'))
7
+ saveText('FinnishBalanceSheetReportLite', 'balance-sheet-lite-fi.tsv', tsv)
8
+ tsv = trimCRLF(readFile('FinnishBalanceSheetReportLite - balance-sheet-lite-en.tsv'))
9
+ saveText('FinnishBalanceSheetReportLite', 'balance-sheet-lite-en.tsv', tsv)
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { readFile, saveText, trimCRLF } from './lib/utils.mjs'
3
+
4
+ let tsv
5
+ tsv = trimCRLF(readFile('FinnishIncomeStatementReport - income-statement-fi.tsv'))
6
+ saveText('FinnishIncomeStatementReport', 'income-statement-fi.tsv', tsv)
7
+
8
+ tsv = trimCRLF(readFile('FinnishIncomeStatementReport - income-statement-detailed-fi.tsv'))
9
+ saveText('FinnishIncomeStatementReport', 'income-statement-detailed-fi.tsv', tsv)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { cleanFlagDuplicates, readFile, saveText, trimCRLF } from './lib/utils.mjs'
3
+
4
+ let tsv
5
+ tsv = trimCRLF(readFile('FinnishIncomeStatementReportInvestment - income-statement-fi.tsv'))
6
+ tsv = cleanFlagDuplicates(tsv)
7
+ saveText('FinnishIncomeStatementReportInvestment', 'income-statement-investment-fi.tsv', tsv)
8
+
9
+ tsv = trimCRLF(readFile('FinnishIncomeStatementReportInvestment - income-statement-detailed-fi.tsv'))
10
+ tsv = cleanFlagDuplicates(tsv)
11
+ saveText('FinnishIncomeStatementReportInvestment', 'income-statement-investment-detailed-fi.tsv', tsv)
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { readFile, saveText, trimCRLF } from './lib/utils.mjs'
3
+
4
+ let tsv
5
+
6
+ tsv = trimCRLF(readFile('FinnishIncomeStatementReportLite - income-statement-lite-fi.tsv'))
7
+ saveText('FinnishIncomeStatementReportLite', 'income-statement-lite-fi.tsv', tsv)
8
+ tsv = trimCRLF(readFile('FinnishIncomeStatementReportLite - income-statement-lite-en.tsv'))
9
+ saveText('FinnishIncomeStatementReportLite', 'income-statement-lite-en.tsv', tsv)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { readFile, saveFile, trimCRLF } from './lib/utils.mjs'
3
+
4
+ const tsv = trimCRLF(readFile('FinnishInvestmentCompany - fi-EUR.tsv'))
5
+ saveFile('FinnishInvestmentCompany', 'backend/fi-EUR.tsv', tsv)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { readFile, saveFile, trimCRLF } from './lib/utils.mjs'
3
+
4
+ const tsv = trimCRLF(readFile('FinnishLimitedCompanyComplete - fi-EUR.tsv'))
5
+ saveFile('FinnishLimitedCompanyComplete', 'backend/fi-EUR.tsv', tsv)
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { readFile, saveFile, trimCRLF } from './lib/utils.mjs'
3
+
4
+ let tsv
5
+ tsv = trimCRLF(readFile('FinnishLimitedCompanyLite - fi-EUR.tsv'))
6
+ saveFile('FinnishLimitedCompanyLite', 'backend/fi-EUR.tsv', tsv)
7
+
8
+ tsv = trimCRLF(readFile('FinnishLimitedCompanyLite - en-EUR.tsv'))
9
+ saveFile('FinnishLimitedCompanyLite', 'backend/en-EUR.tsv', tsv)
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ import { buildData, combine, insertToFile, lint, parseFile, rebuildTranslations, saveFile, saveJson, trimIndentation } from './lib/utils.mjs'
3
+
4
+ // Collect JSON data.
5
+ const all = combine(
6
+ rebuildTranslations('IncomeAndExpenses', 'income', 'Income Tree - Definitions.tsv'),
7
+ rebuildTranslations('IncomeAndExpenses', 'expense', 'Expense Tree - Definitions.tsv'),
8
+ rebuildTranslations('IncomeAndExpenses', 'assets', 'Assets Tree - Definitions.tsv'),
9
+ rebuildTranslations('IncomeAndExpenses', 'tax', 'Tax Types - Definitions.tsv')
10
+ )
11
+
12
+ // Save data file.
13
+ const income = buildData(parseFile('Income Tree - Definitions.tsv'))
14
+ saveJson('IncomeAndExpenses', 'income', income)
15
+ const expense = buildData(parseFile('Expense Tree - Definitions.tsv'))
16
+ saveJson('IncomeAndExpenses', 'expense', expense)
17
+ const assets = buildData(parseFile('Assets Tree - Definitions.tsv'))
18
+ saveJson('IncomeAndExpenses', 'assetCodes', assets)
19
+ const taxTypes = (parseFile('Tax Types - Definitions.tsv').map(line => line.id))
20
+ saveJson('IncomeAndExpenses', 'taxTypes', taxTypes)
21
+
22
+ // Write translations to plugin.
23
+ insertToFile(
24
+ ['IncomeAndExpenses', 'backend', 'index.ts'],
25
+ lint(trimIndentation(all, ' ')),
26
+ ' // START TRANSLATION',
27
+ ' // END TRANSLATION'
28
+ )
29
+
30
+ // Write income definition.
31
+ const incomes = Object.keys(income.parents).sort()
32
+ const commentsIn = incomes.map(code => ` * * \`${code}\` - ${all.en['income-' + code]}`)
33
+ const incomeFile = `/**
34
+ * An income source.
35
+ *
36
+ ${commentsIn.join('\n')}
37
+ */
38
+ export type IncomeSource = ${incomes.map(code => `'${code}'`).join(' |\n ')}
39
+ `
40
+ saveFile('@tasenor-common', 'src/types/income.ts', incomeFile)
41
+
42
+ // Write expense definition.
43
+ const expenses = Object.keys(expense.parents).sort()
44
+ const commentsExp = expenses.map(code => ` * * \`${code}\` - ${all.en['expense-' + code]}`)
45
+ const expenseFile = `/**
46
+ * A cause of expense.
47
+ *
48
+ ${commentsExp.join('\n')}
49
+ */
50
+ export type ExpenseSink = ${expenses.map(code => `'${code}'`).join(' |\n ')}
51
+ `
52
+ saveFile('@tasenor-common', 'src/types/expense.ts', expenseFile)
53
+
54
+ // Write assetType definition.
55
+ const assetCodes = Object.keys(assets.parents).sort()
56
+ const assetsExp = assetCodes.map(code => ` * * \`${code}\` - ${all.en['assets-' + code]}`)
57
+ const assetsFile = `/**
58
+ * An asset type
59
+ *
60
+ ${assetsExp.join('\n')}
61
+ */
62
+ export type AssetCode = ${assetCodes.map(code => `'${code}'`).join(' |\n ')}
63
+ `
64
+ saveFile('@tasenor-common', 'src/types/assetCodes.ts', assetsFile)
package/data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ ## Builders
2
+
3
+ This directory contains scripts to rebuild plugins using some source
4
+ data. Typically source file is TSV-file created with Google Sheet.
5
+
6
+ Store the latest file version(s) to `data/src` and run `data/<PluginCode>.mjs` script.
7
+
8
+ To generate all, you can run `pnpm build-data` on the top level of the repo.
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ import { trimId, readTsv, fixNumber, saveJson } from './lib/utils.mjs'
3
+
4
+ const data = []
5
+ const tsv = readTsv('Finland VAT - Definitions.tsv', true)
6
+
7
+ for (let column = 1; column < tsv[0].length; column++) {
8
+ const from = tsv[0][column]
9
+ const to = tsv[1][column] || null
10
+
11
+ const percentage = {}
12
+ for (let line = 2; line < tsv.length; line++) {
13
+ const id = trimId(tsv[line][0])
14
+ const value = tsv[line][column]
15
+ if (value !== undefined) {
16
+ percentage[id] = fixNumber(value.replace(',', '.'))
17
+ }
18
+ }
19
+ data.push({ from, to, percentage })
20
+ }
21
+
22
+ saveJson('VATFinland', 'vat', data)
@@ -0,0 +1,11 @@
1
+ #!/bin/bash
2
+
3
+ FILE=`dirname "${BASH_SOURCE[0]}"`/../..
4
+ ROOT=`readlink -f "$FILE"`
5
+
6
+ for script in "$ROOT/data/"*.mjs; do
7
+ echo
8
+ echo Running $script
9
+ echo
10
+ $script
11
+ done
@@ -0,0 +1,314 @@
1
+ import fs from 'fs'
2
+ import path, { dirname } from 'path'
3
+ import { fileURLToPath } from 'url'
4
+ // TODO: This should be imported from tasenor-common but it does not work yet.
5
+ const MAX_TARGET_ID_LEN = 64
6
+
7
+ const DIRNAME = path.join(dirname(fileURLToPath(import.meta.url)), '..', '..')
8
+
9
+ /**
10
+ * Read in text from UTF-8 encoded file.
11
+ * @param fileName
12
+ */
13
+ export function readFile(fileName) {
14
+ const file = path.join(DIRNAME, 'data', 'src', fileName)
15
+ const text = fs.readFileSync(file).toString('utf-8')
16
+ return text
17
+ }
18
+
19
+ /**
20
+ * Read TSV file so that first line defines names for columns, which are used in the mapping.
21
+ * @param file
22
+ * @returns
23
+ */
24
+ export function readTsv(fileName, raw = false) {
25
+ const data = readFile(fileName).split('\n').map(s => s.trim()).filter(s => !!s).map(s => s.split('\t'))
26
+ if (raw) {
27
+ return data
28
+ }
29
+ const headers = data[0]
30
+ headers[0] = headers[0].replace(/^#\s*/, '')
31
+ const results = []
32
+ for (let i = 1; i < data.length; i++) {
33
+ const item = {}
34
+ for (let j = 0; j < headers.length; j++) {
35
+ item[headers[j]] = data[i][j]
36
+ }
37
+ results.push(item)
38
+ }
39
+ return results
40
+ }
41
+
42
+ /**
43
+ * Go through data entries and add `level` and `parent` fields. Remove _ prefixes from idField.
44
+ * @param data
45
+ * @param idField
46
+ */
47
+ export function collectParents(data, idField) {
48
+ const parents = {
49
+ '-1': null,
50
+ 0: null,
51
+ 1: null,
52
+ 2: null,
53
+ 3: null,
54
+ 4: null,
55
+ 5: null,
56
+ 6: null
57
+ }
58
+ for (const line of data) {
59
+ const match = /^(_*)/.exec(line[idField])
60
+ line.level = match[1].length
61
+ line[idField] = line[idField].replace(/^_+/, '')
62
+ line.parent = parents[line.level - 1]
63
+ if (line.level && !line.parent) {
64
+ throw new Error(`Something wrong with ${JSON.stringify(line)}. Cannot find parent level for it.`)
65
+ }
66
+ parents[line.level] = line[idField]
67
+ }
68
+ return data
69
+ }
70
+
71
+ /**
72
+ * Collect language codes from header line.
73
+ * @param data
74
+ */
75
+ export function languages(data) {
76
+ return Object.keys(data[0]).slice(1).filter(k => /^[a-z][a-z]$/.test(k))
77
+ }
78
+
79
+ /**
80
+ * Construct a language translation table.
81
+ * @param data
82
+ * @param prefix
83
+ * @param translations
84
+ */
85
+ export function makeTranslations(data, prefix, translations) {
86
+ const tr = {}
87
+ for (const lang of translations) {
88
+ tr[lang] = data.reduce((prev, cur) => ({ ...prev, [`${prefix}-${cur.id}`]: cur[lang] }), {})
89
+ }
90
+ return tr
91
+ }
92
+
93
+ /**
94
+ * Drop first and last bracket and add indentation to every line.
95
+ * @param output
96
+ */
97
+ export function trimIndentation(output, indent = '') {
98
+ let text = JSON.stringify(output, null, 2)
99
+ text = text.substr(2, text.length - 4)
100
+ text = text.split('\n').map(line => indent + line.replace(/^ {2}/, ''))
101
+ return '\n' + text.join('\n') + '\n'
102
+ }
103
+
104
+ /**
105
+ * Load and pre-process a TSV file.
106
+ * @param fileName
107
+ */
108
+ export function parseFile(fileName) {
109
+ const tsv = readTsv(fileName)
110
+ const data = collectParents(tsv, 'id')
111
+ return data
112
+ }
113
+
114
+ /**
115
+ * Refresh plugin translation data.
116
+ * @param prefix
117
+ * @param fileName
118
+ */
119
+ export function rebuildTranslations(plugin, prefix, fileName) {
120
+ const data = parseFile(fileName)
121
+ const translations = languages(data)
122
+ const output = makeTranslations(data, prefix, translations)
123
+ return output
124
+ }
125
+
126
+ /**
127
+ * Put together multiple translations and sort them all.
128
+ * @param files
129
+ * @returns
130
+ */
131
+ export function combine(...files) {
132
+ const all = {}
133
+ const languages = new Set()
134
+ for (const file of files) {
135
+ Object.entries(file).forEach(([lang, data]) => {
136
+ all[lang] = all[lang] || {}
137
+ languages.add(lang)
138
+ Object.assign(all[lang], data)
139
+ })
140
+ }
141
+
142
+ const sorted = {}
143
+ for (const lang of languages) {
144
+ sorted[lang] = {}
145
+ const keys = Object.keys(all[lang]).sort()
146
+ for (const k of keys) {
147
+ sorted[lang][k] = all[lang][k]
148
+ }
149
+ }
150
+
151
+ return sorted
152
+ }
153
+
154
+ /**
155
+ * Do rude lint fixing for JSON string.
156
+ * @param text
157
+ */
158
+ export function lint(text) {
159
+ return text.replace(/"/g, "'").replace(/'(\w+)':/g, '$1:')
160
+ }
161
+
162
+ /**
163
+ * Insert text between the given separators in a file.
164
+ * @param pathParts
165
+ * @param text
166
+ * @param startSep
167
+ * @param endSep
168
+ */
169
+ export function insertToFile(pathParts, text, startSep, endSep) {
170
+ const filePath = path.join(DIRNAME, 'src', ...pathParts)
171
+ const current = fs.readFileSync(filePath).toString('utf-8').split(startSep)
172
+ if (current.length !== 2) {
173
+ throw new Error(`Insertion to ${filePath} failed: start separator ${JSON.stringify(startSep)} not correct.`)
174
+ }
175
+ const tail = current[1].split(endSep)
176
+ if (tail.length !== 2) {
177
+ throw new Error(`Insertion to ${filePath} failed: end separator ${JSON.stringify(endSep)} not correct.`)
178
+ }
179
+ const combined = current[0] + startSep + text + endSep + tail[1]
180
+ fs.writeFileSync(filePath, combined)
181
+ console.log(new Date(), `Refreshed translation data in ${filePath}`)
182
+ }
183
+
184
+ /**
185
+ * Construct actual data to store as a knowledge.
186
+ */
187
+ export function buildData(data) {
188
+ const result = {
189
+ root: null,
190
+ children: {},
191
+ parents: {}
192
+ }
193
+ for (let i = 0; i < data.length; i++) {
194
+ const { id, parent } = data[i]
195
+ if (id.length > MAX_TARGET_ID_LEN) {
196
+ throw new Error(`An ID '${id}' is too long (max. ${MAX_TARGET_ID_LEN}).`)
197
+ }
198
+ result.parents[id] = parent
199
+ if (!parent) {
200
+ if (result.root !== null) {
201
+ throw new Error(`Found second root element ${JSON.stringify(data[i])}.`)
202
+ }
203
+ result.root = id
204
+ continue
205
+ }
206
+ result.children[parent] = result.children[parent] || []
207
+ result.children[parent].push(id)
208
+ }
209
+ return result
210
+ }
211
+
212
+ /**
213
+ * Save JSON data to the plugin directory.
214
+ * @param name
215
+ * @param data
216
+ */
217
+ export function saveJson(plugin, name, data) {
218
+ const filePath = path.join(DIRNAME, 'src', plugin, 'backend', `${name}.json`)
219
+ fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n')
220
+ console.log(new Date(), `Saved JSON data to ${filePath}`)
221
+ }
222
+
223
+ /**
224
+ * Save text file as it is to the plugin directory.
225
+ * @param name
226
+ * @param data
227
+ */
228
+ export function saveText(plugin, name, text) {
229
+ const filePath = path.join(DIRNAME, 'src', plugin, 'backend', name)
230
+ fs.writeFileSync(filePath, text)
231
+ console.log(new Date(), `Saved text data to ${filePath}`)
232
+ }
233
+
234
+ /**
235
+ * Save text data to the file.
236
+ * @param plugin
237
+ * @param filePath
238
+ * @param text
239
+ */
240
+ export function saveFile(plugin, filePath, text) {
241
+ let targetPath
242
+ if (plugin[0] === '@') {
243
+ const project = plugin.substr(1)
244
+ if (!fs.existsSync(path.join(DIRNAME, '..', project))) {
245
+ throw new Error(`Cannot find other project ${project} to write file.`)
246
+ }
247
+ targetPath = path.join(DIRNAME, '..', plugin.substr(1), filePath)
248
+ } else {
249
+ targetPath = path.join(DIRNAME, 'src', plugin, filePath)
250
+ }
251
+ fs.writeFileSync(targetPath, text)
252
+ console.log(new Date(), `Saved data to ${targetPath}`)
253
+ }
254
+
255
+ /**
256
+ * Remove _ prefixes from ID field.
257
+ * @param data
258
+ */
259
+ export function trimId(value) {
260
+ return value.replace(/^_+/, '')
261
+ }
262
+
263
+ /**
264
+ * Remove _ prefixes from ID fields from each line.
265
+ * @param data
266
+ */
267
+ export function trimIds(data, idField = 'id') {
268
+ return data.map(line => ({ ...line, [idField]: trimId(line.id) }))
269
+ }
270
+
271
+ /**
272
+ * Strip extras away and convert numeric string to proper number.
273
+ * @param data
274
+ */
275
+ export function fixNumber(data) {
276
+ return parseFloat(data.replace(/[^0-9.]/g, ''))
277
+ }
278
+
279
+ /**
280
+ * Strip extras away and convert numeric string to proper number.
281
+ * @param data
282
+ * @param fieldName
283
+ */
284
+ export function fixNumbers(data, fieldName) {
285
+ return data.map(line => ({ ...line, [fieldName]: fixNumber(line[fieldName]) }))
286
+ }
287
+
288
+ /**
289
+ * Gather two values from data to form a mapping from one field value to another.
290
+ * @param data
291
+ * @param keyName
292
+ * @param valueName
293
+ */
294
+ export function toMap(data, keyName, valueName) {
295
+ return data.reduce((prev, cur) => ({ ...prev, [cur[keyName]]: cur[valueName] }), {})
296
+ }
297
+
298
+ /**
299
+ * Replace CRLF with LF.
300
+ * @param text
301
+ */
302
+ export function trimCRLF(text) {
303
+ return text.replace(/\r\n/g, '\n')
304
+ }
305
+
306
+ /**
307
+ * Remove duplicated flags from report as TSV data.
308
+ */
309
+ export function cleanFlagDuplicates(tsv) {
310
+ const rempoveDuplicates = (s) => {
311
+ return [...new Set(s.split(' '))].join(' ').trim()
312
+ }
313
+ return tsv.split('\n').map(line => line.split('\t')).map(([a, b, c]) => [a, b, rempoveDuplicates(c)]).map(a => a.join('\t')).join('\n')
314
+ }
@@ -0,0 +1,101 @@
1
+ # id en fi
2
+ ASSETS Assets Vastaavaa
3
+ _NON_CURRENT_ASSETS Non-current assets Pysyvät vastaavat
4
+ __INTANGLIBLE_ASSETS Intanglible assets Aineettomat hyödykkeet
5
+
6
+
7
+
8
+ __TANGLIBLE_ASSETS Intanglible assets Aineelliset hyödykkeet
9
+
10
+
11
+
12
+
13
+
14
+ __INVESTMENTS Investments Sijoitukset
15
+
16
+
17
+
18
+
19
+
20
+
21
+ _CURRENT_ASSETS Current assets Vaihtuvat vastaavat
22
+
23
+ __CURRENT_STOCKS Stocks Vaihto-omaisuus
24
+ ___CURRENT_PUBLIC_STOCK_SHARES Publicly listed shares Pörssinoteeratut osakkeet
25
+ ___CURRENT_PRIVATE_STOCK_SHARES Unlisted shares Listaamattomat osakkeet
26
+ __CURRENT_CRYPTOCURRENCIES Cryptocurrencies Kryptovaluutat
27
+
28
+
29
+
30
+ __CURRENT_DEBTORS Debtors Saamiset
31
+ ___TRADE_DEBTORS Trade debtors Myyntisaamiset
32
+ ____EU_SALES_RECEIVABLES Sales receivables from EU Myyntisaamiset EU-alueelta
33
+ _____EURO_AREA_SALES_RECEIVABLES Sales receivables from Euro Zone Myyntisaamiset euroalueelta
34
+ ______FINLAND_SALES_RECEIVABLES Sales receivables from Finland Myyntisaamiset Suomesta
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+ ___OWNED_BY_GROUP Amounts owned by group undertakings Saamiset saman konsernin yrityksiltä
50
+ ___OWNED_BY_PARTICIPATING Amounts owned by participating interest undertakings Saamiset omistusyhteysyrityksiltä
51
+ ___LOANS_RECEIVABLE Loans receivable Lainasaamiset
52
+ ____P2P_LOANS_RECEIVABLE Peer to peer loans receivable Vertaislainasaamiset
53
+ ___OTHER_DEBTORS Other debtors Muut saamiset
54
+ ___SUBSRIBED_CAPITAL_UNPAID Subscribed capital unpaid Maksamattomat osakkeet/osuudet
55
+ ___ACCRUED_INCOME Prepayments and accrued income Siirtosaamiset
56
+
57
+ __CURRENT_INVESTMENTS Investments Rahoitusarvopaperit
58
+ ___GROUP_UNDERTAKINGS_HOLDINGS Holdings in group undertakings Osuudet saman konsernin yrityksissä
59
+ ___OTHER_SHARES Other shares and similar ownerships Muut osakkeet ja osuudet
60
+
61
+
62
+
63
+ ___OTHER_INVESTMENTS Other investments Muut arvopaperit
64
+
65
+
66
+
67
+
68
+
69
+ __CASH Cash at bank and in hand Rahat ja pankkisaamiset
70
+ ___CASH_IN_HAND Cash in hand Käteinen
71
+ ___CASH_AT_BANK Cash at bank Pankkisaamiset
72
+ ___CASH_AT_STOCK_BROKER Cash at stock broker account Pankkisaamiset osakevälittäjillä
73
+ ___CASH_AT_CRYPTO_BROKER Cash at cryptocurrency broker account Pankkisaamiset kryptovälittäjillä
74
+ ___CASH_AT_P2P Cash at peer-to-peer lender Pankkisaamiset vertaislainavälittäjällä
75
+
76
+
77
+
78
+
79
+
80
+ _CAPITAL_RESERVERS_AND_LIABILITIES Capital, reserves and liabilities Vastattavaa
81
+ __CAPITAL_RESERVERS Capital and reserves Oma pääoma
82
+ ___SUBSCRIBED_CAPITAL Subscribed capital Osake-, osuus- tai muu vastaava pääoma
83
+
84
+
85
+
86
+
87
+ __APPROPRIATIONS Appropriations Tilinpäätössiirtojen kertymä
88
+
89
+ __PROVISIONS Provisions Pakolliset varaukset
90
+
91
+ __CREDITORS Creditors Vieras pääoma
92
+ ___BONDS Bonds Joukkovelkakirjalainat
93
+ ___CONVERTIBLE_BONDS Convertible bonds Vaihtovelkakirjalainat
94
+ ___LIABILITITES_TO_CREDIT_INSTITUTIONS Liabilities to credit institutions Lainat rahoituslaitoksilta
95
+
96
+
97
+
98
+ ___OTHER_CREDITORS Other creditors Muut velat
99
+ ____SHORT_SELLING_STOCKS Short-selling stocks Osakkeiden lyhyeksimyynti
100
+ ____STOCK_BROKER_LOANS Stock-broker loans Lainat osakevälittäjiltä
101
+ ____UNPAID_PROFIT_DISTRIBUTIONS Unpaid profit distributions Voitonjakovelat