GithubHelp home page GithubHelp logo

dseller / mt940-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webschik/mt940-js

0.0 3.0 0.0 121 KB

A mt940 isomorphic Javascript parser

License: MIT License

JavaScript 1.56% TypeScript 98.44%

mt940-js's Introduction

mt940-js

Build Status npm npm npm Coverage Status

An isomorphic Javascript library for working with MT940 format

Reading

API

read(buffer, options)

  • buffer {Buffer|ArrayBuffer} - income buffer that contains data of mt940 file.
  • options {ReadOptions}
  • returns array of Statement.
ReadOptions
  • getTransactionId(transaction, index) - a custom generator for transaction id. By default it's:
/**
* @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:

Related links

JS

mt940 specification

mt940-js's People

Contributors

webschik avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.