npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

edifact-serializer

v0.0.1

Published

Create EDIFACT segment definitions, validate data based on the segment and render the data in the EDI format

Downloads

3

Readme

edifact-serializer

TypeScript version Node.js version APLv2

Template: node-typescript-boilerplate

👩🏻💻 Developer Ready: A comprehensive template. Works out of the box for most Node.js projects.

Getting Started

This project is intended to be used with the latest Active LTS release of Node.js.

Clone repository

To clone the repository, use the following commands:

git clone https://github.com/bloodred17/edifact-serializer.git
cd edifact-serializer
npm install

Usage

The following example demonstrates the creation of a Segment definition:

export const interchangeTrailerSegment = new EdifactSegment({
  name: 'interchange_trailer',
  tag: 'UNZ',
  elements: [
    // Elements and Compund Element definition
  ],
});
  • name : Identifier
  • tag : Valid Segment tag
  • elements : List of Element and Composite Element definitions

The following example demonstrates the creation of a single EDIFACT message Element:

const interchangeControlCount = new EdifactElement({
  name: 'interchange_control_count',
  tag: '0036',
  status: UseStatus.M,
  _format: 'n..6'
})
  • name : Identifier
  • tag : String
  • status : Enum that specifies if the value Mandatory or Conditional
  • _format : Edifact specified format for values

The following example demonstrates the creation of a EDIFACT Composite message element:

const documentMesageIdentification = new EdifactCompositeElement({
  name: 'document_message_identification',
  tag: 'C106',
  status: UseStatus.C,
  elements: [
    // Single message elements
  ]
})
  • name : Identifier
  • tag : String
  • status : Enum that specifies if the value Mandatory or Conditional
  • elements: List of Element definitions

The following example demonstrates a CUSDEC BGM segment definition:

import { EdifactCompositeElement, EdifactElement, EdifactSegment, UseStatus } from 'edifact-serializer';

export const beginningOfMessageSegment = new EdifactSegment({
  name: 'beginning_of_message',
  tag: 'BGM',
  counter: '0020',
  number: 3,
  level: 0,
  elements: [
    new EdifactCompositeElement({
      name: 'document_message_name',
      tag: 'C002',
      status: UseStatus.C,
      elements: [
        new EdifactElement({
          name: 'document_message_name_coded',
          tag: '1001',
          status: UseStatus.C,
          _format: 'an..3'
        }),
        new EdifactElement({
          name: 'code_list_qualifier',
          tag: '1131',
          status: UseStatus.C,
          _format: 'an..3'
        }),
        new EdifactElement({
          name: 'code_list_responsible_agency',
          tag: '3055',
          status: UseStatus.C,
          _format: 'an..3'
        }),
        new EdifactElement({
          name: 'document_message_name',
          tag: '1000',
          status: UseStatus.C,
          _format: 'an..3'
        }),
      ],
    }),
    new EdifactCompositeElement({
      name: 'document_message_identification',
      tag: 'C106',
      status: UseStatus.C,
      elements: [
        new EdifactElement({
          name: 'document_message_number',
          tag: '1004',
          status: UseStatus.C,
          _format: 'an..35'
        }),
        new EdifactElement({
          name: 'version',
          tag: '1056',
          status: UseStatus.C,
          _format: 'an..9'
        }),
        new EdifactElement({
          name: 'revision_number',
          tag: '1060',
          status: UseStatus.C,
          _format: 'an..6',
        }),
      ]
    }),
    new EdifactElement({
      name: 'message_function_coded',
      tag: '1225',
      status: UseStatus.C,
      _format: 'an..3'
    }),
  ],
});

Using the serializer:

const interchangeHeaderData = {
  syntax_identifier: 'UNOB',
  syntax_version_number: '4',
  interchange_sender_identification: '12345678ABC',
  interchange_code_qualifier: '',
  interchange_sender_internal_identification: 'ABCDEFGHIJKLMNOP',
  interchange_sender_internal_sub_identification: 'SPCAS2',
  interchange_recipient_identification: 'SARSDEC',
  date_of_preparation: '20190501',
  time_of_preparation: '1327',
  interchange_control_reference: '1234567890',
  recipient_reference_password: '',
  application_reference: 'CUSDEC',
  processing_priority_code: '',
  acknowledgement_request: '1',
  interchange_agreement_identifier: '',
  test_indicator: '1'
};

const messageHeaderData = {
  message_reference_number: '00000000155033',
  message_type_identifier: 'CUSDEC',
  message_type_version_number: 'D',
  message_type_release_number: '96B',
  controlling_agency: 'UN',
  association_assigned_code: 'ZZZ01',
};

const beginningOfMessageData = {
  document_message_name_coded: '929',
  code_list_qualifier: '',
  code_list_responsible_agency: '',
  document_message_name: 'RCD',
  document_message_number: '12345678ABC20190228654321',
  version: '012345',
  revision_number: '00001',
  message_function_coded: '9'
};

const interchangeMessage = await renderInterchangeMessage([
  { segment: unbSegment, data: interchangeHeaderData },
  { segment: unhSegment, data: messageHeaderData },
  { segment: beginningOfMessageSegment, data: beginningOfMessageData },
  //...other segments following...
]);

renderInterchangeMessageRenders EDIFACT message for a segment() function accepts array of type Message and outputs serialized data.

Message is an interface of segment {EdifactSegment} and data {any}

data is a map of edifact element identifier (name) and value. Refer to the example of 'beginningOfMessageData' and 'beginningOfMessageSegment' above.

Additional functions

renderSegment Renders EDIFACT message for a input segment and data.

validateValue Validates the value based on the EdifactElement definition.

getElementFormat Parses the EDIFACT data format string to useful values that can be used to validate the value

These functions are subject to change. Refer to the internal JSDoc definition for usage.

Features

The definitions are validated using the class-validator package and the data is validated on the basis of the specified format (specified using the _format property).

Bugs and Issue reporting

Add new issues here.

License

Licensed under the APLv2. See the LICENSE file for details.