Skip to content

Commit

Permalink
Enhanced support for de/serializing ISA13 & IEA02
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Huggins committed Oct 16, 2019
1 parent 8598ecd commit 8955e72
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-x12",
"version": "1.3.2",
"version": "1.3.3",
"description": "ASC X12 parser, generator, query engine, and mapper; now with support for streams.",
"main": "index.js",
"keywords": [
Expand Down
9 changes: 9 additions & 0 deletions src/X12Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ export class X12Parser extends Transform {
} else if (edi[i] === segmentTerminator) {
currentElement.range.end = new Position(l, (c - 1))
currentSegment.elements.push(currentElement)

if (currentSegment.tag === 'IEA' && currentSegment.elements.length === 2) {
currentSegment.elements[1].value = `${parseInt(currentSegment.elements[1].value, 10)}`
}

currentSegment.range.end = new Position(l, c)

segments.push(currentSegment)
Expand All @@ -241,6 +246,10 @@ export class X12Parser extends Transform {
currentElement.range.end = new Position(l, (c - 1))
currentSegment.elements.push(currentElement)

if (currentSegment.tag === 'ISA' && currentSegment.elements.length === 13) {
currentSegment.elements[12].value = `${parseInt(currentSegment.elements[12].value, 10)}`
}

currentElement = new X12Element()
currentElement.range.start = new Position(l, c + 1)

Expand Down
6 changes: 5 additions & 1 deletion src/X12Segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ export class X12Segment {

for (let i = 0; i < this.elements.length; i++) {
edi += options.elementDelimiter
edi += this.elements[i].value
if ((this.tag === 'ISA' && i === 12) || (this.tag === 'IEA' && i === 1)) {
edi += String.prototype.padStart.call(this.elements[i].value, 9, '0')
} else {
edi += this.elements[i].value
}
}

edi += options.segmentTerminator
Expand Down

0 comments on commit 8955e72

Please sign in to comment.