@digitransit-search-util/digitransit-search-util-is-duplicate 0.0.8 → 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 +22 -14
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -22,6 +22,21 @@ import truEq from '@digitransit-search-util/digitransit-search-util-tru-eq';
22
22
  * digitransit-util.isDuplicate(param1, param2);
23
23
  * //=true
24
24
  */
25
+
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
+ }
39
+
25
40
  export default function isDuplicate(item1, item2) {
26
41
  const props1 = item1.properties;
27
42
  const props2 = item2.properties;
@@ -41,26 +56,19 @@ export default function isDuplicate(item1, item2) {
41
56
  return false;
42
57
  }
43
58
  if (
44
- ((props1.layer === 'bikeRentalStation' ||
45
- props1.layer === 'favouriteBikeRentalStation') &&
46
- (props2.layer === 'bikeRentalStation' ||
47
- props2.layer === 'favouriteBikeRentalStation')) ||
48
- (props1.layer === 'bikestation' && props2.layer === 'bikestation')
59
+ vehicleRentalLayers.includes(props1.layer) &&
60
+ vehicleRentalLayers.includes(props2.layer)
49
61
  ) {
50
- 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;
51
65
  }
52
66
  if (props1.gtfsId && props2.gtfsId) {
53
67
  return props1.gtfsId === props2.gtfsId;
54
68
  }
55
- if (props1.gtfsId && props2.gid && props2.gid.includes(props1.gtfsId)) {
56
- return true;
57
- }
58
- if (props2.gtfsId && props1.gid && props1.gid.includes(props2.gtfsId)) {
59
- return true;
60
- }
61
69
  if (
62
- (props1.layer === 'stop' || props1.layer === 'station') &&
63
- (props2.layer === 'stop' || props2.layer === 'station') &&
70
+ gtfsStopLayers.includes(props1.layer) &&
71
+ gtfsStopLayers.includes(props2.layer) &&
64
72
  props1.gid &&
65
73
  props2.gid
66
74
  ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitransit-search-util/digitransit-search-util-is-duplicate",
3
- "version": "0.0.8",
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": "7b26c6654a58951bd14f1794a632007817a6e48d"
26
+ "gitHead": "f904285c98141cf0a03ca9c1fab54674c5c47e3e"
27
27
  }