🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

mt940js

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mt940js - npm Package Compare versions

Comparing version
1.3.2
to
1.3.3
test/test-with-NS.mt940x

Sorry, the diff of this file is not supported yet

+5
-0

@@ -11,2 +11,7 @@ mt940-js changelog

2019-12-03 v1.3.3
------------------
+ Support for NS fields in the context of transactions (saved to 'nonSwift' attribute)
+ Support for GVC at the beginning of payment details (thanks to @artur-krueger)
2019-01-31 v1.3.1

@@ -13,0 +18,0 @@ ------------------

+8
-3

@@ -28,8 +28,13 @@ class Field86StructureParser {

details = details.replace(/\n/g, '').trim();
const parsedStruc = {};
if (details.match(/^\d\d\d[\?\>]/)) {
parsedStruc.gvc = details.substr(0,3);
details = details.substr(3);
}
const rule = Field86StructureParser.buildTagRe(details);
if (!rule) return;
if (!rule.detect.test(details)) return; // string must start with tag
const parsedStruc = {};
let match = rule.match.exec(details);

@@ -36,0 +41,0 @@ while (match) {

@@ -49,2 +49,3 @@ /**

* @property {Object} transaction.structuredDetails - optional, if detected, parsed details in form of { subtag: value }
* @property {string} transaction.nonSwift - optional, content of NS tags which happened in the context of transaction (after tags 61 or 86), can be multiline (separated by `\n`)
* @example

@@ -316,3 +317,9 @@ * const mt940parser = new Parser();

}
prevTag = tag;
if (tag instanceof Tags.TagNonSwift) {
if (prevTag instanceof Tags.TagStatementLine || prevTag instanceof Tags.TagTransactionDetails) {
let t = statement.transactions[statement.transactions.length - 1];
t.nonSwift = tag.data;
}
}
if (!(tag instanceof Tags.TagNonSwift)) prevTag = tag;
}

@@ -319,0 +326,0 @@

{
"name": "mt940js",
"version": "1.3.2",
"version": "1.3.3",
"description": "javascript mt940 bank statement parser",

@@ -8,3 +8,3 @@ "main": "index.js",

"test": "mocha",
"testwatch": "mocha --watch",
"testw": "mocha --watch",
"lint": "eslint lib test cli.js index.js",

@@ -11,0 +11,0 @@ "coverage": "istanbul cover ./node_modules/mocha/bin/_mocha",

@@ -75,2 +75,3 @@ # SWIFT MT940 bank statement format JS parser

- `structuredDetails` {Object} - structured details if detected, in for of `{ subtag: value }` e.g. `{ '20': '123456' }`
- `nonSwift` {string} - optional, content of NS tag which happened in the context of transaction (after tags 61 or 86), can be multiline (separated by `\n`)

@@ -77,0 +78,0 @@ Each statement is validated for:

@@ -336,2 +336,115 @@ const assert = require('chai').assert;

});
/* NS TESTS */
describe('NS tests', () => {
const DUMMY_STATEMENT_LINES_WITH_NS = [
':20:B4E08MS9D00A0009',
':21:X',
':25:123456789',
':28C:123/1',
':60F:C140507EUR0,00',
':61:1405070507C100,00NTRFNONREF//AUXREF',
':86:LINE1',
':61:1405070507C200,00NTRFNONREF//AUXREF',
':NS:Hello world',
':86:LINE2',
':61:1405070507C300,00NTRFNONREF//AUXREF',
':86:LINE3',
':NS:Hello',
'bank info',
':62F:C140508EUR600,00',
];
it('_parseLines with NS', () => {
const parser = new Parser();
const result = [...parser._parseLines(DUMMY_STATEMENT_LINES_WITH_NS)];
assert.deepEqual(result, [
{id: '20', subId: '', data: ['B4E08MS9D00A0009']},
{id: '21', subId: '', data: ['X']},
{id: '25', subId: '', data: ['123456789']},
{id: '28', subId: 'C', data: ['123/1']},
{id: '60', subId: 'F', data: ['C140507EUR0,00']},
{id: '61', subId: '', data: ['1405070507C100,00NTRFNONREF//AUXREF']},
{id: '86', subId: '', data: ['LINE1']},
{id: '61', subId: '', data: ['1405070507C200,00NTRFNONREF//AUXREF']},
{id: 'NS', subId: '', data: ['Hello world']},
{id: '86', subId: '', data: ['LINE2']},
{id: '61', subId: '', data: ['1405070507C300,00NTRFNONREF//AUXREF']},
{id: '86', subId: '', data: ['LINE3']},
{id: 'NS', subId: '', data: ['Hello', 'bank info']},
{id: '62', subId: 'F', data: ['C140508EUR600,00']},
]);
});
it('statement with NS', () => {
const parser = new Parser();
const result = parser.parse(DUMMY_STATEMENT_LINES_WITH_NS.join('\n'));
assert.equal(result.length, 1);
assert.deepEqual(result[0], {
transactionReference: 'B4E08MS9D00A0009',
relatedReference: 'X',
accountIdentification: '123456789',
number: {
statement: '123',
sequence: '1',
section: ''
},
statementDate: helpers.Date.parse('14', '05', '08'),
openingBalanceDate: helpers.Date.parse('14', '05', '07'),
closingBalanceDate: helpers.Date.parse('14', '05', '08'),
currency: 'EUR',
openingBalance: 0.0,
closingBalance: 600.0,
closingAvailableBalanceDate: helpers.Date.parse('14', '05', '08'),
forwardAvailableBalanceDate: helpers.Date.parse('14', '05', '08'),
closingAvailableBalance: 600.0,
forwardAvailableBalance: 600.0,
transactions: [
{
amount: 100.00,
isReversal: false,
currency: 'EUR',
reference: 'NONREF',
bankReference: 'AUXREF',
transactionType: 'NTRF',
date: helpers.Date.parse('14', '05', '07'),
entryDate: helpers.Date.parse('14', '05', '07'),
details: 'LINE1',
extraDetails: '',
fundsCode: '',
},
{
amount: 200.00,
isReversal: false,
currency: 'EUR',
reference: 'NONREF',
bankReference: 'AUXREF',
transactionType: 'NTRF',
date: helpers.Date.parse('14', '05', '07'),
entryDate: helpers.Date.parse('14', '05', '07'),
details: 'LINE2',
extraDetails: '',
fundsCode: '',
nonSwift: 'Hello world',
},
{
amount: 300.00,
isReversal: false,
currency: 'EUR',
reference: 'NONREF',
bankReference: 'AUXREF',
transactionType: 'NTRF',
date: helpers.Date.parse('14', '05', '07'),
entryDate: helpers.Date.parse('14', '05', '07'),
details: 'LINE3',
extraDetails: '',
fundsCode: '',
nonSwift: 'Hello\nbank info',
},
]});
});
});
});