@accounter/shaam-uniform-format-generator 0.1.0 → 0.1.1
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.
- package/README.md +366 -13
- package/dist/README.md +476 -0
- package/dist/cjs/api/generate-report-legacy.js +6 -0
- package/dist/cjs/api/generate-report.js +328 -0
- package/dist/cjs/constants.js +11 -0
- package/dist/cjs/generator/format/encoder.js +86 -0
- package/dist/cjs/generator/records/a000-sum.js +66 -0
- package/dist/cjs/generator/records/a000.js +349 -0
- package/dist/cjs/generator/records/a100.js +107 -0
- package/dist/cjs/generator/records/b100.js +305 -0
- package/dist/cjs/generator/records/b110.js +255 -0
- package/dist/cjs/generator/records/c100.js +338 -0
- package/dist/cjs/generator/records/d110.js +272 -0
- package/dist/cjs/generator/records/d120.js +278 -0
- package/{cjs → dist/cjs}/generator/records/index.js +1 -0
- package/dist/cjs/generator/records/m100.js +177 -0
- package/dist/cjs/generator/records/z900.js +93 -0
- package/{cjs → dist/cjs}/index.js +3 -0
- package/dist/cjs/records/a100.js +78 -0
- package/dist/cjs/records/index.js +20 -0
- package/dist/cjs/records/z900.js +82 -0
- package/dist/cjs/types/enums.js +457 -0
- package/{cjs → dist/cjs}/types/index.js +6 -1
- package/dist/cjs/utils/file-helpers.js +198 -0
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/key-generator.js +71 -0
- package/dist/esm/api/generate-report-legacy.js +2 -0
- package/dist/esm/api/generate-report.js +325 -0
- package/dist/esm/constants.js +8 -0
- package/dist/esm/generator/format/encoder.js +77 -0
- package/dist/esm/generator/records/a000-sum.js +61 -0
- package/dist/esm/generator/records/a000.js +344 -0
- package/dist/esm/generator/records/a100.js +102 -0
- package/dist/esm/generator/records/b100.js +300 -0
- package/dist/esm/generator/records/b110.js +250 -0
- package/dist/esm/generator/records/c100.js +333 -0
- package/dist/esm/generator/records/d110.js +267 -0
- package/dist/esm/generator/records/d120.js +273 -0
- package/{esm → dist/esm}/generator/records/index.js +1 -0
- package/dist/esm/generator/records/m100.js +172 -0
- package/dist/esm/generator/records/z900.js +88 -0
- package/{esm → dist/esm}/index.js +3 -0
- package/dist/esm/records/a100.js +73 -0
- package/dist/esm/records/index.js +11 -0
- package/dist/esm/records/z900.js +77 -0
- package/dist/esm/types/enums.js +454 -0
- package/{esm → dist/esm}/types/index.js +5 -1
- package/dist/esm/utils/file-helpers.js +188 -0
- package/dist/esm/utils/index.js +5 -0
- package/dist/esm/utils/key-generator.js +65 -0
- package/dist/package.json +54 -0
- package/dist/typings/api/generate-report-legacy.d.cts +1 -0
- package/dist/typings/api/generate-report-legacy.d.ts +1 -0
- package/dist/typings/constants.d.cts +8 -0
- package/dist/typings/constants.d.ts +8 -0
- package/dist/typings/generator/format/encoder.d.cts +57 -0
- package/dist/typings/generator/format/encoder.d.ts +57 -0
- package/dist/typings/generator/records/a000-sum.d.cts +40 -0
- package/dist/typings/generator/records/a000-sum.d.ts +40 -0
- package/dist/typings/generator/records/a000.d.cts +238 -0
- package/dist/typings/generator/records/a000.d.ts +238 -0
- package/dist/typings/generator/records/a100.d.cts +59 -0
- package/dist/typings/generator/records/a100.d.ts +59 -0
- package/dist/typings/generator/records/b100.d.cts +101 -0
- package/dist/typings/generator/records/b100.d.ts +101 -0
- package/dist/typings/generator/records/b110.d.cts +89 -0
- package/dist/typings/generator/records/b110.d.ts +89 -0
- package/dist/typings/generator/records/c100.d.cts +133 -0
- package/dist/typings/generator/records/c100.d.ts +133 -0
- package/dist/typings/generator/records/d110.d.cts +98 -0
- package/dist/typings/generator/records/d110.d.ts +98 -0
- package/dist/typings/generator/records/d120.d.cts +95 -0
- package/dist/typings/generator/records/d120.d.ts +95 -0
- package/{typings → dist/typings}/generator/records/index.d.cts +1 -0
- package/{typings → dist/typings}/generator/records/index.d.ts +1 -0
- package/dist/typings/generator/records/m100.d.cts +69 -0
- package/dist/typings/generator/records/m100.d.ts +69 -0
- package/dist/typings/generator/records/z900.d.cts +61 -0
- package/dist/typings/generator/records/z900.d.ts +61 -0
- package/{typings → dist/typings}/index.d.cts +3 -0
- package/{typings → dist/typings}/index.d.ts +3 -0
- package/dist/typings/records/a100.d.cts +35 -0
- package/dist/typings/records/a100.d.ts +35 -0
- package/dist/typings/records/index.d.cts +2 -0
- package/dist/typings/records/index.d.ts +2 -0
- package/dist/typings/records/z900.d.cts +38 -0
- package/dist/typings/records/z900.d.ts +38 -0
- package/dist/typings/types/enums.d.cts +162 -0
- package/dist/typings/types/enums.d.ts +162 -0
- package/{typings → dist/typings}/types/index.d.cts +17 -14
- package/{typings → dist/typings}/types/index.d.ts +17 -14
- package/dist/typings/utils/file-helpers.d.cts +131 -0
- package/dist/typings/utils/file-helpers.d.ts +131 -0
- package/dist/typings/utils/index.d.cts +5 -0
- package/dist/typings/utils/index.d.ts +5 -0
- package/dist/typings/utils/key-generator.d.cts +41 -0
- package/dist/typings/utils/key-generator.d.ts +41 -0
- package/documentation/IncomeTax_IncomeTaxSoftwareHousesInfo_horaot1.31_2_05.pdf +0 -0
- package/documentation/_4D6963726F736F667420576F7264202D20F8E5E0E9ED20F8E7E5F720F8E5E0E9ED20F9F7E5F32E646F63_.pdf +0 -0
- package/documentation/a000-sum.csv +3 -0
- package/documentation/a000.csv +37 -0
- package/documentation/a100.csv +7 -0
- package/documentation/b100.csv +29 -0
- package/documentation/b110.csv +26 -0
- package/documentation/c100.csv +37 -0
- package/documentation/d110.csv +27 -0
- package/documentation/d120.csv +26 -0
- package/documentation/m100.csv +17 -0
- package/documentation/z900.csv +8 -0
- package/package.json +50 -29
- package/prompt_plan.md +259 -0
- package/spec.md +206 -0
- package/src/api/generate-report.ts +366 -0
- package/src/api/parse-files.ts +33 -0
- package/src/constants.ts +9 -0
- package/src/format/index.ts +6 -0
- package/src/format/newline.ts +8 -0
- package/src/format/padding.ts +39 -0
- package/src/generator/format/decoder.ts +15 -0
- package/src/generator/format/encoder.ts +95 -0
- package/src/generator/format/index.ts +6 -0
- package/src/generator/index.ts +6 -0
- package/src/generator/records/a000-sum.ts +78 -0
- package/src/generator/records/a000.ts +373 -0
- package/src/generator/records/a100.ts +118 -0
- package/src/generator/records/b100.ts +317 -0
- package/src/generator/records/b110.ts +267 -0
- package/src/generator/records/c100.ts +347 -0
- package/src/generator/records/d110.ts +286 -0
- package/src/generator/records/d120.ts +293 -0
- package/src/generator/records/index.ts +14 -0
- package/src/generator/records/m100.ts +185 -0
- package/src/generator/records/z900.ts +104 -0
- package/src/index.ts +18 -0
- package/src/parser/data-parser.ts +14 -0
- package/src/parser/index.ts +6 -0
- package/src/parser/ini-parser.ts +14 -0
- package/src/types/enums.ts +531 -0
- package/src/types/index.ts +110 -0
- package/src/utils/file-helpers.ts +221 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/key-generator.ts +75 -0
- package/src/validation/errors.ts +35 -0
- package/src/validation/index.ts +6 -0
- package/src/validation/validate-input.ts +67 -0
- package/tests/debug-output.test.ts +81 -0
- package/tests/format/crlf-join.test.ts +124 -0
- package/tests/format/encoder.test.ts +80 -0
- package/tests/format/newline.test.ts +19 -0
- package/tests/format/padding.test.ts +74 -0
- package/tests/index.test.ts +29 -0
- package/tests/ini-text.test.ts +122 -0
- package/tests/integration/comprehensive.integration.test.ts +350 -0
- package/tests/integration/roundtrip.integration.test.ts +377 -0
- package/tests/records/a000-sum.test.ts +278 -0
- package/tests/records/a000.test.ts +318 -0
- package/tests/records/a100.test.ts +239 -0
- package/tests/records/b100.test.ts +419 -0
- package/tests/records/b110.test.ts +445 -0
- package/tests/records/c100.test.ts +333 -0
- package/tests/records/d110.test.ts +93 -0
- package/tests/records/d120.test.ts +275 -0
- package/tests/records/m100.test.ts +437 -0
- package/tests/records/z900.test.ts +254 -0
- package/tests/types/enums.test.ts +290 -0
- package/tests/utils/file-helpers.test.ts +276 -0
- package/tests/utils/key-generator.test.ts +121 -0
- package/tests/validation/document-type-validation.test.ts +521 -0
- package/tests/validation/validate-input.test.ts +219 -0
- package/todo.md +203 -0
- package/tsconfig.json +10 -0
- package/vitest.config.ts +11 -0
- package/cjs/api/generate-report.js +0 -53
- package/cjs/generator/format/encoder.js +0 -46
- package/cjs/generator/records/a000.js +0 -8
- package/cjs/generator/records/a100.js +0 -8
- package/cjs/generator/records/b100.js +0 -8
- package/cjs/generator/records/b110.js +0 -8
- package/cjs/generator/records/c100.js +0 -8
- package/cjs/generator/records/d110.js +0 -8
- package/cjs/generator/records/d120.js +0 -8
- package/cjs/generator/records/m100.js +0 -8
- package/cjs/generator/records/z900.js +0 -8
- package/esm/api/generate-report.js +0 -50
- package/esm/generator/format/encoder.js +0 -42
- package/esm/generator/records/a000.js +0 -5
- package/esm/generator/records/a100.js +0 -5
- package/esm/generator/records/b100.js +0 -5
- package/esm/generator/records/b110.js +0 -5
- package/esm/generator/records/c100.js +0 -5
- package/esm/generator/records/d110.js +0 -5
- package/esm/generator/records/d120.js +0 -5
- package/esm/generator/records/m100.js +0 -5
- package/esm/generator/records/z900.js +0 -5
- package/typings/generator/format/encoder.d.cts +0 -33
- package/typings/generator/format/encoder.d.ts +0 -33
- package/typings/generator/records/a000.d.cts +0 -4
- package/typings/generator/records/a000.d.ts +0 -4
- package/typings/generator/records/a100.d.cts +0 -4
- package/typings/generator/records/a100.d.ts +0 -4
- package/typings/generator/records/b100.d.cts +0 -4
- package/typings/generator/records/b100.d.ts +0 -4
- package/typings/generator/records/b110.d.cts +0 -4
- package/typings/generator/records/b110.d.ts +0 -4
- package/typings/generator/records/c100.d.cts +0 -4
- package/typings/generator/records/c100.d.ts +0 -4
- package/typings/generator/records/d110.d.cts +0 -4
- package/typings/generator/records/d110.d.ts +0 -4
- package/typings/generator/records/d120.d.cts +0 -4
- package/typings/generator/records/d120.d.ts +0 -4
- package/typings/generator/records/m100.d.cts +0 -4
- package/typings/generator/records/m100.d.ts +0 -4
- package/typings/generator/records/z900.d.cts +0 -4
- package/typings/generator/records/z900.d.ts +0 -4
- /package/{cjs → dist/cjs}/api/parse-files.js +0 -0
- /package/{cjs → dist/cjs}/format/index.js +0 -0
- /package/{cjs → dist/cjs}/format/newline.js +0 -0
- /package/{cjs → dist/cjs}/format/padding.js +0 -0
- /package/{cjs → dist/cjs}/generator/format/decoder.js +0 -0
- /package/{cjs → dist/cjs}/generator/format/index.js +0 -0
- /package/{cjs → dist/cjs}/generator/index.js +0 -0
- /package/{cjs → dist/cjs}/package.json +0 -0
- /package/{cjs → dist/cjs}/parser/data-parser.js +0 -0
- /package/{cjs → dist/cjs}/parser/index.js +0 -0
- /package/{cjs → dist/cjs}/parser/ini-parser.js +0 -0
- /package/{cjs → dist/cjs}/validation/errors.js +0 -0
- /package/{cjs → dist/cjs}/validation/index.js +0 -0
- /package/{cjs → dist/cjs}/validation/validate-input.js +0 -0
- /package/{esm → dist/esm}/api/parse-files.js +0 -0
- /package/{esm → dist/esm}/format/index.js +0 -0
- /package/{esm → dist/esm}/format/newline.js +0 -0
- /package/{esm → dist/esm}/format/padding.js +0 -0
- /package/{esm → dist/esm}/generator/format/decoder.js +0 -0
- /package/{esm → dist/esm}/generator/format/index.js +0 -0
- /package/{esm → dist/esm}/generator/index.js +0 -0
- /package/{esm → dist/esm}/parser/data-parser.js +0 -0
- /package/{esm → dist/esm}/parser/index.js +0 -0
- /package/{esm → dist/esm}/parser/ini-parser.js +0 -0
- /package/{esm → dist/esm}/validation/errors.js +0 -0
- /package/{esm → dist/esm}/validation/index.js +0 -0
- /package/{esm → dist/esm}/validation/validate-input.js +0 -0
- /package/{typings → dist/typings}/api/generate-report.d.cts +0 -0
- /package/{typings → dist/typings}/api/generate-report.d.ts +0 -0
- /package/{typings → dist/typings}/api/parse-files.d.cts +0 -0
- /package/{typings → dist/typings}/api/parse-files.d.ts +0 -0
- /package/{typings → dist/typings}/format/index.d.cts +0 -0
- /package/{typings → dist/typings}/format/index.d.ts +0 -0
- /package/{typings → dist/typings}/format/newline.d.cts +0 -0
- /package/{typings → dist/typings}/format/newline.d.ts +0 -0
- /package/{typings → dist/typings}/format/padding.d.cts +0 -0
- /package/{typings → dist/typings}/format/padding.d.ts +0 -0
- /package/{typings → dist/typings}/generator/format/decoder.d.cts +0 -0
- /package/{typings → dist/typings}/generator/format/decoder.d.ts +0 -0
- /package/{typings → dist/typings}/generator/format/index.d.cts +0 -0
- /package/{typings → dist/typings}/generator/format/index.d.ts +0 -0
- /package/{typings → dist/typings}/generator/index.d.cts +0 -0
- /package/{typings → dist/typings}/generator/index.d.ts +0 -0
- /package/{typings → dist/typings}/parser/data-parser.d.cts +0 -0
- /package/{typings → dist/typings}/parser/data-parser.d.ts +0 -0
- /package/{typings → dist/typings}/parser/index.d.cts +0 -0
- /package/{typings → dist/typings}/parser/index.d.ts +0 -0
- /package/{typings → dist/typings}/parser/ini-parser.d.cts +0 -0
- /package/{typings → dist/typings}/parser/ini-parser.d.ts +0 -0
- /package/{typings → dist/typings}/validation/errors.d.cts +0 -0
- /package/{typings → dist/typings}/validation/errors.d.ts +0 -0
- /package/{typings → dist/typings}/validation/index.d.cts +0 -0
- /package/{typings → dist/typings}/validation/index.d.ts +0 -0
- /package/{typings → dist/typings}/validation/validate-input.d.cts +0 -0
- /package/{typings → dist/typings}/validation/validate-input.d.ts +0 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Helper Utilities for SHAAM Uniform Format Generator
|
|
3
|
+
* Provides utilities for creating and managing File objects
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Creates a File object with the given text content and filename
|
|
7
|
+
* This is a utility function to standardize File creation across the package
|
|
8
|
+
*
|
|
9
|
+
* @param text - The text content for the file
|
|
10
|
+
* @param name - The filename (should include extension)
|
|
11
|
+
* @param options - Optional File constructor options
|
|
12
|
+
* @returns A File object containing the text content
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const iniFile = createFile(iniText, 'report.INI.TXT');
|
|
17
|
+
* const dataFile = createFile(dataText, 'report.BKMVDATA.TXT');
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function createFile(text, name, options = { type: 'text/plain' }) {
|
|
21
|
+
if (!text || typeof text !== 'string') {
|
|
22
|
+
throw new Error('Text content must be a non-empty string');
|
|
23
|
+
}
|
|
24
|
+
if (!name || typeof name !== 'string') {
|
|
25
|
+
throw new Error('Filename must be a non-empty string');
|
|
26
|
+
}
|
|
27
|
+
// Ensure we have proper line endings for SHAAM format
|
|
28
|
+
const normalizedText = text.replace(/\r?\n/g, '\r\n');
|
|
29
|
+
return new File([normalizedText], name, {
|
|
30
|
+
type: 'text/plain',
|
|
31
|
+
...options,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates an INI.TXT File object with standardized naming
|
|
36
|
+
*
|
|
37
|
+
* @param iniText - The INI text content
|
|
38
|
+
* @param baseFileName - Base filename (without extension)
|
|
39
|
+
* @returns A File object for the INI file
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const iniFile = createIniFile(iniText, 'my-report');
|
|
44
|
+
* // Creates file named: my-report.INI.TXT
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function createIniFile(iniText, baseFileName = 'report') {
|
|
48
|
+
const fileName = `${baseFileName}.INI.TXT`;
|
|
49
|
+
return createFile(iniText, fileName);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a BKMVDATA.TXT File object with standardized naming
|
|
53
|
+
*
|
|
54
|
+
* @param dataText - The data text content
|
|
55
|
+
* @param baseFileName - Base filename (without extension)
|
|
56
|
+
* @returns A File object for the data file
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const dataFile = createDataFile(dataText, 'my-report');
|
|
61
|
+
* // Creates file named: my-report.BKMVDATA.TXT
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export function createDataFile(dataText, baseFileName = 'report') {
|
|
65
|
+
const fileName = `${baseFileName}.BKMVDATA.TXT`;
|
|
66
|
+
return createFile(dataText, fileName);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates both INI and Data File objects from the report output
|
|
70
|
+
*
|
|
71
|
+
* @param iniText - The INI text content
|
|
72
|
+
* @param dataText - The data text content
|
|
73
|
+
* @param baseFileName - Base filename (without extension)
|
|
74
|
+
* @returns An object containing both File objects
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const { iniFile, dataFile } = createShaamFiles(iniText, dataText, 'my-report');
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function createShaamFiles(iniText, dataText, baseFileName = 'report') {
|
|
82
|
+
return {
|
|
83
|
+
iniFile: createIniFile(iniText, baseFileName),
|
|
84
|
+
dataFile: createDataFile(dataText, baseFileName),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Validates that a File object appears to be a valid SHAAM format file
|
|
89
|
+
*
|
|
90
|
+
* @param file - The File object to validate
|
|
91
|
+
* @param expectedType - Expected file type ('ini' | 'data')
|
|
92
|
+
* @returns True if the file appears valid
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const isValidIni = validateShaamFile(iniFile, 'ini');
|
|
97
|
+
* const isValidData = validateShaamFile(dataFile, 'data');
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export function validateShaamFile(file, expectedType) {
|
|
101
|
+
if (!file || !(file instanceof File)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
// Check filename convention
|
|
105
|
+
const expectedExtension = expectedType === 'ini' ? '.INI.TXT' : '.BKMVDATA.TXT';
|
|
106
|
+
if (!file.name.toUpperCase().endsWith(expectedExtension)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
// Check MIME type
|
|
110
|
+
if (file.type !== 'text/plain') {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
// Check that file has content
|
|
114
|
+
if (file.size === 0) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Reads text content from a File object
|
|
121
|
+
* This is an async utility for reading File objects back to text
|
|
122
|
+
*
|
|
123
|
+
* @param file - The File object to read
|
|
124
|
+
* @returns Promise that resolves to the text content
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const text = await readFileAsText(file);
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export async function readFileAsText(file) {
|
|
132
|
+
if (!file || !(file instanceof File)) {
|
|
133
|
+
throw new Error('Input must be a valid File object');
|
|
134
|
+
}
|
|
135
|
+
return file.text();
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Gets file information from a File object
|
|
139
|
+
*
|
|
140
|
+
* @param file - The File object to inspect
|
|
141
|
+
* @returns File information object
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const info = getFileInfo(iniFile);
|
|
146
|
+
* console.log(`File: ${info.name}, Size: ${info.size} bytes`);
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export function getFileInfo(file) {
|
|
150
|
+
if (!file || !(file instanceof File)) {
|
|
151
|
+
throw new Error('Input must be a valid File object');
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
name: file.name,
|
|
155
|
+
size: file.size,
|
|
156
|
+
type: file.type,
|
|
157
|
+
lastModified: file.lastModified,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* File naming utilities for SHAAM format files
|
|
162
|
+
*/
|
|
163
|
+
export const FileNaming = {
|
|
164
|
+
/**
|
|
165
|
+
* Generates a standardized INI filename
|
|
166
|
+
*/
|
|
167
|
+
iniFileName: (base = 'report') => `${base}.INI.TXT`,
|
|
168
|
+
/**
|
|
169
|
+
* Generates a standardized data filename
|
|
170
|
+
*/
|
|
171
|
+
dataFileName: (base = 'report') => `${base}.BKMVDATA.TXT`,
|
|
172
|
+
/**
|
|
173
|
+
* Extracts base filename from a SHAAM file
|
|
174
|
+
*/
|
|
175
|
+
extractBaseName: (fileName) => {
|
|
176
|
+
if (!fileName || !FileNaming.isValidShaamFileName(fileName)) {
|
|
177
|
+
return 'report';
|
|
178
|
+
}
|
|
179
|
+
const name = fileName.replace(/\.(INI|BKMVDATA)\.TXT$/i, '');
|
|
180
|
+
return name || 'report';
|
|
181
|
+
},
|
|
182
|
+
/**
|
|
183
|
+
* Validates filename follows SHAAM conventions
|
|
184
|
+
*/
|
|
185
|
+
isValidShaamFileName: (fileName) => {
|
|
186
|
+
return /\.(INI|BKMVDATA)\.TXT$/i.test(fileName);
|
|
187
|
+
},
|
|
188
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key generator utility for generating unique identifiers
|
|
3
|
+
* Used for fields 1004, 1103, and 1153 which require randomly generated unique IDs
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generates a random numeric string of specified length
|
|
7
|
+
* @param length - The length of the numeric string to generate (max 15 digits)
|
|
8
|
+
* @returns A random numeric string padded with leading zeros if necessary
|
|
9
|
+
*/
|
|
10
|
+
export function generateRandomKey(length = 15) {
|
|
11
|
+
if (length <= 0 || length > 15) {
|
|
12
|
+
throw new Error('Key length must be between 1 and 15 digits');
|
|
13
|
+
}
|
|
14
|
+
// Generate a random number with the specified number of digits
|
|
15
|
+
// For length 15, max value is 999,999,999,999,999 (15 nines)
|
|
16
|
+
const maxValue = Math.pow(10, length) - 1;
|
|
17
|
+
const minValue = Math.pow(10, length - 1); // Ensures we always get the full length
|
|
18
|
+
// Generate random number between minValue and maxValue
|
|
19
|
+
const randomNum = Math.floor(Math.random() * (maxValue - minValue + 1)) + minValue;
|
|
20
|
+
// Convert to string and pad with zeros if needed
|
|
21
|
+
return randomNum.toString().padStart(length, '0');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Generates a primary identifier for fields 1004, 1103, and 1153
|
|
25
|
+
* These fields must have the same value across all records in a single file
|
|
26
|
+
* @returns A 15-digit numeric string
|
|
27
|
+
*/
|
|
28
|
+
export function generatePrimaryIdentifier() {
|
|
29
|
+
return generateRandomKey(15);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Key generator context to maintain consistent IDs across records
|
|
33
|
+
* This ensures that fields 1004, 1103, and 1153 use the same value within a single file
|
|
34
|
+
*/
|
|
35
|
+
export class KeyGeneratorContext {
|
|
36
|
+
_primaryIdentifier = null;
|
|
37
|
+
/**
|
|
38
|
+
* Gets or generates the primary identifier for this context
|
|
39
|
+
* Ensures the same ID is used across all records that require it
|
|
40
|
+
*/
|
|
41
|
+
getPrimaryIdentifier() {
|
|
42
|
+
this._primaryIdentifier ||= generatePrimaryIdentifier();
|
|
43
|
+
return this._primaryIdentifier;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resets the context, generating new IDs for the next file
|
|
47
|
+
*/
|
|
48
|
+
reset() {
|
|
49
|
+
this._primaryIdentifier = null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Sets a specific primary identifier (useful for testing or when you have a specific ID requirement)
|
|
53
|
+
*/
|
|
54
|
+
setPrimaryIdentifier(id) {
|
|
55
|
+
if (!/^\d{1,15}$/.test(id)) {
|
|
56
|
+
throw new Error('Primary identifier must be a numeric string with 1-15 digits');
|
|
57
|
+
}
|
|
58
|
+
this._primaryIdentifier = id.padStart(15, '0');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Default key generator context instance
|
|
63
|
+
* Use this for most cases to ensure consistency across records
|
|
64
|
+
*/
|
|
65
|
+
export const defaultKeyGenerator = new KeyGeneratorContext();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@accounter/shaam-uniform-format-generator",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Fully typed application that generates, parses, and validates SHAAM uniform format tax reports (INI.TXT and BKMVDATA.TXT).",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"iconv-lite": "0.6.3",
|
|
7
|
+
"zod": "3.25.76"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/urigo/accounter-fullstack.git",
|
|
12
|
+
"directory": "packages/shaam-uniform-format-generator"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/urigo/accounter-fullstack/packages/shaam-uniform-format-generator#readme",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"shaam",
|
|
17
|
+
"uniform-format",
|
|
18
|
+
"accountancy",
|
|
19
|
+
"accountant",
|
|
20
|
+
"accounter",
|
|
21
|
+
"tax-reports",
|
|
22
|
+
"ini",
|
|
23
|
+
"bkmvdata"
|
|
24
|
+
],
|
|
25
|
+
"author": "Gil Gardosh <gilgardosh@gmail.com>",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": "^20.0.0 || >= 22"
|
|
29
|
+
},
|
|
30
|
+
"main": "cjs/index.js",
|
|
31
|
+
"module": "esm/index.js",
|
|
32
|
+
"typings": "typings/index.d.ts",
|
|
33
|
+
"typescript": {
|
|
34
|
+
"definition": "typings/index.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"type": "module",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./typings/index.d.cts",
|
|
41
|
+
"default": "./cjs/index.js"
|
|
42
|
+
},
|
|
43
|
+
"import": {
|
|
44
|
+
"types": "./typings/index.d.ts",
|
|
45
|
+
"default": "./esm/index.js"
|
|
46
|
+
},
|
|
47
|
+
"default": {
|
|
48
|
+
"types": "./typings/index.d.ts",
|
|
49
|
+
"default": "./esm/index.js"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"./package.json": "./package.json"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateUniformFormatReport } from './generate-report.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateUniformFormatReport } from './generate-report.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-width formatting utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Formats a field value with specified width and alignment
|
|
6
|
+
*
|
|
7
|
+
* @param value - The value to format
|
|
8
|
+
* @param width - Target field width
|
|
9
|
+
* @param align - Alignment ('left' or 'right')
|
|
10
|
+
* @param padChar - Character to use for padding (default: space)
|
|
11
|
+
* @returns Formatted fixed-width string
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatField(value: string, width: number, align: 'left' | 'right', padChar?: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Encodes a value to fixed-width format with padding
|
|
16
|
+
*
|
|
17
|
+
* @param value - The value to encode
|
|
18
|
+
* @param width - Target width
|
|
19
|
+
* @param padChar - Padding character (default: space)
|
|
20
|
+
* @param align - Alignment ('left' or 'right')
|
|
21
|
+
* @returns Fixed-width encoded string
|
|
22
|
+
*/
|
|
23
|
+
export declare function encodeFixedWidth(value: string | number, width: number, padChar?: string, align?: 'left' | 'right'): string;
|
|
24
|
+
/**
|
|
25
|
+
* Helper function to format numeric fields with zero padding
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatNumericField(value: string, width: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* Joins an array of field values into a single record line with CRLF ending
|
|
30
|
+
* This is used by individual record encoders to create their output
|
|
31
|
+
*
|
|
32
|
+
* @param fields - Array of formatted field values
|
|
33
|
+
* @returns Single record line ending with CRLF
|
|
34
|
+
*/
|
|
35
|
+
export declare function joinFields(fields: string[]): string;
|
|
36
|
+
/**
|
|
37
|
+
* Joins an array of record lines that already have CRLF endings
|
|
38
|
+
*
|
|
39
|
+
* @param lines - Array of record lines to join (each line should already end with CRLF)
|
|
40
|
+
* @returns Joined string
|
|
41
|
+
*/
|
|
42
|
+
export declare function joinRecords(lines: string[]): string;
|
|
43
|
+
/**
|
|
44
|
+
* Joins an array of record lines and adds CRLF to each line
|
|
45
|
+
*
|
|
46
|
+
* @param lines - Array of record lines to join (without CRLF endings)
|
|
47
|
+
* @returns Joined string with CRLF line endings
|
|
48
|
+
*/
|
|
49
|
+
export declare function joinLinesWithCRLF(lines: string[]): string;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a complete SHAAM format file by joining records
|
|
52
|
+
* This is the main function for assembling final file content
|
|
53
|
+
*
|
|
54
|
+
* @param records - Array of encoded record strings (each already ending with CRLF)
|
|
55
|
+
* @returns Complete file content ready for output
|
|
56
|
+
*/
|
|
57
|
+
export declare function assembleFile(records: string[]): string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-width formatting utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Formats a field value with specified width and alignment
|
|
6
|
+
*
|
|
7
|
+
* @param value - The value to format
|
|
8
|
+
* @param width - Target field width
|
|
9
|
+
* @param align - Alignment ('left' or 'right')
|
|
10
|
+
* @param padChar - Character to use for padding (default: space)
|
|
11
|
+
* @returns Formatted fixed-width string
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatField(value: string, width: number, align: 'left' | 'right', padChar?: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Encodes a value to fixed-width format with padding
|
|
16
|
+
*
|
|
17
|
+
* @param value - The value to encode
|
|
18
|
+
* @param width - Target width
|
|
19
|
+
* @param padChar - Padding character (default: space)
|
|
20
|
+
* @param align - Alignment ('left' or 'right')
|
|
21
|
+
* @returns Fixed-width encoded string
|
|
22
|
+
*/
|
|
23
|
+
export declare function encodeFixedWidth(value: string | number, width: number, padChar?: string, align?: 'left' | 'right'): string;
|
|
24
|
+
/**
|
|
25
|
+
* Helper function to format numeric fields with zero padding
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatNumericField(value: string, width: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* Joins an array of field values into a single record line with CRLF ending
|
|
30
|
+
* This is used by individual record encoders to create their output
|
|
31
|
+
*
|
|
32
|
+
* @param fields - Array of formatted field values
|
|
33
|
+
* @returns Single record line ending with CRLF
|
|
34
|
+
*/
|
|
35
|
+
export declare function joinFields(fields: string[]): string;
|
|
36
|
+
/**
|
|
37
|
+
* Joins an array of record lines that already have CRLF endings
|
|
38
|
+
*
|
|
39
|
+
* @param lines - Array of record lines to join (each line should already end with CRLF)
|
|
40
|
+
* @returns Joined string
|
|
41
|
+
*/
|
|
42
|
+
export declare function joinRecords(lines: string[]): string;
|
|
43
|
+
/**
|
|
44
|
+
* Joins an array of record lines and adds CRLF to each line
|
|
45
|
+
*
|
|
46
|
+
* @param lines - Array of record lines to join (without CRLF endings)
|
|
47
|
+
* @returns Joined string with CRLF line endings
|
|
48
|
+
*/
|
|
49
|
+
export declare function joinLinesWithCRLF(lines: string[]): string;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a complete SHAAM format file by joining records
|
|
52
|
+
* This is the main function for assembling final file content
|
|
53
|
+
*
|
|
54
|
+
* @param records - Array of encoded record strings (each already ending with CRLF)
|
|
55
|
+
* @returns Complete file content ready for output
|
|
56
|
+
*/
|
|
57
|
+
export declare function assembleFile(records: string[]): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* A000Sum Record Schema - Record count summary for INI.TXT
|
|
4
|
+
* Fields 1050-1051 based on SHAAM uniform format specification
|
|
5
|
+
*/
|
|
6
|
+
export declare const A000SumSchema: z.ZodObject<{
|
|
7
|
+
code: z.ZodString;
|
|
8
|
+
recordCount: z.ZodString;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
code: string;
|
|
11
|
+
recordCount: string;
|
|
12
|
+
}, {
|
|
13
|
+
code: string;
|
|
14
|
+
recordCount: string;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* A000Sum Input Schema - for user input (no auto-generated fields)
|
|
18
|
+
*/
|
|
19
|
+
export declare const A000SumInputSchema: z.ZodObject<{
|
|
20
|
+
code: z.ZodString;
|
|
21
|
+
recordCount: z.ZodString;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
code: string;
|
|
24
|
+
recordCount: string;
|
|
25
|
+
}, {
|
|
26
|
+
code: string;
|
|
27
|
+
recordCount: string;
|
|
28
|
+
}>;
|
|
29
|
+
export type A000Sum = z.infer<typeof A000SumSchema>;
|
|
30
|
+
export type A000SumInput = z.infer<typeof A000SumInputSchema>;
|
|
31
|
+
/**
|
|
32
|
+
* Encodes an A000Sum record to fixed-width string format
|
|
33
|
+
* Total line width: 19 characters + CRLF
|
|
34
|
+
*/
|
|
35
|
+
export declare function encodeA000Sum(input: A000SumInput): string;
|
|
36
|
+
/**
|
|
37
|
+
* Parses a fixed-width A000Sum record line back to object
|
|
38
|
+
* Expected line length: 19 characters (excluding CRLF)
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseA000Sum(line: string): A000Sum;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* A000Sum Record Schema - Record count summary for INI.TXT
|
|
4
|
+
* Fields 1050-1051 based on SHAAM uniform format specification
|
|
5
|
+
*/
|
|
6
|
+
export declare const A000SumSchema: z.ZodObject<{
|
|
7
|
+
code: z.ZodString;
|
|
8
|
+
recordCount: z.ZodString;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
code: string;
|
|
11
|
+
recordCount: string;
|
|
12
|
+
}, {
|
|
13
|
+
code: string;
|
|
14
|
+
recordCount: string;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* A000Sum Input Schema - for user input (no auto-generated fields)
|
|
18
|
+
*/
|
|
19
|
+
export declare const A000SumInputSchema: z.ZodObject<{
|
|
20
|
+
code: z.ZodString;
|
|
21
|
+
recordCount: z.ZodString;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
code: string;
|
|
24
|
+
recordCount: string;
|
|
25
|
+
}, {
|
|
26
|
+
code: string;
|
|
27
|
+
recordCount: string;
|
|
28
|
+
}>;
|
|
29
|
+
export type A000Sum = z.infer<typeof A000SumSchema>;
|
|
30
|
+
export type A000SumInput = z.infer<typeof A000SumInputSchema>;
|
|
31
|
+
/**
|
|
32
|
+
* Encodes an A000Sum record to fixed-width string format
|
|
33
|
+
* Total line width: 19 characters + CRLF
|
|
34
|
+
*/
|
|
35
|
+
export declare function encodeA000Sum(input: A000SumInput): string;
|
|
36
|
+
/**
|
|
37
|
+
* Parses a fixed-width A000Sum record line back to object
|
|
38
|
+
* Expected line length: 19 characters (excluding CRLF)
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseA000Sum(line: string): A000Sum;
|