Files
jrshikoku/utils/seUtils.ts

74 lines
2.0 KiB
TypeScript

/**
* SE(駅での列車の状態)に関するユーティリティ関数
*/
import type { SeTypes, SeStringResult } from "@/types";
/**
* SE文字列からラベルとタイプへのマッピング
*/
const SE_MAPPING: Record<string, SeStringResult> = {
"発": ["出発", "normal"],
"着": ["到着", "normal"],
"発編": ["出発", "community"],
"着編": ["到着", "community"],
"通発編": ["出発", "community"],
"通着編": ["到着", "community"],
"通編": ["通過", "community"],
"頃編": ["頃", "community"],
// 運休系
"休編": ["運休", "community"], // 後方互換性のため残す
"休発": ["出発", "normal"],
"休着": ["到着", "normal"],
"休発編": ["出発", "community"],
"休着編": ["到着", "community"],
"通休編": ["通過", "community"],
"通発休編": ["出発", "community"],
"通着休編": ["到着", "community"],
};
/**
* SE文字列を表示用の文字列とタイプに変換
* @param se SE文字列
* @returns [表示用文字列, タイプ]
*/
export const parseSeString = (se: SeTypes): SeStringResult => {
return SE_MAPPING[se] || [se, "normal"];
};
/**
* 運休系のSEかどうかを判定
*/
export const isCanceledSe = (se: SeTypes): boolean => {
return se === "休編" ||
se === "休発" ||
se === "休着" ||
se === "休発編" ||
se === "休着編" ||
se === "通休編" ||
se === "通発休編" ||
se === "通着休編";
};
/**
* 通過系のSEかどうかを判定
*/
export const isThroughSe = (se: SeTypes): boolean => {
return (
se === "通過" ||
se === "通編" ||
se === "通発編" ||
se === "通着編" ||
se === "通休編" ||
se === "通発休編" ||
se === "通着休編"
);
};
/**
* コミュニティ投稿データかどうかを判定(「編」が含まれる)
*/
export const isCommunitySe = (se: SeTypes): boolean => {
return se.includes("編");
};