UNPKG

@midlandsbank/node-nacha

Version:

NACHA ACH EFT File Parser/Formatter for CCD+ / PPD+ / CTX+

83 lines (66 loc) 2.08 kB
var lineParsers = require('./line-parsers'); function parseAch(achString) { var ach = {}; var lines = achString.split('\n'); for (var i = 0; i < lines.length; i++) { var line = lines[i]; if (line.length === 0 || (line[0] === '9' && line[1] === '9')) { continue; } var name = line[0]; if (lineParsers != null && typeof lineParsers[name] === "function") { lineParsers[name](line, ach); } if (line[0] === '9' && (ach != null)) { return ach; } } return ach; } module.exports = parseAch; /* // Generated by CoffeeScript 1.11.1 var AchParser, EachPart, insertTransform, lineParsers, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; EachPart = require('each-part').EachPart; lineParsers = require('./line-parsers'); insertTransform = function(source) { var eacher; if (source instanceof EachPart) { return; } source.unpipe(this); eacher = new EachPart({ delim: '\n' }); return source.pipe(eacher).pipe(this); }; module.exports = AchParser = (function(superClass) { extend(AchParser, superClass); function AchParser() { AchParser.__super__.constructor.call(this, { objectMode: true }); this.on('pipe', insertTransform.bind(this)); this.ach = {}; } AchParser.prototype._transform = function(data, encoding, done) { var line, name; line = data.string; if (line.length === 0 || (line[0] === '9' && line[1] === '9')) { return done(); } if (lineParsers != null) { if (typeof lineParsers[name = line[0]] === "function") { lineParsers[name](line, this.ach); } } if (line[0] === '9' && (this.ach != null)) { this.push(this.ach); this.ach = {}; } return done(); }; return AchParser; })(require('stream').Transform); */