bus-mj 2.0.1 → 2.2.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/README.md +85 -5
- package/data/nodes.js +2 -2
- package/data/relations.js +1 -1
- package/data/result.json +22531 -0
- package/index.d.ts +10 -12
- package/index.js +4 -4
- package/package.json +34 -4
- package/src/getBus.js +48 -27
- package/tsconfig.json +0 -0
package/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ type Bus = {
|
|
|
3
3
|
id: number,
|
|
4
4
|
members: Stop[],
|
|
5
5
|
tags: {
|
|
6
|
-
|
|
6
|
+
color: string,
|
|
7
7
|
band: string[],
|
|
8
8
|
board: string |null,
|
|
9
9
|
fee: string,
|
|
@@ -28,14 +28,12 @@ type Stop = {
|
|
|
28
28
|
label: string | null,
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export function findOpenHoursAll(): string[];
|
|
41
|
-
}
|
|
31
|
+
export function findStopAll(): Stop[];
|
|
32
|
+
export function findBusByOneStop(stopId: number): Bus[];
|
|
33
|
+
export function findBusByTwoStop(startStopId: number, endStopId: number): Bus[];
|
|
34
|
+
export function findBusDetailById(busId: number): Bus;
|
|
35
|
+
export function findBusAll(): Bus[];
|
|
36
|
+
export function findOperatorAll(): string[];
|
|
37
|
+
export function findZoneAll(): string[];
|
|
38
|
+
export function findBusDetailByOperator(operatorName: string): Bus[];
|
|
39
|
+
export function findOpenHoursAll(): string[];
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
2
|
findStopAll,
|
|
3
3
|
findBusByOneStop,
|
|
4
4
|
findBusByTwoStop,
|
|
@@ -8,9 +8,9 @@ const {
|
|
|
8
8
|
findZoneAll,
|
|
9
9
|
findBusDetailByOperator,
|
|
10
10
|
findOpenHoursAll
|
|
11
|
-
}
|
|
11
|
+
} from "./src/getBus.js";
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
export {
|
|
14
14
|
findStopAll,
|
|
15
15
|
findBusByOneStop,
|
|
16
16
|
findBusByTwoStop,
|
|
@@ -20,4 +20,4 @@ exports = {
|
|
|
20
20
|
findZoneAll,
|
|
21
21
|
findBusDetailByOperator,
|
|
22
22
|
findOpenHoursAll
|
|
23
|
-
};
|
|
23
|
+
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bus-mj",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "package for BUS station in Mahajanga",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
|
-
"
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"import": "./index.js",
|
|
12
|
+
"default": "./index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
8
15
|
"scripts": {
|
|
9
|
-
"test": "
|
|
16
|
+
"test": "node -e \"const {findBusAll, findStopAll} = require('./index.js'); console.log('✓ Module loaded successfully'); console.log('✓ Buses found:', findBusAll().length); console.log('✓ Stops found:', findStopAll().length);\""
|
|
10
17
|
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js",
|
|
20
|
+
"index.d.ts",
|
|
21
|
+
"src/",
|
|
22
|
+
"data/"
|
|
23
|
+
],
|
|
11
24
|
"repository": {
|
|
12
25
|
"type": "git",
|
|
13
26
|
"url": "git+https://github.com/selestinohajaniaina/bus-mahajanga-api.git"
|
|
14
27
|
},
|
|
15
28
|
"keywords": [
|
|
16
29
|
"api",
|
|
17
|
-
"bus-mahajanga"
|
|
30
|
+
"bus-mahajanga",
|
|
31
|
+
"bus mahajanga",
|
|
32
|
+
"bus-mahajanga-api",
|
|
33
|
+
"bus mahajanga api",
|
|
34
|
+
"api bus mahajanga",
|
|
35
|
+
"api-bus-mahajanga",
|
|
36
|
+
"mahajanga",
|
|
37
|
+
"bus",
|
|
38
|
+
"mahajanga bus",
|
|
39
|
+
"mahajanga-bus",
|
|
40
|
+
"transport",
|
|
41
|
+
"public-transport",
|
|
42
|
+
"public transport",
|
|
43
|
+
"madagascar",
|
|
44
|
+
"bus-api",
|
|
45
|
+
"bus api",
|
|
46
|
+
"bus-api-mahajanga",
|
|
47
|
+
"bus api mahajanga"
|
|
18
48
|
],
|
|
19
49
|
"author": "selestino",
|
|
20
50
|
"license": "ISC",
|
package/src/getBus.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/getBus.js
|
|
2
|
+
import relationsData from "../data/relations.js";
|
|
3
|
+
import nodesData from "../data/nodes.js";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
const nodes = nodesData;
|
|
6
|
+
|
|
7
|
+
let relations = relationsData.map((relation) => {
|
|
5
8
|
relation.members = relation.members.map((member) =>
|
|
6
9
|
findStopByRef(member.ref)
|
|
7
10
|
);
|
|
@@ -13,7 +16,7 @@ relations = relations.map((relation) => {
|
|
|
13
16
|
* @param {number} ref id of node
|
|
14
17
|
* @returns { Stop } detail of bus'stop
|
|
15
18
|
*/
|
|
16
|
-
function findStopByRef(ref) {
|
|
19
|
+
export function findStopByRef(ref) {
|
|
17
20
|
return nodes.find((e) => e.id === ref);
|
|
18
21
|
}
|
|
19
22
|
|
|
@@ -21,7 +24,7 @@ function findStopByRef(ref) {
|
|
|
21
24
|
* list all STOPS in data
|
|
22
25
|
* @returns { Stop[] }
|
|
23
26
|
*/
|
|
24
|
-
function findStopAll() {
|
|
27
|
+
export function findStopAll() {
|
|
25
28
|
return nodes.filter((node) => node.label != undefined);
|
|
26
29
|
}
|
|
27
30
|
|
|
@@ -30,7 +33,7 @@ function findStopAll() {
|
|
|
30
33
|
* @param {number} bus_id id of bus ...
|
|
31
34
|
* @returns { Bus }
|
|
32
35
|
*/
|
|
33
|
-
function findBusDetailById(bus_id) {
|
|
36
|
+
export function findBusDetailById(bus_id) {
|
|
34
37
|
return relations.find((bus) => bus.id == bus_id);
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -39,9 +42,20 @@ function findBusDetailById(bus_id) {
|
|
|
39
42
|
* @param {number} stop_id id of stop
|
|
40
43
|
* @returns { Bus[] }
|
|
41
44
|
*/
|
|
42
|
-
function findBusByOneStop(stop_id) {
|
|
45
|
+
export function findBusByOneStop(stop_id) {
|
|
43
46
|
return relations.filter((relation) => {
|
|
44
|
-
return relation.members.some((member) => member.ref
|
|
47
|
+
return relation.members.some((member) => member.ref == stop_id);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* find Bus that have a one stop asked
|
|
53
|
+
* @param {number} stop_label label of stop
|
|
54
|
+
* @returns { Bus[] }
|
|
55
|
+
*/
|
|
56
|
+
export function findBusByStopLabel(stop_label) {
|
|
57
|
+
return relations.filter((relation) => {
|
|
58
|
+
return relation.members.some((member) => member.label && member.label.toUpperCase() == stop_label.toUpperCase());
|
|
45
59
|
});
|
|
46
60
|
}
|
|
47
61
|
|
|
@@ -51,19 +65,38 @@ function findBusByOneStop(stop_id) {
|
|
|
51
65
|
* @param {number} end STOP_ID - end of Road
|
|
52
66
|
* @returns { Bus[] }
|
|
53
67
|
*/
|
|
54
|
-
function findBusByTwoStop(begin, end) {
|
|
68
|
+
export function findBusByTwoStop(begin, end) {
|
|
55
69
|
let firstRelationsFound = findBusByOneStop(begin);
|
|
56
70
|
return firstRelationsFound.filter((relation) => {
|
|
57
71
|
return relation.members.some((member) => member.ref === end);
|
|
58
72
|
});
|
|
59
73
|
}
|
|
60
74
|
|
|
75
|
+
/**
|
|
76
|
+
* find the right bus of trajet giving
|
|
77
|
+
* @param {string} begin STOP_LABEL - begin of Road
|
|
78
|
+
* @param {string} end STOP_LABEL - end of Road
|
|
79
|
+
* @returns { Bus[] }
|
|
80
|
+
*/
|
|
81
|
+
export function findBusByTwoStopLabel(begin, end) {
|
|
82
|
+
let firstRelationsFound = findBusByStopLabel(begin);
|
|
83
|
+
return firstRelationsFound.filter((relation) => {
|
|
84
|
+
const beginIndex = relation.members.findIndex(
|
|
85
|
+
(member) => member.label && member.label.toUpperCase() == begin.toUpperCase()
|
|
86
|
+
);
|
|
87
|
+
const endIndex = relation.members.findIndex(
|
|
88
|
+
(member) => member.label && member.label.toUpperCase() == end.toUpperCase()
|
|
89
|
+
);
|
|
90
|
+
return beginIndex != -1 && endIndex != -1 && beginIndex < endIndex;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
61
94
|
/**
|
|
62
95
|
* list all bus detail of Operator
|
|
63
96
|
* @param {string} operator_name id of operator ...
|
|
64
97
|
* @returns { Bus[] }
|
|
65
98
|
*/
|
|
66
|
-
function findBusDetailByOperator(operator_name) {
|
|
99
|
+
export function findBusDetailByOperator(operator_name) {
|
|
67
100
|
return relations.filter(
|
|
68
101
|
(bus) =>
|
|
69
102
|
bus.tags.operator &&
|
|
@@ -75,7 +108,7 @@ function findBusDetailByOperator(operator_name) {
|
|
|
75
108
|
* fetch all bus
|
|
76
109
|
* @returns { Bus[] }
|
|
77
110
|
*/
|
|
78
|
-
function findBusAll() {
|
|
111
|
+
export function findBusAll() {
|
|
79
112
|
return relations;
|
|
80
113
|
}
|
|
81
114
|
|
|
@@ -83,7 +116,7 @@ function findBusAll() {
|
|
|
83
116
|
* fetch all operator
|
|
84
117
|
* @returns { string[] }
|
|
85
118
|
*/
|
|
86
|
-
function findOperatorAll() {
|
|
119
|
+
export function findOperatorAll() {
|
|
87
120
|
return relations
|
|
88
121
|
.map((relation) => relation.tags.operator)
|
|
89
122
|
.filter(
|
|
@@ -96,7 +129,7 @@ function findOperatorAll() {
|
|
|
96
129
|
* fetch all opennning hours
|
|
97
130
|
* @returns { string[] }
|
|
98
131
|
*/
|
|
99
|
-
function findOpenHoursAll() {
|
|
132
|
+
export function findOpenHoursAll() {
|
|
100
133
|
return relations.map((relation) => relation.tags.opening_hours);
|
|
101
134
|
}
|
|
102
135
|
|
|
@@ -104,23 +137,11 @@ function findOpenHoursAll() {
|
|
|
104
137
|
* fetch all zone
|
|
105
138
|
* @returns { string[] }
|
|
106
139
|
*/
|
|
107
|
-
function findZoneAll() {
|
|
140
|
+
export function findZoneAll() {
|
|
108
141
|
return relations
|
|
109
142
|
.map((relation) => relation.tags.network)
|
|
110
143
|
.filter(
|
|
111
144
|
(value, index, self) =>
|
|
112
145
|
self.indexOf(value) === index && value != undefined
|
|
113
146
|
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
module.exports = {
|
|
117
|
-
findStopAll,
|
|
118
|
-
findBusByOneStop,
|
|
119
|
-
findBusByTwoStop,
|
|
120
|
-
findBusDetailById,
|
|
121
|
-
findBusAll,
|
|
122
|
-
findOperatorAll,
|
|
123
|
-
findZoneAll,
|
|
124
|
-
findBusDetailByOperator,
|
|
125
|
-
findOpenHoursAll
|
|
126
|
-
};
|
|
147
|
+
}
|
package/tsconfig.json
DELETED
|
File without changes
|