-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove hardcoded transporttype and add pikaratikka color to numbers
Also refactor some duplicated functions under the same module
- Loading branch information
Showing
5 changed files
with
47 additions
and
61 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
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
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,28 @@ | ||
// Util functions to handle line data. | ||
|
||
const parseLineNumber = (lineId) => | ||
// Remove 1st number, which represents the city | ||
// Remove all zeros from the beginning | ||
lineId.substring(1).replace(/^0+/, ""); | ||
|
||
const parseTransportType = (line) => { | ||
if (line.routes.nodes.length > 0) { | ||
return line.routes.nodes[0].mode; | ||
} | ||
// Backup if mode not found from routes. The old hardcoded way. | ||
if (line.lineId.substring(0, 4) >= 1001 && line.lineId.substring(0, 4) <= 1010) { | ||
return "TRAM"; | ||
} | ||
return "BUS"; | ||
}; | ||
|
||
const compareLineNameOrder = (a, b) => { | ||
if (a.lineId.substring(1, 4) !== b.lineId.substring(1, 4)) { | ||
return a.lineId.substring(1, 4) > b.lineId.substring(1, 4) ? 1 : -1; | ||
} else if (a.lineId.substring(0, 1) !== b.lineId.substring(0, 1)) { | ||
return a.lineId.substring(0, 1) > b.lineId.substring(0, 1) ? 1 : -1; | ||
} | ||
return a.lineId.substring(4, 6) > b.lineId.substring(4, 6) ? 1 : -1; | ||
}; | ||
|
||
export { parseLineNumber, parseTransportType, compareLineNameOrder }; |