An ASC X12 parser, generator, query engine, and mapper written for NodeJS. Parsing supports reading from streams to conserve resources in memory-intensive operations.
Install it from the npm repository:
npm install --save node-x12
Then require it in your project:
const X12Parser =
Then import it in your project:
Contributions by TrueCommerce up to April 2016:
- Near-complete class object model of ASC X12 parts
- Query Engine
Enhancements original to this fork:
- Simplified object notation class for EDI (allows for easy JSON support)
- Streaming Parser (allows for parsing of large EDI files with reduced memory overhead)
- Transaction set to object mapping
- Object to transaction set mapping, now with support for Liquid syntax
- Support for fat EDI documents
- Convenience methods for several generating/mapping scenarios
- Intellisense support in VSCode with packaged type declarations
See the API for more information.
Version 2.x series is being actively developed. Minor versions should not cause breaking changes, but major releases will break.
The next major version has lots of things planned in order to more completely describe ASC X12 and perform more of the heavy lifting in terms of parsing and handling X12 EDI documents. To view and track all issues in the 2.x series: milestone 'Version 2.0.0'
The query language makes it possible to directly select values from the class object model. See Query Language for more information.
Example 1: Select
Example 2: Select
REF02 Elements With a
PO Qualifier in
Example 3: Select Line-Level PO Numbers (850)
Example 4: Select ASN Line Quantities
Example 5: Select values from a loop series
Fat EDI Documents
Some vendors will concatenate multiple valid EDI documents into a single request or file. This DOES NOT CONFORM to the ASC X12 spec, but it does happen. Implementing support for this scenario was trivial. When parsing an EDI document, it will be handled one of two ways:
- When strict, the parser will return an
X12FatInterchangeobject with property
interchanges, an array of
- When not strict, the parser will merge valid EDI documents into a single interchange
In the latter of the two scenarios, the parser will set the header and trailer to the last available ISA and IEA segments. The element data of the discarded ISA and IEA segments will be lost if the original fat EDI document is not preserved. If all the header and trailer information is important to your organization, we recommend setting the parser to strict so that you get all the data into an object, or else go back to your implementer and request that they fix their EDI.
Implementers of ASC X12 are not guaranteed to conform completely to spec. There are scenarios that this library WILL NOT be able to handle and WILL NEVER be added. Despite the addition of functionality beyond the base parser from the original libray, the goal of this library is to remain a simple implementation of the spec. Some examples of scenarios this library won't handle:
- Control characters in the content of an element
- Mixed encrypted/non-encrypted documents
- Missing elements in XYZ tag
Such issues should be resolved between a user of this library and the implementer of ASC X12 documents they are working with.
Additional documentation can be found self-hosted within the repository.
Created originally for the TC Toolbox project by TrueCommerce; the public repository for TC Toolbox has been taken offline. The original, parser-only library may be found at TrueCommerce/node-x12, which is still public at this time but no longer maintained. Without the good work done by TrueCommerce up until 2016, this library would not exist.
Thanks to @DotJoshJohnson.