UNPKG

@makakwastaken/ts-edifact

Version:
126 lines 4.54 kB
"use strict"; /** * @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. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); // Run this sample with: npx ts-node examples/definitions.ts const fs = __importStar(require("node:fs")); const path = __importStar(require("node:path")); const reader_1 = require("../src/reader"); const tracker_1 = require("../src/tracker"); let document = ''; document += "UNB+UNOA:1+005435656:1+006415160:1+060515:1434+00000000000778'"; document += "UNH+00000000000117+INVOIC:D:01B:UN'"; document += "BGM+380+342459+9'"; document += "DTM+3:20060515:102'"; document += "RFF+ON:521052'"; document += "NAD+BY+792820524::16++CUMMINS MID-RANGE ENGINE PLANT'"; document += "NAD+SE+005435656::16++GENERAL WIDGET COMPANY'"; document += "CUX+1:USD'"; document += "LIN+1++157870:IN'"; document += "IMD+F++:::WIDGET'"; document += "QTY+47:1020:EA'"; document += "ALI+US'"; document += "MOA+203:1202.58'"; document += "PRI+INV:1.179'"; document += "LIN+2++157871:IN'"; document += "IMD+F++:::DIFFERENT WIDGET'"; document += "QTY+47:20:EA'"; document += "ALI+JP'"; document += "MOA+203:410'"; document += "PRI+INV:20.5'"; document += "UNS+S'"; document += "MOA+39:2137.58'"; document += "ALC+C+ABG'"; document += "MOA+8:525'"; document += "UNT+23+00000000000117'"; document += "UNZ+1+00000000000778'"; function _validateDocument(doc, callback) { const reader = new reader_1.Reader(); const result = reader.parse(doc); let checked = 0; const data = fs.readFileSync(path.resolve('./src/messageSpec/INVOIC.struct.json'), { encoding: 'utf-8' }); const msgStruct = JSON.parse(data); const tracker = new tracker_1.Tracker(msgStruct); for (const obj of result) { if (obj.name !== 'UNA' && obj.name !== 'UNB' && obj.name !== 'UNZ') { tracker.accept(obj.name); checked++; } } if (callback) { callback(checked); } else { return checked; } } function validateDocumentSync(doc) { _validateDocument(doc, (_checked) => { }); } validateDocumentSync(document); async function validateDocumentAsync(doc) { const promise = new Promise((resolve) => { _validateDocument(doc, resolve); }); const result = await promise; return result; } void validateDocumentAsync(document); function validateDocumentAsync2(doc) { const result = _validateDocument(doc); return result; } validateDocumentAsync2(document); function sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); } void sleep(500); //# sourceMappingURL=definitions.js.map