-
Notifications
You must be signed in to change notification settings - Fork 0
/
completeOrphanRow.ts
35 lines (32 loc) · 1.33 KB
/
completeOrphanRow.ts
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
/**
* completeOrphanRow
* Created by dcorns on 1/26/21
* Copyright © 2021 Dale Corns
*/
import {ProviderConfig} from './app-types';
const completeOrphanRow = (orphanRow: any, providerConfig: ProviderConfig, propertyNames: Array<string>, remainingRow: any) => {
const orphanRowCopy = {...orphanRow};
const orphanPropertyCount = Object.keys(orphanRowCopy).length;
const remainingPropNames = propertyNames.length - orphanPropertyCount;
let rowIndexDif = providerConfig.totalColumns - remainingRow.length + 1;
const propNameIndexDif = propertyNames.length - remainingPropNames;
const lastOrphanProperty = propertyNames[orphanPropertyCount - 1];
if (lastOrphanProperty) {
orphanRowCopy[lastOrphanProperty] = orphanRow[lastOrphanProperty] + remainingRow.shift();
}
else{
rowIndexDif--;
}
for (let i = 0; i < remainingPropNames; i++) {
if (propertyNames[i + propNameIndexDif]) {
if (remainingRow[providerConfig.validColumns[i + propNameIndexDif] - rowIndexDif]) {
orphanRowCopy[propertyNames[i + propNameIndexDif]] = remainingRow[providerConfig.validColumns[i + propNameIndexDif] - rowIndexDif];
}
} else {
//end of valid properties
break;
}
}
return orphanRowCopy;
}
export default completeOrphanRow