UNPKG

@briancullen/aws-textract-parser

Version:

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

26 lines (25 loc) 1.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var DocumentNode_1 = __importDefault(require("../model/DocumentNode")); var DocumentParser = /** @class */ (function () { function DocumentParser(pageParserFactory) { this.pageParserFactory = pageParserFactory; } DocumentParser.prototype.process = function (input) { var _a, _b; if (((_a = input.DocumentMetadata) === null || _a === void 0 ? void 0 : _a.Pages) === undefined) { return new DocumentNode_1.default([]); } var blocks = (_b = input.Blocks, (_b !== null && _b !== void 0 ? _b : [])); var blocksById = blocks.reduce(function (map, block) { return map.set(block.Id, block); }, new Map()); var parser = this.pageParserFactory(blocksById); var pages = blocks.filter(function (block) { return block.BlockType === 'PAGE'; }) .map(function (block) { return parser.process(block); }); return new DocumentNode_1.default(pages); }; return DocumentParser; }()); exports.DocumentParser = DocumentParser;