-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
read-trips: use for-await, minor changes
- Loading branch information
Showing
5 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
const readCsv = require('../read-csv') | ||
const readTrips = require('../read-trips') | ||
|
||
const readFile = (file) => { | ||
return readCsv(require.resolve('sample-gtfs-feed/gtfs/' + file + '.txt')) | ||
} | ||
|
||
;(async () => { | ||
const trips = await readTrips(readFile) | ||
for await (const trip of trips.values()) { | ||
console.log(trip) | ||
} | ||
})() | ||
.catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const expectSorting = (filename, compareFn) => { | ||
let prevRow = null | ||
let rowNr = 0 | ||
|
||
const checkRow = (row) => { | ||
rowNr++ | ||
|
||
if (prevRow !== null && compareFn(prevRow, row) > 0) { | ||
const err = new Error(filename + ' is not sorted as needed') | ||
err.previousRow = prevRow | ||
err.row = row | ||
err.rowNr = rowNr | ||
throw err | ||
} | ||
prevRow = row | ||
} | ||
return checkRow | ||
} | ||
|
||
module.exports = expectSorting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters