{"id":13592234,"url":"https://github.com/aaronhuggins/node-x12","last_synced_at":"2025-07-03T12:03:09.156Z","repository":{"id":41865976,"uuid":"207387615","full_name":"aaronhuggins/node-x12","owner":"aaronhuggins","description":"ASC X12 parser, generator, query engine, and mapper; now with support for streams.","archived":false,"fork":false,"pushed_at":"2022-04-30T22:58:29.000Z","size":1266,"stargazers_count":54,"open_issues_count":6,"forks_count":13,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-06-26T07:43:36.664Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://aaronhuggins.github.io/node-x12/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aaronhuggins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-09T19:24:20.000Z","updated_at":"2025-05-30T17:00:19.000Z","dependencies_parsed_at":"2022-08-11T19:40:23.635Z","dependency_job_id":null,"html_url":"https://github.com/aaronhuggins/node-x12","commit_stats":{"total_commits":301,"total_committers":9,"mean_commits":33.44444444444444,"dds":"0.38870431893687707","last_synced_commit":"168ce75ed88ff3965338dad3ffb5130ab43bfb21"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/aaronhuggins/node-x12","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronhuggins%2Fnode-x12","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronhuggins%2Fnode-x12/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronhuggins%2Fnode-x12/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronhuggins%2Fnode-x12/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaronhuggins","download_url":"https://codeload.github.com/aaronhuggins/node-x12/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronhuggins%2Fnode-x12/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263322786,"owners_count":23448712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T16:01:07.194Z","updated_at":"2025-07-03T12:03:09.110Z","avatar_url":"https://github.com/aaronhuggins.png","language":"TypeScript","funding_links":[],"categories":["Libraries"],"sub_categories":["Javascript"],"readme":"# Node-X12\n\nAn ASC X12 parser, generator, query engine, and mapper written for NodeJS and\nDeno. Parsing supports reading from Node streams to conserve resources in\nmemory-intensive operations.\n\n[![Denoland/X Module](https://shield.deno.dev/x/x12)](https://deno.land/x/x12)\n[![npm version](https://badge.fury.io/js/node-x12.svg)](https://badge.fury.io/js/node-x12)\n[![GitHub last commit](https://img.shields.io/github/last-commit/aaronhuggins/node-x12)]()\n[![GitHub contributors](https://img.shields.io/github/contributors/aaronhuggins/node-x12)]()\u003cbr /\u003e\n[![npm collaborators](https://img.shields.io/npm/collaborators/node-x12)]()\n[![GitHub top language](https://img.shields.io/github/languages/top/aaronhuggins/node-x12)]()\n[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/aaronhuggins/node-x12)]()\n[![npm](https://img.shields.io/npm/dw/node-x12)]()\n[![NPM](https://img.shields.io/npm/l/node-x12)]()\u003cbr /\u003e\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=aaronhuggins_node-x12\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=aaronhuggins_node-x12)\n[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=aaronhuggins_node-x12\u0026metric=sqale_rating)](https://sonarcloud.io/dashboard?id=aaronhuggins_node-x12)\n[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=aaronhuggins_node-x12\u0026metric=security_rating)](https://sonarcloud.io/dashboard?id=aaronhuggins_node-x12)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=aaronhuggins_node-x12\u0026metric=coverage)](https://sonarcloud.io/summary/new_code?id=aaronhuggins_node-x12)\n\n## Installing\n\nSimply import into your runtime: [Deno](https://deno.land/x/x12), browser,\n[Node ESM, or Node CommonJS](https://www.npmjs.com/package/node-x12). Browser\nimports can be handled via your favorite bundler, or using Skypack CDN.\n\nFor NPM: `npm i node-x12`\n\n## Features\n\nContributions by TrueCommerce up to April 2016:\n\n- Near-complete class object model of ASC X12 parts\n- Parser\n- Query Engine\n\nEnhancements original to this fork:\n\n- Simplified object notation class for EDI (allows for easy JSON support)\n- Streaming Parser (allows for parsing of large EDI files with reduced memory\n  overhead)\n- Generator\n- Transaction set to object mapping\n- Object to transaction set mapping, now with support for\n  [Liquid syntax](/docs/TransactionMapping.md#liquid-macro-language)\n- Support for fat EDI documents\n- Convenience methods for several generating/mapping scenarios\n- Intellisense support in VSCode with packaged type declarations\n\nSee the [API](/docs/API.md) for more information.\n\n#### Future\n\nThis library is in\n[maintenance mode as of 2021](https://github.com/aaronhuggins/node-x12/issues/24).\nDevelopment of a next-generation ASC X12 parser is taking place in\n[js-edi](https://github.com/aaronhuggins/js-edi). This new library will support\nboth ASC X12 and EDIFACT, as well as a more fleshed-out query language, by\nleveraging Antler4 grammars which closely follow publicly-provided details of\ntheir specs.\n\n### Query Language\n\nThe query language makes it possible to directly select values from the class\nobject model. See [Query Language](/docs/QueryLanguage.md) for more information.\n\n**Example 1: Select `REF02` Elements**\u003cbr /\u003e `REF02`\n\n**Example 2: Select `REF02` Elements With a `PO` Qualifier in `REF01`**\u003cbr /\u003e\n`REF02:REF01[\"PO\"]`\n\n**Example 3: Select Line-Level PO Numbers (850)**\u003cbr /\u003e `PO1-REF02:REF01[\"PO\"]`\n\n**Example 4: Select ASN Line Quantities**\u003cbr /\u003e `HL+S+O+P+I-LIN-SN102`\n\n**Example 5: Select values from a loop series**\u003cbr /\u003e\n`FOREACH(LX)=\u003eMAN02:MAN01[\"CP\"]`\n\n### Fat EDI Documents\n\nSome vendors will concatenate multiple valid EDI documents into a single request\nor file. This **DOES NOT CONFORM** to the ASC X12 spec, but it does happen.\nImplementing support for this scenario was trivial. When parsing an EDI\ndocument, it will be handled one of two ways:\n\n1. When strict, the parser will return an `X12FatInterchange` object with\n   property `interchanges`, an array of `X12Interchange` objects\n2. When not strict, the parser will merge valid EDI documents into a single\n   interchange\n\nIn the latter of the two scenarios, the parser will set the header and trailer\nto the last available ISA and IEA segments. The element data of the discarded\nISA and IEA segments will be lost if the original fat EDI document is not\npreserved. If all the header and trailer information is important to your\norganization, we recommend setting the parser to strict so that you get all the\ndata into an object, or else go back to your implementer and request that they\nfix their EDI.\n\n### Gotchas\n\nImplementers of ASC X12 are not guaranteed to conform completely to spec. There\nare scenarios that this library WILL NOT be able to handle and WILL NEVER be\nadded. Despite the addition of functionality beyond the base parser from the\noriginal libray, the goal of this library is to remain a simple implementation\nof the spec. Some examples of scenarios this library won't handle:\n\n- Control characters in the content of an element\n- Mixed encrypted/non-encrypted documents\n- Missing elements in XYZ tag\n\nSuch issues should be resolved between a user of this library and the\nimplementer of ASC X12 documents they are working with.\n\n## Documentation\n\nAdditional documentation can be found [self-hosted](/docs/TOC.md) within the\nrepository.\n\n## Examples\n\n```js\nconst { X12Generator, X12Parser, X12TransactionMap } = require(\"node-x12\");\n\n// Parse valid ASC X12 EDI into an object.\nconst parser = new X12Parser(true);\nlet interchange = parser.parse(\"...raw X12 data...\");\n\n// Parse a stream of valid ASC X12 EDI\nconst ediStream = fs.createReadStream(\"someFile.edi\");\nconst segments = [];\n\nediStream\n  .pipe(parser)\n  .on(\"data\", (data) =\u003e {\n    segments.push(data);\n  })\n  .on(\"end\", () =\u003e {\n    interchange = parser.getInterchangeFromSegments(segments);\n  });\n\n// Generate valid ASC X12 EDI from an object.\nconst jsen = {\n  options: {\n    elementDelimiter: \"*\",\n    segmentTerminator: \"\\n\",\n  },\n  header: [\n    \"00\",\n    \"\",\n    \"00\",\n    \"\",\n    \"ZZ\",\n    \"10000000\",\n    \"01\",\n    \"100000000\",\n    \"100000\",\n    \"0425\",\n    \"|\",\n    \"00403\",\n    \"100748195\",\n    \"0\",\n    \"P\",\n    \"\u003e\",\n  ],\n  functionalGroups: [...etc],\n};\nconst generator = new X12Generator(jsen);\n\n// Query X12 like an object model\nconst engine = new X12QueryEngine();\nconst results = engine.query(interchange, 'REF02:REF01[\"IA\"]');\n\nresults.forEach((result) =\u003e {\n  // Do something with each result.\n  // result.interchange\n  // result.functionalGroup\n  // result.transaction\n  // result.segment\n  // result.element\n  // result.value OR result.values\n});\n\n// Map transaction sets to javascript objects\nconst map = {\n  status: \"W0601\",\n  poNumber: \"W0602\",\n  poDate: \"W0603\",\n  shipto_name: 'N102:N101[\"ST\"]',\n  shipto_address: 'N1-N301:N101[\"ST\"]',\n  shipto_city: 'N1-N401:N101[\"ST\"]',\n  shipto_state: 'N1-N402:N101[\"ST\"]',\n  shipto_zip: 'N1-N403:N101[\"ST\"]',\n};\n\ninterchange.functionalGroups.forEach((group) =\u003e {\n  group.transactions.forEach((transaction) =\u003e {\n    console.log(transaction.toObject(map));\n  });\n});\n```\n\n## Credit\n\nCreated originally for the\n[TC Toolbox](https://github.com/TrueCommerce/vscode-tctoolbox) project by\nTrueCommerce; the public repository for TC Toolbox has been taken offline. The\noriginal, parser-only library may be found at\n[TrueCommerce/node-x12](https://github.com/TrueCommerce/node-x12), which is\nstill public at this time but no longer maintained. Without the good work done\nby TrueCommerce up until 2016, this library would not exist.\n\nThanks to [@DotJoshJohnson](https://github.com/DotJoshJohnson).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronhuggins%2Fnode-x12","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronhuggins%2Fnode-x12","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronhuggins%2Fnode-x12/lists"}