@digitransit-search-util/digitransit-search-util-is-duplicate 1.0.0 → 2.0.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.
Files changed (2) hide show
  1. package/index.js +17 -6
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -24,6 +24,18 @@ import truEq from '@digitransit-search-util/digitransit-search-util-tru-eq';
24
24
  */
25
25
 
26
26
  const gtfsStopLayers = ['stop', 'station', 'favouriteStop', 'favouriteStation'];
27
+ const vehicleRentalLayers = ['favouriteVehicleRentalStation', 'bikestation'];
28
+
29
+ function labelIdToGid(id) {
30
+ if (!id) {
31
+ return '';
32
+ }
33
+ const parts = id.split(':');
34
+ if (parts.length === 0) {
35
+ return '';
36
+ }
37
+ return `citybikes${parts[0]}:bikestation:${parts[1]}`;
38
+ }
27
39
 
28
40
  export default function isDuplicate(item1, item2) {
29
41
  const props1 = item1.properties;
@@ -44,13 +56,12 @@ export default function isDuplicate(item1, item2) {
44
56
  return false;
45
57
  }
46
58
  if (
47
- ((props1.layer === 'bikeRentalStation' ||
48
- props1.layer === 'favouriteBikeRentalStation') &&
49
- (props2.layer === 'bikeRentalStation' ||
50
- props2.layer === 'favouriteBikeRentalStation')) ||
51
- (props1.layer === 'bikestation' && props2.layer === 'bikestation')
59
+ vehicleRentalLayers.includes(props1.layer) &&
60
+ vehicleRentalLayers.includes(props2.layer)
52
61
  ) {
53
- return props1.labelId === props2.labelId;
62
+ const id1 = props1.gid || labelIdToGid(props1.labelId);
63
+ const id2 = props2.gid || labelIdToGid(props2.labelId);
64
+ return id1 === id2;
54
65
  }
55
66
  if (props1.gtfsId && props2.gtfsId) {
56
67
  return props1.gtfsId === props2.gtfsId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitransit-search-util/digitransit-search-util-is-duplicate",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "digitransit-search-util is-duplicate module",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -23,5 +23,5 @@
23
23
  "dependencies": {
24
24
  "@digitransit-search-util/digitransit-search-util-tru-eq": "0.0.2"
25
25
  },
26
- "gitHead": "5c78ef7df03c2e12cc7a4be8d3ea3f2d76261d0a"
26
+ "gitHead": "f904285c98141cf0a03ca9c1fab54674c5c47e3e"
27
27
  }