Files
jrshikoku/utils/seUtils.ts
harukin-expo-dev-env 84403ea89d 暫定保存
2025-12-05 07:34:44 +00:00

62 lines
1.6 KiB
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.
/**
* SE駅での列車の状態に関するユーティリティ関数
*/
import type { SeTypes, SeStringResult } from "@/types";
/**
* SE文字列からラベルとタイプへのマッピング
*/
const SE_MAPPING: Record<string, SeStringResult> = {
"発": ["出発", "normal"],
"着": ["到着", "normal"],
"発編": ["出発", "community"],
"着編": ["到着", "community"],
"通発編": ["出発", "community"],
"通着編": ["到着", "community"],
"通編": ["通過", "community"],
"頃編": ["頃", "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かどうかを判定
*/
export const isThroughSe = (se: SeTypes): boolean => {
return (
se === "通過" ||
se === "通編" ||
se === "通発編" ||
se === "通着編" ||
se === "通休編" ||
se === "通発休編" ||
se === "通着休編"
);
};
/**
* コミュニティ投稿データかどうかを判定(「編」が含まれる)
*/
export const isCommunitySe = (se: SeTypes): boolean => {
return se.includes("編");
};