jrshikoku/lib/trainPositionTextArray.ts
2024-10-17 11:52:17 +00:00

34 lines
853 B
TypeScript
Raw 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;
};
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 } };
};