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

ofx-data-extractor

v1.4.0

Published

A module written in TypeScript that provides a utility to extract data from an OFX file in Node.js and Browser

Downloads

4,551

Readme

ofx-data-extractor

npm version MIT License codecov

Ofx Data Extractor and Formatter

This is a Node.js and Browser module written in TypeScript that provides a utility for extracting data from an OFX file. The module can also format some of the data and retrieve specific parts of the file if requested.

Installation

You can install this module using the Node Package Manager (NPM) with the following command:

npm

npm install ofx-data-extractor

yarn

yarn add ofx-data-extractor

Methods

The Ofx class provides the following methods:

  • fromBuffer(data: Buffer): Used to read files on the node. Returns the methods
  • fromBlob(data: Blob): Used to read files in the browser. Returns the methods below.
  • config(options: OfxConfig): Used for formatting the generated json.`
  • getHeaders(): OFXMetaData: Returns the metadata section of the OFX file as an object.
  • getBankTransferList(): Pick<BankTransferList, 'STRTTRN'>: Returns a list of bank transfer transactions as an object.
  • getCreditCardTransferList(): Pick<BankTransferList, 'STRTTRN'>: Returns a list of credit card transactions as an object.
  • getTransactionsSummary(): Object: Returns a summary of transactions for a bank statement as an object.
  • getContent(): OfxStructure: Returns the OFX file content as an object.
  • toJson(): OfxResponse: Returns the entire OFX file content as a JSON object.

Usage

The module provides a class called Ofx that can be used to extract and format data from an OFX file. Here's an example of how to use it:

import { Ofx } from 'ofx-data-extractor'

const data = 'OFXHEADER:100\nDATA:OFXSGML\nVERSION:102\n...'
const ofx = new Ofx(data) // works in node.js and browser

const headers = ofx.getHeaders()
console.log(headers)

const transactionsSummary = ofx.getTransactionsSummary()
console.log(transactionsSummary)

const bankTransferList = ofx.getBankTransferList()
console.log(bankTransferList)

const ofxResponse = ofx.toJson()
console.log(ofxResponse)

Constructor

The Ofx class constructor takes in two arguments:

data: The OFX file content as a string or a Buffer. config: Optional configuration options for formatting the OFX data.

Read data - static methods (Node.js)

import { Ofx } from 'ofx-data-extractor'
import fs from 'fs'

const file = await fs.readFile('/path/to/file')
const ofx = await Ofx.fromBuffer(file)

const ofxResponse = ofx.toJson()
console.log(ofxResponse)

Read data - static methods (Browser)

import { Ofx } from 'ofx-data-extractor'

function handleFile(event) {
    const ofx = Ofx.fromBlob(event.target.files[0])
    const ofxResponse = ofx.toJson()
    console.log(ofxResponse)
}

// tsx/jsx/html
<input type="file" onChange={handleFile} />

Configuration

The Ofx (constructor and config method) class can be configured with the following options:

  • formatDate: A function that takes in a date string and returns a formatted date string.
  • fitId: A string that determines how the financial institution transaction ID is handled. Possible values are "separated" (the default) or "included".
  • nativeTypes: A boolean value that determines whether numeric fields should be represented as numbers or strings in the resulting JSON object.