jrshikoku/lib/trainPositionTextArray.ts
harukin-expo-dev-env 199d41fd83 クエリの追加
2024-10-17 16:12:36 +00:00

40 lines
967 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

type returnBetweenType = {
isBetween: true;
Pos: {
from: string;
to: string;
};
};
type returnCurrentType = {
isBetween: false;
Pos: {
Pos: string;
};
};
export type trainDataType = {
Pos?: string;
Direction?: number;
Index?: number;
Line?: string;
PosNum?: number;
Type?: string;
delay?: string | number;
num?: string;
};
type trainData = (
trainData: trainDataType
) => returnBetweenType | returnCurrentType;
export const trainPosition: trainData = (trainData) => {
if (!trainData?.Pos) return { isBetween: false, Pos: { Pos: "" } };
const { Pos, Direction } = trainData;
if (Pos.match("")) {
const [topST, downST] = Pos.replace("(下り)", "")
.replace("(上り)", "")
.split("");
const from = Direction == 1 ? topST : downST;
const to = Direction == 1 ? downST : topST;
return { isBetween: true, Pos: { from, to } };
} else return { isBetween: false, Pos: { Pos } };
};