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 🙏

© 2026 – Pkg Stats / Ryan Hefner

transaction-serde

v2.2.1

Published

Transaction serialisation and deserialisation library

Readme

transaction-serde

A TypeScript library for serialising and deserialising financial transaction data between JSON, CSV, and QIF formats.

npm version License: MIT

Features

  • Multi-format support: Convert between JSON, CSV, and QIF (Quicken Interchange Format)
  • Automatic date parsing: Handles multiple date formats automatically
  • TypeScript support: Full type definitions included
  • Flexible CSV handling: Custom mapping functions for non-standard CSV formats
  • Browser & Node.js: Works in both environments

Installation

npm install transaction-serde

Quick Start

import { serialisers, deserialisers } from 'transaction-serde';

// Parse transactions from CSV
const csv = `date,amount,payee,description,category
2024-01-15,100.00,Salary,Monthly salary,Income
2024-01-16,-25.50,Coffee Shop,Morning coffee,Food & Drink`;

const transactions = deserialisers.csv(csv);

// Convert to JSON
const json = serialisers.json(transactions);

// Convert to QIF
const qif = serialisers.qif(transactions);

API

Transaction Type

All functions work with the Transaction type:

type Transaction = Partial<{
  date: Date;        // Transaction date
  amount: number;    // Amount (positive for income, negative for expenses)
  payee: string;     // Payee or merchant name
  description: string; // Transaction description/memo
  category: string;  // Category classification
}>;

Deserialisers

deserialisers.json(input: string): Transaction[]

Parses a JSON string containing an array of transaction objects.

const json = '[{"date":"2024-01-15","amount":100,"payee":"Store"}]';
const transactions = deserialisers.json(json);

deserialisers.csv(input: string, options?): Transaction[]

Parses a CSV string with headers into transactions.

// Standard CSV with matching headers
const transactions = deserialisers.csv(csvString);

// Custom mapping for non-standard headers
const transactions = deserialisers.csv(csvString, {
  headers: true,
  map: (row) => ({
    date: row.Date,
    amount: row.Value,
    payee: row.Merchant
  })
});

Options:

  • headers (boolean): Whether the CSV has headers. Default: true
  • map (function): Custom function to map CSV rows to transaction fields

deserialisers.qif(input: string): Transaction[]

Parses a QIF string into transactions.

const qif = `!Type:Bank
D2024-01-15
T100
PStore
^`;
const transactions = deserialisers.qif(qif);

Serialisers

serialisers.json(transactions: Transaction[]): string

Converts transactions to a JSON string with ISO date format.

const json = serialisers.json(transactions);
// '[{"date":"2024-01-15","amount":100,"payee":"Store"}]'

serialisers.csv(transactions: Transaction[]): string

Converts transactions to a CSV string with headers.

const csv = serialisers.csv(transactions);
// 'date,amount,payee,description,category\n"2024-01-15",100,"Store",...'

serialisers.qif(transactions: Transaction[], options?): string

Converts transactions to QIF format.

const qif = serialisers.qif(transactions);

// With options
const qif = serialisers.qif(transactions, {
  locale: 'en-GB',
  header: '!Type:CCard'
});

Options:

  • locale (string | string[]): Locale for number formatting. Default: 'en-US'
  • header (string): QIF account type header. Default: '!Type:Bank'

Available headers:

  • !Type:Bank - Bank account
  • !Type:Cash - Cash account
  • !Type:CCard - Credit card
  • !Type:Oth A - Other assets
  • !Type:Oth L - Liabilities

Date Handling

The library automatically parses dates in many common formats:

  • ISO format: 2024-01-15, 2024/01/15
  • UK format: 15/01/2024, 15-01-2024
  • US format: 01/15/2024, 01-15-2024
  • Text formats: 15 January 2024, Jan 15 2024

All dates are converted to UTC to ensure consistent handling across timezones.

Error Handling

The library throws errors for invalid input:

try {
  const transactions = deserialisers.json('not valid json');
} catch (error) {
  // Error: Input is not valid JSON
}

try {
  const transactions = deserialisers.qif('invalid header\ndata');
} catch (error) {
  // Error: Unknown header: invalid header
}

Browser Usage

The library is available as an ES module and IIFE bundle for browser use:

<!-- ES Module -->
<script type="module">
  import { serialisers, deserialisers } from 'transaction-serde';
</script>

<!-- IIFE Bundle -->
<script src="node_modules/transaction-serde/build/browser/index.iife.js"></script>
<script>
  const { serialisers, deserialisers } = transactionSerde;
</script>

Documentation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT