An isomorphic Javascript library for working with MT940 format
npm install mt940-js> An isomorphic Javascript library for working with MT940 format
buffer {Buffer|ArrayBuffer} - income buffer that contains data of mt940 file.options {ReadOptions}Promise with list of Statement.##### ReadOptions
* getTransactionId(transaction, index) - a custom generator for transaction id. By default it's:
``js${ date }${ transaction.description }${ amount }${ transaction.currency }
/**
* @description version 0.5.x
* @param {Transaction} transaction
* @param {number} index
* @returns {string}
*/
function getTransactionId (transaction, index) {
return md5();
}
/**
* @description version 0.6.x+
* @param {Transaction} transaction
* @param {number} index
* @returns {string}
*/
function getTransactionId (transaction, index) {
return md5(JSON.strinfigy(transaction));
}
`
js
import * as mt940 from 'mt940-js';
import fs from 'fs';fs.readFile('/path/to/your/mt940/file', (error, buffer) => {
mt940.read(buffer).then((statements) => {
//
});
});
``$3
#### Reading a local file
``html
``
``js
import * as mt940 from 'mt940-js';function onFileSelected (file) {
const reader = new FileReader();
reader.onload = () => {
mt940.read(reader.result).then((statements) => {
// List of the Statements
});
};
reader.readAsArrayBuffer(file);
}
``
#### Reading a remote file
``js
import * as mt940 from 'mt940-js';fetch('/url/to/mt940/file')
.then((response) => response.arrayBuffer())
.then((buffer) => {
mt940.read(buffer).then((statements) => {
// List of the Statements
});
});
```