Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mt940-js

webschik4.8kMIT1.0.0TypeScript support: included

An isomorphic Javascript library for working with MT940 format

JS, isomorphic, mt940

readme

mt940-js

Build Status npm npm npm Coverage Status

An isomorphic Javascript library for working with MT940 format

Changelog

Reading

API

read(buffer, options)

  • buffer {Buffer|ArrayBuffer} - income buffer that contains data of mt940 file.
  • options {ReadOptions}
  • returns Promise with list of Statement.
ReadOptions
  • getTransactionId(transaction, index) - a custom generator for transaction id. By default it's: `js /**
  • @description version 0.5.x
  • @param {Transaction} transaction
  • @param {number} index
  • @returns {string} */ function getTransactionId (transaction, index) { return md5(${ date }${ transaction.description }${ amount }${ transaction.currency }); }

/**

  • @description version 0.6.x+
  • @param {Transaction} transaction
  • @param {number} index
  • @returns {string} */ function getTransactionId (transaction, index) { return md5(JSON.strinfigy(transaction)); } `

Node.js environment

import * as mt940 from 'mt940-js';
import fs from 'fs';

fs.readFile('/path/to/your/mt940/file', (error, buffer) => {
    mt940.read(buffer).then((statements) => {
        //
    });
});

Browser environment

Reading a local file

<input type="file" onchange="onFileSelected(this.files[0])"/>
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

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
        });
    });

Writing

Coming soon

Supported MT940 tags

  • :20:
  • :21:
  • :25:
  • :28(C):
  • :60(M|F):
  • :61:
  • :62(M|F):
  • :64:
  • :65:
  • :86:

JS

mt940 specification

changelog

1.0.0

0.6.0

0.5.2

  • fix parsing of customer and bank references

0.5.1

  • fix transactions parsing

0.5.0

  • parse bank and customer references in transaction info, tag :61:
  • refactoring. Build the module only with Typescript, without Webpack

0.4.1

  • removed Webpack polyfills

0.4.0

  • added id property to transaction info
  • added isExpense property to transaction info

0.3.0

  • Transaction description
    • filter symbols \r, \n
    • replace multiple spaces by 1 space symbol

0.2.0

  • added npm-shrinkwrap.json
  • added Transaction, BalanceInfo interfaces to .d.ts file

0.1.0