@tikpay/iso8583-ts
v0.2.0
Published
ISO 8583 parser written in TypeScript with LLVAR/LLLVAR enforcement, bitmap handling and built-in field level BCD/ASCII encoding.
Readme
A fast and type-safe ISO 8583 parser/encoder written in TypeScript, with strict LLVAR/LLLVAR enforcement, bitmap handling and built-in field level BCD/ASCII encoding.
🧰 Features
✔️ Type-safe message building & parsing
✔️ Field level BCD/ASCII encoding configuration
✔️ LLVAR / LLLVAR length enforcement
✔️ Bitmap parsing and generation
✔️ Dual build: ESM + CJS
🚀 Install
npm i @tikpay/iso8583-ts📦 Usage
Import
import { Iso8583, N, AN, ANS, B, bitmap } from '@tikpay/iso8583-ts' //ESMor
const { Iso8583, N, AN, ANS, B, bitmap } = require('@tikpay/iso8583-ts') //CJSDefine specification
import { AN, bitmap, LLVARn... } from '@tikpay/iso8583-ts'
export const sampleSpec: MessageSpec = {
0: { name: 'MTI', format: N(4, { encoding: NumericEncoding.BCD }) }, //optional
1: { name: 'Bitmap', format: bitmap(8) }, //optional
2: {
name: 'PAN',
format: LLVARn({
length: 19,
lenHeader: VarLenHeaderEncoding.BCD,
payload: VarPayloadEncoding.BCD_DIGITS,
lenCountMode: VarLenCountMode.DIGITS,
}),
},
22: { name: 'POSData', format: AN(12) },
35: { name: 'Track2', format: LLVARans({ length: 37 }) },
}Pack
const iso8583 = new Iso8583(sampleSpec)
const mti = '0200'
const paymentCall = {
3: '000000',
4: '00001000',
11: '123456',
12: '250910142500',
22: '9010A0B00000',
49: '036',
}
const { bytes, mti: packedMti } = iso8583.pack(mti, paymentCall)Unpack
const iso8583 = new Iso8583(sampleSpec)
const decoded = iso8583.unpack(bytes)
console.log(decoded.mti) // '0200'
console.log(decoded.fields) // { 3: '000000', 4: '00001000', ... }⭐ Inspiration
This library was inspired by excellent work from other ISO 8583 projects, including:
📄 License
This project is licensed under the terms of the MIT open source license.
