bus-mj 2.2.5 → 2.2.7

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/index.d.ts CHANGED
@@ -39,4 +39,5 @@ export function findBusDetailByOperator(operatorName: string): Bus[];
39
39
  export function findOpenHoursAll(): string[];
40
40
  export function findStopByRef(ref: number): Stop;
41
41
  export function findBusByStopLabel(label: string): Bus[];
42
- export function findBusByTwoStopLabel(begin: string, end: string): Bus[];
42
+ export function findBusByTwoStopLabel(begin: string, end: string): Bus[];
43
+ export function findBusOperator(operator: string): Bus[];
package/index.js CHANGED
@@ -10,7 +10,8 @@ import {
10
10
  findOpenHoursAll,
11
11
  findStopByRef,
12
12
  findBusByStopLabel,
13
- findBusByTwoStopLabel
13
+ findBusByTwoStopLabel,
14
+ findBusOperator
14
15
  } from "./src/getBus.js";
15
16
 
16
17
  export {
@@ -25,5 +26,6 @@ export {
25
26
  findOpenHoursAll,
26
27
  findStopByRef,
27
28
  findBusByStopLabel,
28
- findBusByTwoStopLabel
29
+ findBusByTwoStopLabel,
30
+ findBusOperator
29
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bus-mj",
3
- "version": "2.2.5",
3
+ "version": "2.2.7",
4
4
  "description": "package for BUS station in Mahajanga",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/getBus.js CHANGED
@@ -66,7 +66,10 @@ export function findBusByOneStop(stop_id) {
66
66
  */
67
67
  export function findBusByStopLabel(stop_label) {
68
68
  return relations.filter((relation) => {
69
- return relation.members.some((member) => member.label && member.label.toUpperCase() == stop_label.toUpperCase());
69
+ return relation.members.some(
70
+ (member) =>
71
+ member.label && member.label.toUpperCase() == stop_label.toUpperCase()
72
+ );
70
73
  });
71
74
  }
72
75
 
@@ -76,10 +79,30 @@ export function findBusByStopLabel(stop_label) {
76
79
  * @param {Bus[]} __relation list of bus to filter
77
80
  * @returns { Bus[] }
78
81
  */
79
- export function __findBusByStopLabel(stop_label, __relation) {
80
- return __relation.filter((rel) => {
81
- return rel.members.some((member) => member.label && member.label.toUpperCase() == stop_label.toUpperCase());
82
- });
82
+ export function __findBusByStopLabel(stop_label, relations, beginLabel) {
83
+ return relations
84
+ .map((rel) => {
85
+ const beginIndex = rel.members.findIndex(
86
+ (m) => m.label?.toUpperCase() === beginLabel.toUpperCase()
87
+ );
88
+
89
+ const endIndex = rel.members.findIndex(
90
+ (m) => m.label?.toUpperCase() === stop_label.toUpperCase()
91
+ );
92
+
93
+ if (beginIndex === -1 || endIndex === -1) {
94
+ return null;
95
+ }
96
+
97
+ const start = Math.min(beginIndex, endIndex);
98
+ const end = Math.max(beginIndex, endIndex);
99
+
100
+ return {
101
+ ...rel,
102
+ members: rel.members.slice(start, end + 1),
103
+ };
104
+ })
105
+ .filter(Boolean);
83
106
  }
84
107
 
85
108
  /**
@@ -103,7 +126,7 @@ export function findBusByTwoStop(begin, end) {
103
126
  */
104
127
  export function findBusByTwoStopLabel(begin, end) {
105
128
  let firstRelationsFound = findBusByStopLabel(begin);
106
- return __findBusByStopLabel(end, firstRelationsFound);
129
+ return __findBusByStopLabel(end, firstRelationsFound, begin);
107
130
  }
108
131
 
109
132
  /**
@@ -127,6 +150,14 @@ export function findBusAll() {
127
150
  return relations;
128
151
  }
129
152
 
153
+ /**
154
+ * fetch bus by operator
155
+ * @returns { Bus[] }
156
+ */
157
+ export function findBusOperator(operator) {
158
+ return relations.filter((e) => e.tags.operator == operator);
159
+ }
160
+
130
161
  /**
131
162
  * fetch all operator
132
163
  * @returns { string[] }
@@ -159,4 +190,4 @@ export function findZoneAll() {
159
190
  (value, index, self) =>
160
191
  self.indexOf(value) === index && value != undefined
161
192
  );
162
- }
193
+ }