npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-swiftmessageparser

v2.0.1

Published

Swift financial message parser (MT940, MT942)

Downloads

4

Readme

Centrapay SWIFT Parser

SWIFT bank statement parser for JavaScript and Typescript (ES2015). Supports MT 940 Customer Statement Message and MT 942 Interim Transaction Report.

Installation

pnpm install stitch-swiftmessageparser

Usage

import parser from 'stitch-swiftmessageparser';
import * as fs from 'fs';

const statements = parser.parse({
  type: 'mt940',
  data: fs.readFileSync('./sample.txt', 'utf8'),
});

statements.forEach((stmt) => {
  console.log('stmt', stmt);
  stmt.transactions.forEach((txn) => {
    console.log(txn.amount, txn.currency);
  });
});

CLI

This package also includes a CLI which parses a SWIFT file and outputs the result as JSON:

swift-parse -t mt942 my-statement.txt

API

parser.parse()

Parse a SWIFT statement document.

If parser.parse() is invoked with { validate: true } then MT940 statements are additionally validated for:

  • all strictly required tags
  • opening/closing balance currency is the same
  • opening balance + turnover = closing balance

Returns: Array<Statement>

Params:

| Param | Type | Description | | -------- | ------- | ----------------------------------------------------- | | data | string | raw SWIFT message text | | type | string | message format (mt940 or mt942) | | validate | boolean | Optional perform additional semantic error checking |

Statement

| Field | Type | Description | | --------------------------- | --------- | -------------------------------------------------------------------------- | | transactionReference | string | tag 20 reference | | relatedReference | string | tag 21 reference | | accountIdentification | string | tag 25 own bank account identification | | number.statement | string | tag 28 main statement number | | number.sequence | string | tag 28 statement sub number (sequence) | | number.section | string | tag 28 statement sub sub number (present on some banks) | | statementDate | Date | tag 62 (MT940, day precision) or tag 13D (MT942, minute precision) | | openingBalanceDate | Date | tag 60 statement opening date | | closingBalanceDate | Date | tag 62 statement closing date | | closingAvailableBalanceDate | Date | tag 64 closing available balance date, default = closing date | | forwardAvailableBalanceDate | Date | tag 65 forward available balance date, default = closing available date | | currency | string | statement currency (USD, EUR ...) | | openingBalance | BigNumber | beginning balance of the statement (with sign, based on debit/credit mark) | | closingBalance | BigNumber | ending balance of the statement (with sign, based on debit/credit mark) | | closingAvailableBalance | BigNumber | tag 64 closing available balance, default = closing balance | | forwardAvailableBalance | BigNumber | tag 65 forward available balance, default = closing available | | informationToAccountOwner | string | additional statement level information | | transactions | array | collection of transactions | | messageBlocks | object | statement message blocks, if present (EXPERIMENTAL) |

Transaction

| Field | Type | Description | | ----------------- | --------- | ---------------------------------------------------------------------- | | date | Date | transaction date | | amount | BigNumber | transaction amount (with sign, Credit+, Debit-) | | reversal | Boolean | transaction is a reversal | | currency | string | transaction currency (copy of statement currency) | | details | string | content of relevant 86 tag(s), may be multiline (\n separated) | | transactionType | string | MT940 transaction type code (e.g. NTRF ...) | | reference | string | payment reference field | | entryDate | Date | entry date field | | fundsCode | string | funds code field | | bankReference | string | bank reference | | extraDetails | string | extra details (supplementary details) | | structuredDetails | Object | structured details if detected | | nonSwift | string | content of NS tags associated with a transaction (after tags 61 or 86) |

Structured Transaction Details

The transaction.structuredDetails attribute can be used to access structured data from statement transaction details (SWIFT "86" tag). The following structured detail formats are supported:

  • '<sep>DD', where <sep> can be '>' or '?' and DD is two digits
  • '/TAG/value', where TAG is 2 to 4 uppercase chars.

Example

>20some details >30more data
{
  "20": "some details",
  "30": "more data"
}

Example

/ORDP/Smith Corp
{
  "ORDP": "Smith Corp"
}

History

See Changelog

Legal

Copyright © 2015 Alexander Tsybulsky and other contributors. Copyright © 2020 Centrapay.

This software is licensed under Apache-2.0 License. Please see LICENSE for details.

Credits

Forked from a-fas/mt940. Originally inspired by WoLpH/mt940.