@makakwastaken/ts-edifact
Version:
Edifact parser library
69 lines • 2.3 kB
TypeScript
/**
* @author Roman Vottner
* @copyright 2020 Roman Vottner
* @license Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { Separators } from './edi/separators';
import { Dictionary, type ElementEntry, type SegmentEntry } from './validator';
export type ResultType = {
name: string;
elements: ElementEntry[];
};
export type Result = {
name: string;
elements: ResultElement[];
};
export type ResultElement = {
name: string;
components: ResultComponents;
};
export type ResultComponents = {
[key: string]: string | undefined;
};
export interface ReaderConfig {
throwOnMissingSegments?: boolean;
throwOnInvalidComponentValue?: boolean;
}
/**
* The `Reader` class is included for backwards compatibility. It translates an
* UN/EDIFACT document to an array of segments. Each segment has a `name` and
* `elements` property where `elements` is an array consisting of component
* arrays. The class exposes a `parse()` method which accepts the document as a
* string.
*/
export declare class Reader {
private result;
private elements;
private element;
private validator;
private parser;
private defined;
private validationTables;
private componentValues;
private definitionCache;
private unbCharsetDefined;
separators: Separators;
constructor(messageSpecDir?: string, config?: ReaderConfig);
/**
* Provide the underlying `Validator` with segment or element definitions.
*
* @summary Define segment and element structures.
* @param definitions An object containing the definitions.
*/
define(definitions: Dictionary<SegmentEntry>): void;
private initializeIfNeeded;
parse(document: string): ResultType[];
}
//# sourceMappingURL=reader.d.ts.map