transit-departures-widget 2.2.1 → 2.3.0

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.3.0] - 2024-04-22
9
+
10
+ ## Fixed
11
+
12
+ - Better removing of last stoptime of trip
13
+
8
14
  ## [2.2.1] - 2024-04-08
9
15
 
10
16
  ## Fixed
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "transit-departures-widget",
3
3
  "description": "Build a realtime transit departures tool from GTFS and GTFS-Realtime.",
4
- "version": "2.2.1",
4
+ "version": "2.3.0",
5
5
  "keywords": [
6
6
  "transit",
7
7
  "gtfs",
@@ -342,13 +342,30 @@ function setupTransitDeparturesWidget(routes, stops, config) {
342
342
  }
343
343
 
344
344
  function filterDepartures(departures, { selectedStops, direction, route }) {
345
- // Remove departure information for last stoptime by stop_sequence if it has any
345
+ // Remove departure and arrival information for last stoptime by stop_sequence if it has any
346
346
  const cleanedDepartures = departures.map((departure) => {
347
- const stopTimeUpdates = departure?.trip_update?.stop_time_update
348
-
349
- if (stopTimeUpdates && stopTimeUpdates.length >= 2) {
350
- delete stopTimeUpdates[0].arrival
351
- delete stopTimeUpdates[stopTimeUpdates.length - 1].departure
347
+ if (departure?.trip_update?.stop_time_update?.length > 0) {
348
+ // Find index of largest stop_sequence
349
+ let largestStopSequence = 0
350
+ let largestStopSequenceIndex = 0
351
+ for (
352
+ let index = 0;
353
+ index < departure.trip_update.stop_time_update.length;
354
+ index++
355
+ ) {
356
+ if (
357
+ departure.trip_update.stop_time_update[index].stop_sequence >
358
+ largestStopSequence
359
+ ) {
360
+ largestStopSequence =
361
+ departure.trip_update.stop_time_update[index].stop_sequence
362
+ largestStopSequenceIndex = index
363
+ }
364
+ }
365
+ departure.trip_update.stop_time_update.splice(
366
+ largestStopSequenceIndex,
367
+ 1,
368
+ )
352
369
  }
353
370
 
354
371
  return departure