Code Monkey home page Code Monkey logo

ofx-data-extractor's Introduction

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.
  • 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.

ofx-data-extractor's People

Contributors

dependabot[bot] avatar fabiofranca02 avatar fabiopf02 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ofx-data-extractor's Issues

Brazilian Nubank ofx import BUG

Describe the bug

pathFile = 'D:/server/shared/files/november.ofx';
const ofx = await Ofx.fromFilePath(pathFile);

To Reproduce
Steps to reproduce the behavior

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Backslash characters cause error

If, for example, a <MEMO> string has a backslash character, an error appears: Uncaught SyntaxError: JSON.parse: bad escaped character. Since backslash characters are allowed in strings in OFX files, this library should also allow them.

BUG: following browser example throws compile error

Describe the bug
Installed the module for a react application, and followed the code example for browser processing.

Once The application is started, there is a compile error displayed:
Compiled with problems:
×
ERROR in ./node_modules/ofx-data-extractor/dist/esm/index.min.js 191:4-16
Module not found: Error: Can't resolve 'fs' in './node_modules/ofx-data-extractor/dist/esm'

To Reproduce

  1. install the module
  2. user. the browser method to parse and OFX file
  3. start the application

Expected behavior
Expected the application to start without any errors since the node file system is not being used to read the file.

Desktop (please complete the following information):

  • OS: MacOS 14.2.1
  • Browser Mircrosoft Edge Version 121.0.2277.112
  • Module Version: 1.3.3

Plans to add support for CREDITCARDMSGSRSV1?

Thank you for developing such a cool project! Are there plans for this library to support CREDITCARDMSGSRSV1? I am working on a project which imports ofx/qfx files and am currently looking for a library that we can use. I am interested in using this library but it currently lacks support for CREDITCARDMSGSRSV1 which we need. It would be great if support can be added :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.