@centrapay/swift-parser

中文文档
1.0.3发布于 2026/11/03Apache-2.0CommonJS构建来源已验证近 30 天下载 1万

Swift financial message parser (MT940, MT942)

原始使用文档
文档目录11 节
  1. Installation
  2. Usage
  3. CLI
  4. API
  5. parser.parse()
  6. Statement
  7. Transaction
  8. Structured Transaction Details
  9. History
  10. Legal
  11. Credits

Centrapay SWIFT Parser

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

Installation

npm install @centrapay/swift-parser

Usage

const parser = require('@centrapay/swift-parser');
const statements = parser.parse({
  type: 'mt940',
  data: fs.readFileSync(path, 'utf8'),
});

statements.forEach(stmt => {
  console.log(stmt.statementDate, stmt.accountIdentification, stmt.number.statement);
  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:

ParamTypeDescription
datastringraw SWIFT message text
typestringmessage format (mt940 or mt942)
validatebooleanOptional perform additional semantic error checking

Statement

FieldTypeDescription
transactionReferencestringtag 20 reference
relatedReferencestringtag 21 reference
accountIdentificationstringtag 25 own bank account identification
number.statementstringtag 28 main statement number
number.sequencestringtag 28 statement sub number (sequence)
number.sectionstringtag 28 statement sub sub number (present on some banks)
statementDateDatetag 62 (MT940, day precision) or tag 13D (MT942, minute precision)
openingBalanceDateDatetag 60 statement opening date
closingBalanceDateDatetag 62 statement closing date
closingAvailableBalanceDateDatetag 64 closing available balance date, default = closing date
forwardAvailableBalanceDateDatetag 65 forward available balance date, default = closing available date
currencystringstatement currency (USD, EUR ...)
openingBalanceBigNumberbeginning balance of the statement (with sign, based on debit/credit mark)
closingBalanceBigNumberending balance of the statement (with sign, based on debit/credit mark)
closingAvailableBalanceBigNumbertag 64 closing available balance, default = closing balance
forwardAvailableBalanceBigNumbertag 65 forward available balance, default = closing available
informationToAccountOwnerstringadditional statement level information
transactionsarraycollection of transactions
messageBlocksobjectstatement message blocks, if present (EXPERIMENTAL)

Transaction

FieldTypeDescription
dateDatetransaction date
amountBigNumbertransaction amount (with sign, Credit+, Debit-)
reversalBooleantransaction is a reversal
currencystringtransaction currency (copy of statement currency)
detailsstringcontent of relevant 86 tag(s), may be multiline (\n separated)
transactionTypestringMT940 transaction type code (e.g. NTRF ...)
referencestringpayment reference field
entryDateDateentry date field
fundsCodestringfunds code field
bankReferencestringbank reference
extraDetailsstringextra details (supplementary details)
structuredDetailsObjectstructured details if detected
nonSwiftstringcontent 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

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.

版本与发布记录

@centrapay/swift-parser 共发布 6 个版本,首次发布于 2020/08/03;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.3latest2026/11/036 天前
1.0.22026/10/051 个月前
1.0.12024/10/302 年前
1.0.02020/08/056 年前
0.2.02020/08/036 年前
0.1.02020/08/036 年前

关于 @centrapay/swift-parser 的常见问题

@centrapay/swift-parser 是什么?

Swift financial message parser (MT940, MT942)

如何安装 @centrapay/swift-parser?

在项目目录运行 npm install @centrapay/swift-parser,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 swift-parse,可以用 npx swift-parse 直接运行。

@centrapay/swift-parser 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/centrapay__swift-parser 是否存在。

@centrapay/swift-parser 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@centrapay/swift-parser 可以商用吗?

@centrapay/swift-parser 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@centrapay/swift-parser 的下载量有多少?

根据 npm 官方下载统计,@centrapay/swift-parser 在 2026/10/10 – 2026/11/08 这 30 天内被下载 10,432 次,日均约 348 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@centrapay/swift-parser 还在维护吗?

最新版本 1.0.3 发布于 2026/11/03(6 天前);至今共发布 6 个版本,其中过去 12 个月发布了 2 个;首次发布于 2020/08/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。