@transportme/vline-nsp-reader 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,13 +28,15 @@ export default class PassPDFReader {
28
28
  const body = this.getBody(table)
29
29
 
30
30
  for (let columnIndex = 0; columnIndex < body[0].length; columnIndex++) {
31
+ let operationDay = body[0][columnIndex]
31
32
  let currentRun = {
32
33
  type: '',
33
- stops: []
34
+ stops: [],
35
+ operationDay
34
36
  }
35
37
 
36
38
  let lastStation
37
- for (let stationIndex = 0; stationIndex < stations.length; stationIndex++) {
39
+ for (let stationIndex = 1; stationIndex < stations.length; stationIndex++) {
38
40
  const stationName = stations[stationIndex]
39
41
  const stopData = (body[stationIndex][columnIndex] || '').replace('.', ':')
40
42
  if (stationName === 'Service') {
@@ -50,7 +52,8 @@ export default class PassPDFReader {
50
52
  lastStation = null
51
53
  currentRun = {
52
54
  type: stopData[0] + stopData.slice(1).toLowerCase(),
53
- stops: []
55
+ stops: [],
56
+ operationDay
54
57
  }
55
58
 
56
59
  continue
@@ -56,12 +56,12 @@ export default class PassTableReader {
56
56
  const tableData = []
57
57
 
58
58
  page.Texts.forEach(text => {
59
- if (text.y < tableStart - commonHeight || text.y > tableEnd + commonHeight * 1.5) return
59
+ if (text.y < tableStart - commonHeight * 2 || text.y > tableEnd + commonHeight * 1.5) return
60
60
 
61
61
  let textContent = decodeURIComponent(text.R[0].T)
62
62
 
63
- let currentRow = rowStarts.findIndex(r => r > text.y + 0.3) - 1
64
- if (currentRow < 0) currentRow = rowStarts.length - 1
63
+ let currentRow = text.y < tableStart - commonHeight ? 0 : rowStarts.findIndex(r => r > text.y + 0.3)
64
+ if (currentRow < 0) currentRow = rowStarts.length
65
65
 
66
66
  let currentCol = colStarts.findLastIndex(c => c < text.x + 0.4)
67
67
 
@@ -78,29 +78,22 @@ export default class PassTableReader {
78
78
  }
79
79
  }
80
80
 
81
- return tableData
82
- })
83
-
84
- console.log(tables)
85
-
86
- console.log(heightFrequency)
87
- console.log(VLines)
88
- console.log(rowStarts)
81
+ const colCount = tableData[1].length
82
+ for (let x = colCount - 1; x > 0; x--) {
83
+ let text = tableData[0][x] || ''
84
+ if (text.startsWith(' ') || text.startsWith('to')) {
85
+ tableData[0][x - 1] = (tableData[0][x - 1] + ' ' + text.trim()).replace('continued', '').trim()
86
+ tableData[0][x] = ''
87
+ }
88
+ }
89
89
 
90
- let pageData = []
91
- let smallTable = rowStarts.length === 2
90
+ for (let x = 1; x < colCount; x++) {
91
+ if (!tableData[0][x]) tableData[0][x] = tableData[0][x - 1]
92
+ }
92
93
 
93
- return pageData
94
+ return tableData
95
+ })
94
96
  })
95
-
96
- return pages[0]
97
-
98
- // return pages.map(page => {
99
- // let maxSize = Math.max(...page.map(row => row.length))
100
- // let blankCells = Array(maxSize).fill('')
101
-
102
- // return page.map(row => row.map(g => g.replace(/ +/g, ' ').trim()).concat(blankCells).slice(0, maxSize))
103
- // })
104
97
  }
105
98
 
106
99
  read() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transportme/vline-nsp-reader",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "main": "lib.mjs",
5
5
  "scripts": {
6
6
  "test": "mocha './{,!(node_modules)/**}/*.test.mjs'"