forked from ArtemySinitsa/aws-textract-json-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilityFuncs.js
More file actions
39 lines (34 loc) · 889 Bytes
/
utilityFuncs.js
File metadata and controls
39 lines (34 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module.exports = data => {
return () => {
// GET ALL WORD BLOCKS
const getAllWords = data.Blocks.filter(word => word.BlockType === 'WORD');
// GET ALL SELECTS BLOCKS
const getAllSelects = data.Blocks.filter(
select => select.BlockType === 'SELECTION_ELEMENT'
);
const getWords = childIds => {
return childIds.Ids.map(id => {
return getAllWords.filter(word => {
return word.Id === id;
});
});
};
const getSelects = childIds => {
return childIds.Ids.map(id => {
return getAllSelects.filter(word => {
return word.Id === id;
});
});
};
const buildWords = words => {
return words.reduce((fullKey, [word]) => {
return `${fullKey} ${word.Text}`.trim();
}, '');
};
return {
buildWords,
getSelects,
getWords
};
};
};