New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ofx-data-extractor

Package Overview
Dependencies
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ofx-data-extractor - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

2

dist/common/constants.d.ts

@@ -9,3 +9,5 @@ export declare const ELEMENT_CLOSURE_REGEX: RegExp;

export declare const FINISH_STATEMENT_TRANSACTION = "</STMTTRN>";
export declare const QUOTE_PATTERN = "_#_";
export declare const QUOTE_PATTERN_REGEX: RegExp;
export declare const OPENING_TAGS_INITIALLY_IGNORED: string[];
export declare const CLOSING_TAGS_INITIALLY_IGNORED: string[];

16

dist/esm/index.min.js

@@ -1,11 +0,11 @@

// Ofx-data-extractor v1.4.0 Copyright (c) 2024 Fábio Pereira França
const N=/<\/\w+>/g,x=/<\w+>/g,f="<BANKMSGSRSV1>",l="</BANKMSGSRSV1>",d="<CREDITCARDMSGSRSV1>",g="</CREDITCARDMSGSRSV1>",S="<STMTTRN>",u="</STMTTRN>",O=[f,S,d],M=[l,g,u];function y(e){const t=e.slice(0,4),n=e.slice(4,6),r=e.slice(6,8),s=e.slice(8,10),a=e.slice(10,12),i=e.slice(12,14);return{yyyy:t,yy:t.slice(2),y:t,MM:n,M:n,dd:r,d:r,hh:s,h:s,mm:a,m:a,ss:i,s:i}}function L(e,t){const n=y(e);let r=t;for(const[s,a]of Object.entries(n))r=r.replace(s,a);return r}function T(e){return e.replace(/(\\)/g,"\\\\").replace(N,t=>w(t,!0)).replace(x,t=>p(t,!0)).replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/({")/g,`{
// Ofx-data-extractor v1.4.1 Copyright (c) 2024 Fábio Pereira França
const E=/<\/\w+>/g,x=/<\w+>/g,l="<BANKMSGSRSV1>",f="</BANKMSGSRSV1>",d="<CREDITCARDMSGSRSV1>",g="</CREDITCARDMSGSRSV1>",S="<STMTTRN>",T="</STMTTRN>",N="_#_",M=new RegExp(N,"g"),y=[l,S,d],L=[f,g,T];function b(e){const t=e.slice(0,4),n=e.slice(4,6),r=e.slice(6,8),s=e.slice(8,10),a=e.slice(10,12),i=e.slice(12,14);return{yyyy:t,yy:t.slice(2),y:t,MM:n,M:n,dd:r,d:r,hh:s,h:s,mm:a,m:a,ss:i,s:i}}function _(e,t){const n=b(e);let r=t;for(const[s,a]of Object.entries(n))r=r.replace(s,a);return r}function u(e){return e.replace(/(\\)/g,"\\\\").replace(E,t=>D(t,!0)).replace(x,t=>w(t,!0)).replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(]")/g,'],"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/({")/g,`{
"`).replace(/(})/g,`
}`).replace(/(",")/g,`",
"`).replace(/,\s*}/g,`
}`).replace(/(,",)/,",").slice(0,-1)}const b=e=>JSON.stringify({date:e.slice(0,12),transactionCode:e.slice(12,19),protocol:e.slice(19)}),k=e=>e.startsWith("DT"),E=e=>e.trim();function p(e,t=!1){return O.includes(e)&&!t?e:e.replace(/[<]/g,`
"`).replace(/[>]/g,'":{')}function w(e,t=!1){return M.includes(e)&&!t?`
${e}`:"},"}function _({fitId:e,fitValue:t}){return e==="separated"?b(t):`"${t}",`}function G(e){return e.search(",")>e.search(".")?e.replace(/[.]/g,"").replace(/[,]/g,"."):e.replace(/[,]/g,"")}function F({dateString:e,formatDate:t="y-M-d"}){return L(e,t)}function J(e){let t=e.value.replace(/[{]/g,"").replace(/(},)/g,"");const n=e.field.replace(/['"]/g,"");return n.endsWith("AMT")&&(t=G(t)),k(n)&&(t=F({dateString:t,formatDate:e.formatDate})),n==="FITID"?_({fitId:e.fitId,fitValue:t}):e.nativeTypes&&D(n,t)?`${Number(t)},`:`"${t}",`}function K(e,t){let n=e;return e.match(/{(\w|\W)+/)&&(n=n.replace(/({(\w|\W)+)$/,r=>J({field:n.slice(0,n.indexOf(":")),value:r,...t}))),n}function D(e,t){return e.endsWith("ID")||e.endsWith("NUM")?!1:!isNaN(Number(t))}function A(e){const t=e.indexOf(S),n=e.lastIndexOf(u)+u.length,r=e.substring(t,n),s=new RegExp(S,"g"),a=new RegExp(u,"g"),i=`"STRTTRN":[${r.replace(s,"{").replace(a,"},")}]`;return{oldListText:e,newListText:e.replace(r,i)}}function R(e){if(!(e.indexOf(f)>0))return{newBankStatementTransactions:null,oldBankStatementTransactions:null};const n=A(e.substring(e.indexOf(f),e.indexOf(l)+l.length));return{newBankStatementTransactions:n.newListText,oldBankStatementTransactions:n.oldListText}}function C(e){if(!(e.indexOf(d)>0))return{newCreditCardStatementTransactions:null,oldCreditCardStatementTransactions:null};const n=e.substring(e.indexOf(d),e.indexOf(g)+g.length),r=A(n);return{newCreditCardStatementTransactions:r.newListText,oldCreditCardStatementTransactions:r.oldListText}}function P(e){const t=[];for(const n of e)t.push(...n.replace("<?xml"," ").replace("<?OFX"," ").replace("?>"," ").split(" ").filter(Boolean).map(E).map(r=>r.replace("=",":").replace(/["]/g,"")));return t}function $(e,t){const n={};e.join("").search("<?")>-1&&(e=P(e));for(const r of e){const[s,a]=r.split(":"),i=s.replace(`
`,"").toUpperCase();n[i]=t&&D(s,a)?Number(a):a}return n}function X(e){return e.reduce((t,n)=>n.TRNTYPE.toLocaleLowerCase().startsWith("deb")?(t.amountOfDebits++,t.debit+=Number(n.TRNAMT.replace("-","")),t):(t.amountOfCredits++,t.credit+=Number(n.TRNAMT),t),{credit:0,debit:0,amountOfCredits:0,amountOfDebits:0})}class z{config;internConfig={};constructor(t){this.config=t,this.internConfig=t}getConfig(){return this.internConfig}sanitizeRow(t){return K(t,this.internConfig)}getPartialJsonData(t){const[n,r]=t.split("<OFX>"),s="<OFX>"+r,{sanitizeRow:a}=this;return s.replace(N,i=>w(i)).replace(x,i=>p(i)).split(`
`).map(E).filter(Boolean).map(a,this).join("")}}function h(e){return e.toString()}async function I(e){return await new Promise((n,r)=>{if(typeof window<"u"&&window.FileReader){const s=new window.FileReader;s.onload=a=>n(a.target.result),s.onerror=a=>r(a.target.error),s.readAsText(e)}else r(new Error("FileReader is not available in this environment."))})}class o{data;dataRead="";constructor(t){this.data=t,t&&(this.dataRead=t)}getData(){return this.dataRead}fromString(t){return new o(t)}fromBuffer(t){return new o(h(t))}async fromBlob(t){return new o(await I(t))}static fromString(t){return new o(t)}static fromBuffer(t){return new o(h(t))}static async fromBlob(t){return new o(await I(t))}}class V{configInstance={}}class B extends V{setConfig(t){this.configInstance=t}getBankTransferList(t){const{newBankStatementTransactions:n}=R(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${T(n)}}`)?.BANKMSGSRSV1?.STMTTRNRS?.STMTRS?.BANKTRANLIST?.STRTTRN:[]}getCreditCardTransferList(t){const{newCreditCardStatementTransactions:n}=C(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${T(n)}}`)?.CREDITCARDMSGSRSV1?.CCSTMTTRNRS?.CCSTMTRS?.BANKTRANLIST?.STRTTRN:[]}getTransactionsSummary(t){const n=this.getContent(t),{DTEND:r,DTSTART:s,STRTTRN:a}=n.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=X(a);return{dateStart:s,dateEnd:r,...i}}getContent(t){const n=this.configInstance.getPartialJsonData(t),{newBankStatementTransactions:r,oldBankStatementTransactions:s}=R(n),{newCreditCardStatementTransactions:a,oldCreditCardStatementTransactions:i}=C(n);let c=n;return r&&(c=c.replace(s,r)),a&&(c=c.replace(i,a)),JSON.parse(`{${T(c)}}`)}}class W{customExtractor;customExtractorInstance;dataReaderInstance=new o("");constructor(t){this.customExtractor=t,this.customExtractorInstance=t||new B,this.config({})}data(t){return this.dataReaderInstance=t,this}config(t){return this.customExtractorInstance.setConfig(new z(t)),this}getHeaders(){const[t]=this.dataReaderInstance.getData().split("<OFX>");return $(t.split(`
`).filter(n=>!!n.trim().length),!!this.customExtractorInstance.configInstance.getConfig().nativeTypes)}getBankTransferList(){return this.customExtractorInstance.getBankTransferList(this.dataReaderInstance.getData())}getCreditCardTransferList(){return this.customExtractorInstance.getCreditCardTransferList(this.dataReaderInstance.getData())}getTransactionsSummary(){return this.customExtractorInstance.getTransactionsSummary(this.dataReaderInstance.getData())}getContent(){return this.customExtractorInstance.getContent(this.dataReaderInstance.getData())}toJson(){const t=this.getHeaders(),n=this.customExtractorInstance.getContent(this.dataReaderInstance.getData());return{...t,...n}}}class m{extractor;constructor(t,n){this.extractor=new W(new B),this.extractor.data(new o(t)),this.extractor.config(n||{})}static fromBuffer(t){return new m(o.fromBuffer(t).getData())}static async fromBlob(t){const n=await o.fromBlob(t);return new m(n.getData())}config(t){return this.extractor.config(t),this}getHeaders(){return this.extractor.getHeaders()}getBankTransferList(){return this.extractor.getBankTransferList()}getCreditCardTransferList(){return this.extractor.getCreditCardTransferList()}getTransactionsSummary(){return this.extractor.getTransactionsSummary()}getContent(){return this.extractor.getContent()}toJson(){return this.extractor.toJson()}}export{W as Extractor,m as Ofx,B as OfxExtractor,o as Reader,I as blobToString,h as bufferToString,T as fixJsonProblems,L as formatDate};
}`).replace(/(,",)/,",").replace(M,'\\"').slice(0,-1)}const k=e=>JSON.stringify({date:e.slice(0,12),transactionCode:e.slice(12,19),protocol:e.slice(19)}),G=e=>e.startsWith("DT"),p=e=>e.trim();function w(e,t=!1){return y.includes(e)&&!t?e:e.replace(/[<]/g,`
"`).replace(/[>]/g,'":{')}function D(e,t=!1){return L.includes(e)&&!t?`
${e}`:"},"}function F({fitId:e,fitValue:t}){return e==="separated"?k(t):`"${t}",`}function J(e){return e.search(",")>e.search(".")?e.replace(/[.]/g,"").replace(/[,]/g,"."):e.replace(/[,]/g,"")}function P({dateString:e,formatDate:t="y-M-d"}){return _(e,t)}function K(e){let t=e.value.replace(/[{]/g,"").replace(/(},)/g,"").replace(/["]/g,N);const n=e.field.replace(/['"]/g,"");return n.endsWith("AMT")&&(t=J(t)),G(n)&&(t=P({dateString:t,formatDate:e.formatDate})),n==="FITID"?F({fitId:e.fitId,fitValue:t}):e.nativeTypes&&A(n,t)?`${Number(t)},`:`"${t}",`}function X(e,t){let n=e;return e.match(/{(\w|\W)+/)&&(n=n.replace(/({(\w|\W)+)$/,r=>K({field:n.slice(0,n.indexOf(":")),value:r,...t}))),n}function A(e,t){return e.endsWith("ID")||e.endsWith("NUM")?!1:!isNaN(Number(t))}function O(e){const t=e.indexOf(S),n=e.lastIndexOf(T)+T.length,r=e.substring(t,n),s=new RegExp(S,"g"),a=new RegExp(T,"g"),i=`"STRTTRN":[${r.replace(s,"{").replace(a,"},")}]`;return{oldListText:e,newListText:e.replace(r,i)}}function m(e){if(!(e.indexOf(l)>0))return{newBankStatementTransactions:null,oldBankStatementTransactions:null};const n=O(e.substring(e.indexOf(l),e.indexOf(f)+f.length));return{newBankStatementTransactions:n.newListText,oldBankStatementTransactions:n.oldListText}}function C(e){if(!(e.indexOf(d)>0))return{newCreditCardStatementTransactions:null,oldCreditCardStatementTransactions:null};const n=e.substring(e.indexOf(d),e.indexOf(g)+g.length),r=O(n);return{newCreditCardStatementTransactions:r.newListText,oldCreditCardStatementTransactions:r.oldListText}}function $(e){const t=[];for(const n of e)t.push(...n.replace("<?xml"," ").replace("<?OFX"," ").replace("?>"," ").split(" ").filter(Boolean).map(p).map(r=>r.replace("=",":").replace(/["]/g,"")));return t}function V(e,t){const n={};e.join("").search("<?")>-1&&(e=$(e));for(const r of e){const[s,a]=r.split(":"),i=s.replace(`
`,"").toUpperCase();n[i]=t&&A(s,a)?Number(a):a}return n}function z(e){return e.reduce((t,n)=>{const r=Math.abs(+n.TRNAMT);return n.TRNTYPE.toLocaleLowerCase().startsWith("deb")?(t.amountOfDebits++,t.debit+=r,t):(t.amountOfCredits++,t.credit+=r,t)},{credit:0,debit:0,amountOfCredits:0,amountOfDebits:0})}class W{config;internConfig={};constructor(t){this.config=t,this.internConfig=t}getConfig(){return this.internConfig}sanitizeRow(t){return X(t,this.internConfig)}getPartialJsonData(t){const[n,r]=t.split("<OFX>"),s="<OFX>"+r,{sanitizeRow:a}=this;return s.replace(E,i=>D(i)).replace(x,i=>w(i)).split(`
`).map(p).filter(Boolean).map(a,this).join("")}}function h(e){return e.toString()}async function I(e){return await new Promise((n,r)=>{if(typeof window<"u"&&window.FileReader){const s=new window.FileReader;s.onload=a=>n(a.target.result),s.onerror=a=>r(a.target.error),s.readAsText(e)}else r(new Error("FileReader is not available in this environment."))})}class o{data;dataRead="";constructor(t){this.data=t,t&&(this.dataRead=t)}getData(){return this.dataRead}fromString(t){return new o(t)}fromBuffer(t){return new o(h(t))}async fromBlob(t){return new o(await I(t))}static fromString(t){return new o(t)}static fromBuffer(t){return new o(h(t))}static async fromBlob(t){return new o(await I(t))}}class j{configInstance={}}class B extends j{setConfig(t){this.configInstance=t}getBankTransferList(t){const{newBankStatementTransactions:n}=m(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${u(n)}}`)?.BANKMSGSRSV1?.STMTTRNRS?.STMTRS?.BANKTRANLIST?.STRTTRN:[]}getCreditCardTransferList(t){const{newCreditCardStatementTransactions:n}=C(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${u(n)}}`)?.CREDITCARDMSGSRSV1?.CCSTMTTRNRS?.CCSTMTRS?.BANKTRANLIST?.STRTTRN:[]}getTransactionsSummary(t){const n=this.getContent(t),{DTEND:r,DTSTART:s,STRTTRN:a}=n.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=z(a);return{dateStart:s,dateEnd:r,...i}}getContent(t){const n=this.configInstance.getPartialJsonData(t),{newBankStatementTransactions:r,oldBankStatementTransactions:s}=m(n),{newCreditCardStatementTransactions:a,oldCreditCardStatementTransactions:i}=C(n);let c=n;return r&&(c=c.replace(s,r)),a&&(c=c.replace(i,a)),JSON.parse(`{${u(c)}}`)}}class H{customExtractor;customExtractorInstance;dataReaderInstance=new o("");constructor(t){this.customExtractor=t,this.customExtractorInstance=t||new B,this.config({})}data(t){return this.dataReaderInstance=t,this}config(t){return this.customExtractorInstance.setConfig(new W(t)),this}getHeaders(){const[t]=this.dataReaderInstance.getData().split("<OFX>");return V(t.split(`
`).filter(n=>!!n.trim().length),!!this.customExtractorInstance.configInstance.getConfig().nativeTypes)}getBankTransferList(){return this.customExtractorInstance.getBankTransferList(this.dataReaderInstance.getData())}getCreditCardTransferList(){return this.customExtractorInstance.getCreditCardTransferList(this.dataReaderInstance.getData())}getTransactionsSummary(){return this.customExtractorInstance.getTransactionsSummary(this.dataReaderInstance.getData())}getContent(){return this.customExtractorInstance.getContent(this.dataReaderInstance.getData())}toJson(){const t=this.getHeaders(),n=this.customExtractorInstance.getContent(this.dataReaderInstance.getData());return{...t,...n}}}class R{extractor;constructor(t,n){this.extractor=new H(new B),this.extractor.data(new o(t)),this.extractor.config(n||{})}static fromBuffer(t){return new R(o.fromBuffer(t).getData())}static async fromBlob(t){const n=await o.fromBlob(t);return new R(n.getData())}config(t){return this.extractor.config(t),this}getHeaders(){return this.extractor.getHeaders()}getBankTransferList(){return this.extractor.getBankTransferList()}getCreditCardTransferList(){return this.extractor.getCreditCardTransferList()}getTransactionsSummary(){return this.extractor.getTransactionsSummary()}getContent(){return this.extractor.getContent()}toJson(){return this.extractor.toJson()}}export{H as Extractor,R as Ofx,B as OfxExtractor,o as Reader,I as blobToString,h as bufferToString,u as fixJsonProblems,_ as formatDate};

@@ -1,11 +0,11 @@

// Ofx-data-extractor v1.4.0 Copyright (c) 2024 Fábio Pereira França
(function(o,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(o=typeof globalThis<"u"?globalThis:o||self,f(o.ofx={}))})(this,function(o){"use strict";const f=/<\/\w+>/g,x=/<\w+>/g,g="<BANKMSGSRSV1>",S="</BANKMSGSRSV1>",m="<CREDITCARDMSGSRSV1>",R="</CREDITCARDMSGSRSV1>",C="<STMTTRN>",T="</STMTTRN>",M=[g,C,m],L=[S,R,T];function k(e){const t=e.slice(0,4),n=e.slice(4,6),r=e.slice(6,8),s=e.slice(8,10),a=e.slice(10,12),i=e.slice(12,14);return{yyyy:t,yy:t.slice(2),y:t,MM:n,M:n,dd:r,d:r,hh:s,h:s,mm:a,m:a,ss:i,s:i}}function E(e,t){const n=k(e);let r=t;for(const[s,a]of Object.entries(n))r=r.replace(s,a);return r}function l(e){return e.replace(/(\\)/g,"\\\\").replace(f,t=>w(t,!0)).replace(x,t=>D(t,!0)).replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/({")/g,`{
// Ofx-data-extractor v1.4.1 Copyright (c) 2024 Fábio Pereira França
(function(o,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(o=typeof globalThis<"u"?globalThis:o||self,f(o.ofx={}))})(this,function(o){"use strict";const f=/<\/\w+>/g,x=/<\w+>/g,g="<BANKMSGSRSV1>",S="</BANKMSGSRSV1>",m="<CREDITCARDMSGSRSV1>",R="</CREDITCARDMSGSRSV1>",C="<STMTTRN>",T="</STMTTRN>",N="_#_",L=new RegExp(N,"g"),_=[g,C,m],k=[S,R,T];function G(e){const t=e.slice(0,4),n=e.slice(4,6),r=e.slice(6,8),s=e.slice(8,10),a=e.slice(10,12),i=e.slice(12,14);return{yyyy:t,yy:t.slice(2),y:t,MM:n,M:n,dd:r,d:r,hh:s,h:s,mm:a,m:a,ss:i,s:i}}function p(e,t){const n=G(e);let r=t;for(const[s,a]of Object.entries(n))r=r.replace(s,a);return r}function l(e){return e.replace(/(\\)/g,"\\\\").replace(f,t=>O(t,!0)).replace(x,t=>D(t,!0)).replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(]")/g,'],"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/({")/g,`{
"`).replace(/(})/g,`
}`).replace(/(",")/g,`",
"`).replace(/,\s*}/g,`
}`).replace(/(,",)/,",").slice(0,-1)}const _=e=>JSON.stringify({date:e.slice(0,12),transactionCode:e.slice(12,19),protocol:e.slice(19)}),G=e=>e.startsWith("DT"),p=e=>e.trim();function D(e,t=!1){return M.includes(e)&&!t?e:e.replace(/[<]/g,`
"`).replace(/[>]/g,'":{')}function w(e,t=!1){return L.includes(e)&&!t?`
${e}`:"},"}function F({fitId:e,fitValue:t}){return e==="separated"?_(t):`"${t}",`}function J(e){return e.search(",")>e.search(".")?e.replace(/[.]/g,"").replace(/[,]/g,"."):e.replace(/[,]/g,"")}function P({dateString:e,formatDate:t="y-M-d"}){return E(e,t)}function K(e){let t=e.value.replace(/[{]/g,"").replace(/(},)/g,"");const n=e.field.replace(/['"]/g,"");return n.endsWith("AMT")&&(t=J(t)),G(n)&&(t=P({dateString:t,formatDate:e.formatDate})),n==="FITID"?F({fitId:e.fitId,fitValue:t}):e.nativeTypes&&A(n,t)?`${Number(t)},`:`"${t}",`}function $(e,t){let n=e;return e.match(/{(\w|\W)+/)&&(n=n.replace(/({(\w|\W)+)$/,r=>K({field:n.slice(0,n.indexOf(":")),value:r,...t}))),n}function A(e,t){return e.endsWith("ID")||e.endsWith("NUM")?!1:!isNaN(Number(t))}function O(e){const t=e.indexOf(C),n=e.lastIndexOf(T)+T.length,r=e.substring(t,n),s=new RegExp(C,"g"),a=new RegExp(T,"g"),i=`"STRTTRN":[${r.replace(s,"{").replace(a,"},")}]`;return{oldListText:e,newListText:e.replace(r,i)}}function B(e){if(!(e.indexOf(g)>0))return{newBankStatementTransactions:null,oldBankStatementTransactions:null};const n=O(e.substring(e.indexOf(g),e.indexOf(S)+S.length));return{newBankStatementTransactions:n.newListText,oldBankStatementTransactions:n.oldListText}}function b(e){if(!(e.indexOf(m)>0))return{newCreditCardStatementTransactions:null,oldCreditCardStatementTransactions:null};const n=e.substring(e.indexOf(m),e.indexOf(R)+R.length),r=O(n);return{newCreditCardStatementTransactions:r.newListText,oldCreditCardStatementTransactions:r.oldListText}}function X(e){const t=[];for(const n of e)t.push(...n.replace("<?xml"," ").replace("<?OFX"," ").replace("?>"," ").split(" ").filter(Boolean).map(p).map(r=>r.replace("=",":").replace(/["]/g,"")));return t}function j(e,t){const n={};e.join("").search("<?")>-1&&(e=X(e));for(const r of e){const[s,a]=r.split(":"),i=s.replace(`
`,"").toUpperCase();n[i]=t&&A(s,a)?Number(a):a}return n}function z(e){return e.reduce((t,n)=>n.TRNTYPE.toLocaleLowerCase().startsWith("deb")?(t.amountOfDebits++,t.debit+=Number(n.TRNAMT.replace("-","")),t):(t.amountOfCredits++,t.credit+=Number(n.TRNAMT),t),{credit:0,debit:0,amountOfCredits:0,amountOfDebits:0})}class V{config;internConfig={};constructor(t){this.config=t,this.internConfig=t}getConfig(){return this.internConfig}sanitizeRow(t){return $(t,this.internConfig)}getPartialJsonData(t){const[n,r]=t.split("<OFX>"),s="<OFX>"+r,{sanitizeRow:a}=this;return s.replace(f,i=>w(i)).replace(x,i=>D(i)).split(`
`).map(p).filter(Boolean).map(a,this).join("")}}function h(e){return e.toString()}async function I(e){return await new Promise((n,r)=>{if(typeof window<"u"&&window.FileReader){const s=new window.FileReader;s.onload=a=>n(a.target.result),s.onerror=a=>r(a.target.error),s.readAsText(e)}else r(new Error("FileReader is not available in this environment."))})}class c{data;dataRead="";constructor(t){this.data=t,t&&(this.dataRead=t)}getData(){return this.dataRead}fromString(t){return new c(t)}fromBuffer(t){return new c(h(t))}async fromBlob(t){return new c(await I(t))}static fromString(t){return new c(t)}static fromBuffer(t){return new c(h(t))}static async fromBlob(t){return new c(await I(t))}}class W{configInstance={}}class N extends W{setConfig(t){this.configInstance=t}getBankTransferList(t){const{newBankStatementTransactions:n}=B(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${l(n)}}`)?.BANKMSGSRSV1?.STMTTRNRS?.STMTRS?.BANKTRANLIST?.STRTTRN:[]}getCreditCardTransferList(t){const{newCreditCardStatementTransactions:n}=b(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${l(n)}}`)?.CREDITCARDMSGSRSV1?.CCSTMTTRNRS?.CCSTMTRS?.BANKTRANLIST?.STRTTRN:[]}getTransactionsSummary(t){const n=this.getContent(t),{DTEND:r,DTSTART:s,STRTTRN:a}=n.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=z(a);return{dateStart:s,dateEnd:r,...i}}getContent(t){const n=this.configInstance.getPartialJsonData(t),{newBankStatementTransactions:r,oldBankStatementTransactions:s}=B(n),{newCreditCardStatementTransactions:a,oldCreditCardStatementTransactions:i}=b(n);let u=n;return r&&(u=u.replace(s,r)),a&&(u=u.replace(i,a)),JSON.parse(`{${l(u)}}`)}}class y{customExtractor;customExtractorInstance;dataReaderInstance=new c("");constructor(t){this.customExtractor=t,this.customExtractorInstance=t||new N,this.config({})}data(t){return this.dataReaderInstance=t,this}config(t){return this.customExtractorInstance.setConfig(new V(t)),this}getHeaders(){const[t]=this.dataReaderInstance.getData().split("<OFX>");return j(t.split(`
`).filter(n=>!!n.trim().length),!!this.customExtractorInstance.configInstance.getConfig().nativeTypes)}getBankTransferList(){return this.customExtractorInstance.getBankTransferList(this.dataReaderInstance.getData())}getCreditCardTransferList(){return this.customExtractorInstance.getCreditCardTransferList(this.dataReaderInstance.getData())}getTransactionsSummary(){return this.customExtractorInstance.getTransactionsSummary(this.dataReaderInstance.getData())}getContent(){return this.customExtractorInstance.getContent(this.dataReaderInstance.getData())}toJson(){const t=this.getHeaders(),n=this.customExtractorInstance.getContent(this.dataReaderInstance.getData());return{...t,...n}}}class d{extractor;constructor(t,n){this.extractor=new y(new N),this.extractor.data(new c(t)),this.extractor.config(n||{})}static fromBuffer(t){return new d(c.fromBuffer(t).getData())}static async fromBlob(t){const n=await c.fromBlob(t);return new d(n.getData())}config(t){return this.extractor.config(t),this}getHeaders(){return this.extractor.getHeaders()}getBankTransferList(){return this.extractor.getBankTransferList()}getCreditCardTransferList(){return this.extractor.getCreditCardTransferList()}getTransactionsSummary(){return this.extractor.getTransactionsSummary()}getContent(){return this.extractor.getContent()}toJson(){return this.extractor.toJson()}}o.Extractor=y,o.Ofx=d,o.OfxExtractor=N,o.Reader=c,o.blobToString=I,o.bufferToString=h,o.fixJsonProblems=l,o.formatDate=E});
}`).replace(/(,",)/,",").replace(L,'\\"').slice(0,-1)}const F=e=>JSON.stringify({date:e.slice(0,12),transactionCode:e.slice(12,19),protocol:e.slice(19)}),J=e=>e.startsWith("DT"),w=e=>e.trim();function D(e,t=!1){return _.includes(e)&&!t?e:e.replace(/[<]/g,`
"`).replace(/[>]/g,'":{')}function O(e,t=!1){return k.includes(e)&&!t?`
${e}`:"},"}function P({fitId:e,fitValue:t}){return e==="separated"?F(t):`"${t}",`}function K(e){return e.search(",")>e.search(".")?e.replace(/[.]/g,"").replace(/[,]/g,"."):e.replace(/[,]/g,"")}function X({dateString:e,formatDate:t="y-M-d"}){return p(e,t)}function $(e){let t=e.value.replace(/[{]/g,"").replace(/(},)/g,"").replace(/["]/g,N);const n=e.field.replace(/['"]/g,"");return n.endsWith("AMT")&&(t=K(t)),J(n)&&(t=X({dateString:t,formatDate:e.formatDate})),n==="FITID"?P({fitId:e.fitId,fitValue:t}):e.nativeTypes&&A(n,t)?`${Number(t)},`:`"${t}",`}function V(e,t){let n=e;return e.match(/{(\w|\W)+/)&&(n=n.replace(/({(\w|\W)+)$/,r=>$({field:n.slice(0,n.indexOf(":")),value:r,...t}))),n}function A(e,t){return e.endsWith("ID")||e.endsWith("NUM")?!1:!isNaN(Number(t))}function B(e){const t=e.indexOf(C),n=e.lastIndexOf(T)+T.length,r=e.substring(t,n),s=new RegExp(C,"g"),a=new RegExp(T,"g"),i=`"STRTTRN":[${r.replace(s,"{").replace(a,"},")}]`;return{oldListText:e,newListText:e.replace(r,i)}}function b(e){if(!(e.indexOf(g)>0))return{newBankStatementTransactions:null,oldBankStatementTransactions:null};const n=B(e.substring(e.indexOf(g),e.indexOf(S)+S.length));return{newBankStatementTransactions:n.newListText,oldBankStatementTransactions:n.oldListText}}function y(e){if(!(e.indexOf(m)>0))return{newCreditCardStatementTransactions:null,oldCreditCardStatementTransactions:null};const n=e.substring(e.indexOf(m),e.indexOf(R)+R.length),r=B(n);return{newCreditCardStatementTransactions:r.newListText,oldCreditCardStatementTransactions:r.oldListText}}function j(e){const t=[];for(const n of e)t.push(...n.replace("<?xml"," ").replace("<?OFX"," ").replace("?>"," ").split(" ").filter(Boolean).map(w).map(r=>r.replace("=",":").replace(/["]/g,"")));return t}function z(e,t){const n={};e.join("").search("<?")>-1&&(e=j(e));for(const r of e){const[s,a]=r.split(":"),i=s.replace(`
`,"").toUpperCase();n[i]=t&&A(s,a)?Number(a):a}return n}function W(e){return e.reduce((t,n)=>{const r=Math.abs(+n.TRNAMT);return n.TRNTYPE.toLocaleLowerCase().startsWith("deb")?(t.amountOfDebits++,t.debit+=r,t):(t.amountOfCredits++,t.credit+=r,t)},{credit:0,debit:0,amountOfCredits:0,amountOfDebits:0})}class H{config;internConfig={};constructor(t){this.config=t,this.internConfig=t}getConfig(){return this.internConfig}sanitizeRow(t){return V(t,this.internConfig)}getPartialJsonData(t){const[n,r]=t.split("<OFX>"),s="<OFX>"+r,{sanitizeRow:a}=this;return s.replace(f,i=>O(i)).replace(x,i=>D(i)).split(`
`).map(w).filter(Boolean).map(a,this).join("")}}function h(e){return e.toString()}async function E(e){return await new Promise((n,r)=>{if(typeof window<"u"&&window.FileReader){const s=new window.FileReader;s.onload=a=>n(a.target.result),s.onerror=a=>r(a.target.error),s.readAsText(e)}else r(new Error("FileReader is not available in this environment."))})}class c{data;dataRead="";constructor(t){this.data=t,t&&(this.dataRead=t)}getData(){return this.dataRead}fromString(t){return new c(t)}fromBuffer(t){return new c(h(t))}async fromBlob(t){return new c(await E(t))}static fromString(t){return new c(t)}static fromBuffer(t){return new c(h(t))}static async fromBlob(t){return new c(await E(t))}}class U{configInstance={}}class I extends U{setConfig(t){this.configInstance=t}getBankTransferList(t){const{newBankStatementTransactions:n}=b(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${l(n)}}`)?.BANKMSGSRSV1?.STMTTRNRS?.STMTRS?.BANKTRANLIST?.STRTTRN:[]}getCreditCardTransferList(t){const{newCreditCardStatementTransactions:n}=y(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${l(n)}}`)?.CREDITCARDMSGSRSV1?.CCSTMTTRNRS?.CCSTMTRS?.BANKTRANLIST?.STRTTRN:[]}getTransactionsSummary(t){const n=this.getContent(t),{DTEND:r,DTSTART:s,STRTTRN:a}=n.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=W(a);return{dateStart:s,dateEnd:r,...i}}getContent(t){const n=this.configInstance.getPartialJsonData(t),{newBankStatementTransactions:r,oldBankStatementTransactions:s}=b(n),{newCreditCardStatementTransactions:a,oldCreditCardStatementTransactions:i}=y(n);let u=n;return r&&(u=u.replace(s,r)),a&&(u=u.replace(i,a)),JSON.parse(`{${l(u)}}`)}}class M{customExtractor;customExtractorInstance;dataReaderInstance=new c("");constructor(t){this.customExtractor=t,this.customExtractorInstance=t||new I,this.config({})}data(t){return this.dataReaderInstance=t,this}config(t){return this.customExtractorInstance.setConfig(new H(t)),this}getHeaders(){const[t]=this.dataReaderInstance.getData().split("<OFX>");return z(t.split(`
`).filter(n=>!!n.trim().length),!!this.customExtractorInstance.configInstance.getConfig().nativeTypes)}getBankTransferList(){return this.customExtractorInstance.getBankTransferList(this.dataReaderInstance.getData())}getCreditCardTransferList(){return this.customExtractorInstance.getCreditCardTransferList(this.dataReaderInstance.getData())}getTransactionsSummary(){return this.customExtractorInstance.getTransactionsSummary(this.dataReaderInstance.getData())}getContent(){return this.customExtractorInstance.getContent(this.dataReaderInstance.getData())}toJson(){const t=this.getHeaders(),n=this.customExtractorInstance.getContent(this.dataReaderInstance.getData());return{...t,...n}}}class d{extractor;constructor(t,n){this.extractor=new M(new I),this.extractor.data(new c(t)),this.extractor.config(n||{})}static fromBuffer(t){return new d(c.fromBuffer(t).getData())}static async fromBlob(t){const n=await c.fromBlob(t);return new d(n.getData())}config(t){return this.extractor.config(t),this}getHeaders(){return this.extractor.getHeaders()}getBankTransferList(){return this.extractor.getBankTransferList()}getCreditCardTransferList(){return this.extractor.getCreditCardTransferList()}getTransactionsSummary(){return this.extractor.getTransactionsSummary()}getContent(){return this.extractor.getContent()}toJson(){return this.extractor.toJson()}}o.Extractor=M,o.Ofx=d,o.OfxExtractor=I,o.Reader=c,o.blobToString=E,o.bufferToString=h,o.fixJsonProblems=l,o.formatDate=p});
{
"name": "ofx-data-extractor",
"version": "1.4.0",
"version": "1.4.1",
"keywords": [

@@ -5,0 +5,0 @@ "ofx",

@@ -5,2 +5,3 @@ # [ofx-data-extractor](https://www.npmjs.com/package/ofx-data-extractor)

[![codecov](https://codecov.io/gh/Fabiopf02/ofx-data-extractor/branch/main/graph/badge.svg?token=L4A7E4H8IN)](https://codecov.io/gh/Fabiopf02/ofx-data-extractor)
[![Release Package](https://github.com/Fabiopf02/ofx-data-extractor/actions/workflows/release.yml/badge.svg)](https://github.com/Fabiopf02/ofx-data-extractor/actions/workflows/release.yml)

@@ -7,0 +8,0 @@ ## Ofx Data Extractor and Formatter

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc