# mt940-js

> An isomorphic Javascript library for working with MT940 format

Latest version **1.0.0** (published 2020-02-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install mt940-js
pnpm add mt940-js
yarn add mt940-js
bun add mt940-js
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-02-29 |
| First published | 2016-11-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 40 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | webschik |
| Maintainers | webschik |
| Keywords | JS, isomorphic, mt940 |

## Links

- npm: https://www.npmjs.com/package/mt940-js
- Repository: https://github.com/webschik/mt940-js
- Homepage: https://github.com/webschik/mt940-js#readme
- Issues: https://github.com/webschik/mt940-js/issues
- npm.io page: https://npm.io/package/mt940-js

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-02-29
- 0.6.0 — 2017-11-06
- 0.5.2 — 2017-08-02
- 0.5.1 — 2017-07-27
- 0.5.0 — 2017-06-26
- 0.4.1 — 2017-01-26
- 0.4.0 — 2017-01-22
- 0.3.0 — 2017-01-15
- 0.2.0 — 2016-12-26
- 0.1.1 — 2016-11-27
- 0.1.0 — 2016-11-27

## README

# mt940-js
[![Build Status](https://travis-ci.org/webschik/mt940-js.svg?branch=master)](https://travis-ci.org/webschik/mt940-js)
[![npm](https://img.shields.io/npm/dm/mt940-js.svg)](https://www.npmjs.com/package/mt940-js)
[![npm](https://img.shields.io/npm/v/mt940-js.svg)](https://www.npmjs.com/package/mt940-js)
[![npm](https://img.shields.io/npm/l/mt940-js.svg)](https://www.npmjs.com/package/mt940-js)
[![Coverage Status](https://coveralls.io/repos/github/webschik/mt940-js/badge.svg?branch=master)](https://coveralls.io/github/webschik/mt940-js?branch=master)

> An isomorphic Javascript library for working with [MT940](#related-links) format

# [Changelog](CHANGELOG.md)

## Reading
### API
#### read(buffer, options)
* `buffer` {Buffer|ArrayBuffer} - income buffer that contains data of mt940 file.
* `options` {ReadOptions}
* returns `Promise` with list of [Statement](src/index.ts#L49).

##### 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
````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) => {
        //
    });
});
````

### Browser environment
#### Reading a local file
````html
<input type="file" onchange="onFileSelected(this.files[0])"/>
````
````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
        });
    });
````

## Writing
Coming soon

## Supported MT940 tags
* **:20:**
* **:21:**
* **:25:**
* **:28(C):**
* **:60(M|F):**
* **:61:**
* **:62(M|F):**
* **:64:**
* **:65:**
* **:86:**

## Related links
### JS
* [Buffer](https://nodejs.org/api/buffer.html)
* [ArrayBuffer](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)

### mt940 specification
* [Societe Generale spec.](https://web.archive.org/web/20160725042101/http://www.societegenerale.rs/fileadmin/template/main/pdf/SGS%20MT940.pdf)
* [Sepa spec.](http://www.sepaforcorporates.com/swift-for-corporates/account-statement-mt940-file-format-overview/)
* [Deutsche Bank spec.](https://deutschebank.nl/nl/docs/MT94042_EN.pdf)

---
_Source: https://npm.io/package/mt940-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
