UNPKG

@briancullen/aws-textract-parser

Version:

Library for converting AWS Textract responses into a more usable structure.

29 lines (28 loc) 1.48 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var PageBlockNode_1 = __importDefault(require("../model/PageBlockNode")); var PageParser = /** @class */ (function () { function PageParser(lineParser, geometryParser, blockIdParser, blockMap) { this.lineParser = lineParser; this.geometryParser = geometryParser; this.blockIdParser = blockIdParser; this.blockMap = blockMap; } PageParser.prototype.process = function (page) { var _this = this; var _a, _b, _c; var children = (_c = (_b = (_a = page.Relationships) === null || _a === void 0 ? void 0 : _a.find(function (relationship) { return relationship.Type === 'CHILD'; })) === null || _b === void 0 ? void 0 : _b.Ids, (_c !== null && _c !== void 0 ? _c : [])); var lines = children.map(function (id) { return _this.blockMap.get(id); }) .filter(function (block) { return block !== undefined; }) .filter(function (block) { return block.BlockType === 'LINE'; }) .map(function (block) { return _this.lineParser.process(block); }); var id = this.blockIdParser(page); var geometry = this.geometryParser(page); return new PageBlockNode_1.default(id, geometry, lines); }; return PageParser; }()); exports.default = PageParser;