const WRAPPABLE_TYPE_LENGTH = 4; const MIN_LONG_TRAIN_NAME_LENGTH = 8; const countCharacters = (value: string) => Array.from(value).length; const normalizeTrainName = (trainName: string) => trainName.replace(/\s+/g, ""); export const shouldWrapTrainType = ( typeName: string, trainName: string, ): boolean => countCharacters(typeName) === WRAPPABLE_TYPE_LENGTH && countCharacters(normalizeTrainName(trainName)) >= MIN_LONG_TRAIN_NAME_LENGTH; export const formatWrappedTrainType = (typeName: string): string => { const chars = Array.from(typeName); if (chars.length !== WRAPPABLE_TYPE_LENGTH) { return typeName; } return `${chars.slice(0, 2).join("")}\n${chars.slice(2).join("")}`; };