bangkok-train-fare 0.1.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/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { calculateFare, calculateGreenFare, } from "./fare/fareEngine.js";
2
+ export { buildPath, } from "./fare/pathfinder.js";
3
+ export { searchByCode, searchStation } from "./station/service.js";
@@ -0,0 +1,2 @@
1
+ export { searchByCode, searchStation } from "./service.js";
2
+ export type { Station } from "./model.js";
@@ -0,0 +1 @@
1
+ export { searchByCode, searchStation } from "./service.js";
@@ -0,0 +1,11 @@
1
+ export type Station = {
2
+ id: number;
3
+ code: string;
4
+ name_th: string;
5
+ label_th?: string;
6
+ name_en: string;
7
+ type: string;
8
+ line_id: number;
9
+ line_th: string;
10
+ line_en: string;
11
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { Station } from "./model.js";
2
+ export declare function searchByCode(code: string): Station;
3
+ export declare function searchStation(keyword: string): Promise<Station[]>;
@@ -0,0 +1,17 @@
1
+ import Fuse from "fuse.js";
2
+ import stations from "./stations.json" with { type: "json" };
3
+ const stationFuse = new Fuse(stations, {
4
+ keys: ["name_th", "name_en"],
5
+ threshold: 0.3,
6
+ });
7
+ export function searchByCode(code) {
8
+ return stations.find((s) => s.code === code);
9
+ }
10
+ export async function searchStation(keyword) {
11
+ if (!keyword)
12
+ return [];
13
+ return stationFuse
14
+ .search(keyword)
15
+ .slice(0, 5)
16
+ .map((result) => result.item);
17
+ }