UNPKG

@midlandsbank/node-nacha

Version:

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

87 lines (82 loc) 2.13 kB
// Generated by CoffeeScript 1.11.1 var extractFields, formats, noop; formats = require('./formats'); extractFields = function(line, format, target) { var end, field, i, j, len, ref, results, value; i = 0; ref = format.fields; results = []; for (j = 0, len = ref.length; j < len; j++) { field = ref[j]; end = i + field.length; value = line.slice(i, end); if (field.trim !== false) { value = value.trim(); } i = end; if (field.numeric) { value = Number(value); } results.push(target[field.name] = value); } return results; }; noop = function() {}; module.exports = { 1: function(line, ach) { ach.file = {}; ach.batches = []; extractFields(line, formats.fileHeader, ach.file); }, 5: function(line, ach) { var batch; batch = { entries: [] }; if (ach.batches == null) { ach.batches = []; } ach.batches.push(batch); extractFields(line, formats.batchHeader, batch); }, 6: function(line, ach) { var batch, entry; batch = ach.batches[ach.batches.length - 1]; entry = {}; if (batch.entries == null) { batch.entries = []; } batch.entries.push(entry); extractFields(line, formats[batch.entryClassCode].entry, entry); }, 7: function(line, ach) { var addenda, batch, entry; batch = ach.batches[ach.batches.length - 1]; entry = batch.entries[batch.entries.length - 1]; addenda = {}; if (batch.entryClassCode === 'CTX') { if (entry.addendas == null) { entry.addendas = []; } entry.addendas.push(addenda); } else { entry.addenda = addenda; } extractFields(line, formats[batch.entryClassCode].addenda, addenda); }, 8: function(line, ach) { var batch; batch = ach.batches[ach.batches.length - 1]; batch.footer = {}; extractFields(line, formats.batchFooter, batch.footer); }, 9: function(line, ach) { if ((line != null ? line[1] : void 0) === '9') { return; } ach.file.footer = {}; extractFields(line, formats.fileFooter, ach.file.footer); }, ' ': noop, '\n': noop };