Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #29 and allows optional fields to be omitted during object creation #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/batch/control.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const utils = require('../utils')

module.exports = {
recordTypeCode: {
name: 'Record Type Code',
Expand Down Expand Up @@ -70,7 +72,7 @@ module.exports = {
required: false,
type: 'alphanumeric',
blank: true,
value: ''
value: utils.SPACE.repeat(19)
},

reserved: {
Expand All @@ -80,7 +82,7 @@ module.exports = {
required: false,
type: 'alphanumeric',
blank: true,
value: ''
value: utils.SPACE.repeat(6)
},

originatingDFI: {
Expand Down
8 changes: 5 additions & 3 deletions lib/batch/header.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const utils = require('../utils')

module.exports = {
recordTypeCode: {
name: 'Record Type Code',
Expand Down Expand Up @@ -33,7 +35,7 @@ module.exports = {
required: false,
type: 'alphanumeric',
blank: true,
value: ''
value: utils.SPACE.repeat(20)
},

companyIdentification: {
Expand Down Expand Up @@ -69,7 +71,7 @@ module.exports = {
position: 8,
required: false,
type: 'alphanumeric',
value: ''
value: utils.SPACE.repeat(6)
},

effectiveEntryDate: {
Expand All @@ -88,7 +90,7 @@ module.exports = {
required: false,
type: 'numeric',
blank: true,
value: ''
value: utils.SPACE.repeat(3)
},

originatorStatusCode: {
Expand Down
6 changes: 4 additions & 2 deletions lib/entry-addenda/fields.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const utils = require('../utils');

module.exports = {
recordTypeCode: {
name: 'Record Type Code',
Expand All @@ -14,7 +16,7 @@ module.exports = {
position: 2,
required: true,
type: 'numeric',
value: '05'
value: '05'
},

paymentRelatedInformation: {
Expand All @@ -23,7 +25,7 @@ module.exports = {
position: 3,
required: false,
type: 'alphanumeric',
value: ''
value: utils.SPACE.repeat(80)
},

addendaSequenceNumber: {
Expand Down
6 changes: 4 additions & 2 deletions lib/entry/fields.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const utils = require('../utils');

module.exports = {
recordTypeCode: {
name: 'Record Type Code',
Expand Down Expand Up @@ -59,7 +61,7 @@ module.exports = {
position: 7,
required: false,
type: 'alphanumeric',
value: ''
value: utils.SPACE.repeat(15)
},

individualName: {
Expand All @@ -77,7 +79,7 @@ module.exports = {
position: 9,
required: false,
type: 'alphanumeric',
value: '',
value: utils.SPACE.repeat(2)
},

addendaId: {
Expand Down
219 changes: 108 additions & 111 deletions lib/file/header.js
Original file line number Diff line number Diff line change
@@ -1,125 +1,122 @@
var utils = require('../utils');

// The date/time defaults are dynamic, so always create a new object
module.exports = function () {
return {
recordTypeCode: {
name: 'Record Type Code',
width: 1,
position: 1,
required: true,
type: 'numeric',
value: '1'
},
module.exports = {
recordTypeCode: {
name: 'Record Type Code',
width: 1,
position: 1,
required: true,
type: 'numeric',
value: '1'
},

priorityCode: {
name: 'Priority Code',
width: 2,
position: 2,
required: true,
type: 'numeric',
value: '01'
},
priorityCode: {
name: 'Priority Code',
width: 2,
position: 2,
required: true,
type: 'numeric',
value: '01'
},

immediateDestination: {
name: 'Immediate Destination',
width: 10,
position: 3,
required: true,
type: 'ABA',
paddingChar: ' ',
value: ''
},
immediateDestination: {
name: 'Immediate Destination',
width: 10,
position: 3,
required: true,
type: 'ABA',
paddingChar: ' ',
value: ''
},

immediateOrigin: {
name: 'Immediate Origin',
width: 10,
position: 4,
required: true,
type: 'numeric',
paddingChar: ' ',
value: ''
},
immediateOrigin: {
name: 'Immediate Origin',
width: 10,
position: 4,
required: true,
type: 'numeric',
paddingChar: ' ',
value: ''
},

fileCreationDate: {
name: 'File Creation Date',
width: 6,
position: 5,
required: true,
type: 'numeric',
value: utils.formatDate(new Date())
},
fileCreationDate: {
name: 'File Creation Date',
width: 6,
position: 5,
required: true,
type: 'numeric',
value: utils.formatDate(new Date())
},

fileCreationTime: {
name: 'File Creation Time',
width: 4,
position: 6,
required: true,
type: 'numeric',
value: utils.formatTime(new Date())
},
fileCreationTime: {
name: 'File Creation Time',
width: 4,
position: 6,
required: true,
type: 'numeric',
value: utils.formatTime(new Date())
},

fileIdModifier: {
name: 'File Modifier',
width: 1,
position: 7,
required: true,
type: 'alphanumeric',
value: 'A'
},
fileIdModifier: {
name: 'File Modifier',
width: 1,
position: 7,
required: true,
type: 'alphanumeric',
value: 'A'
},

recordSize: {
name: 'Record Size',
width: 3,
position: 8,
type: 'numeric',
required: true,
value: '094'
},
recordSize: {
name: 'Record Size',
width: 3,
position: 8,
type: 'numeric',
required: true,
value: '094'
},

blockingFactor: {
name: 'Blocking Factor',
width: 2,
position: 9,
type: 'numeric',
required: true,
value: '10'
},
blockingFactor: {
name: 'Blocking Factor',
width: 2,
position: 9,
type: 'numeric',
required: true,
value: '10'
},

formatCode: {
name: 'Format Code',
width: 1,
position: 10,
required: true,
type: 'numeric',
value: '1'
},
formatCode: {
name: 'Format Code',
width: 1,
position: 10,
required: true,
type: 'numeric',
value: '1'
},

immediateDestinationName: {
name: 'Immediate Destination Name',
width: 23,
position: 11,
required: true,
type: 'alphanumeric',
value: ''
},
immediateDestinationName: {
name: 'Immediate Destination Name',
width: 23,
position: 11,
required: true,
type: 'alphanumeric',
value: ''
},

immediateOriginName: {
name: 'Immediate Origin Name',
width: 23,
position: 12,
required: true,
type: 'alphanumeric',
value: ''
},
immediateOriginName: {
name: 'Immediate Origin Name',
width: 23,
position: 12,
required: true,
type: 'alphanumeric',
value: ''
},

referenceCode: {
name: 'Reference Code',
width: 8,
position: 13,
required: true,
type: 'alphanumeric',
value: ''
}
};
};
referenceCode: {
name: 'Reference Code',
width: 8,
position: 13,
required: false,
type: 'alphanumeric',
value: utils.SPACE.repeat(8)
}
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose removing the newline at the end of the file was not intentional. Could you put it back in?

4 changes: 3 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var _ = require('lodash');
var moment = require('moment');
var nACHError = require('./error');
var counter = 0;
const SPACE = " ";

// Pad a given string to a fixed width using any character or number (defaults to one blank space)
// Both a string and width are required params for this function, but it also takes two optional
Expand Down Expand Up @@ -157,4 +158,5 @@ module.exports.getNextMultiple = getNextMultiple;
module.exports.overrideLowLevel = overrideLowLevel;
module.exports.computeCheckDigit = computeCheckDigit;
module.exports.computeBusinessDay = computeBusinessDay;
module.exports.getNextMultipleDiff = getNextMultipleDiff;
module.exports.getNextMultipleDiff = getNextMultipleDiff;
module.exports.SPACE = SPACE;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're at it, it would be nice to add the file-ending newline here too.