Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions util/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ export const formatPhoneNumber = (phoneNumber: string): string => {

export const formatParentName = (user: User): string => {
const familyName = user.firstName;
// 全角スペースがあればそのまま返す
if (user.parentName.includes(" ")) {
return user.parentName;
}
// 半角スペースがあれば全角スペースに変換して返す
if (user.parentName.includes(" ")) {
return user.parentName.replace(/ /g, " ");
}
// スペースがないとき、親子の姓が同じ場合は、子の姓の文字数を参考にスペースを入れる
const parentFamilyName = user.parentName.slice(0, familyName.length);
if (familyName === parentFamilyName) {
return `${user.firstName} ${user.parentName.slice(familyName.length)}`;
if (typeof user.parentName === "string") {
// 全角スペースがあればそのまま返す
if (user.parentName.includes(" ")) {
return user.parentName;
}
// 半角スペースがあれば全角スペースに変換して返す
if (user.parentName.includes(" ")) {
return user.parentName.replace(/ /g, " ");
}
// スペースがないとき、親子の姓が同じ場合は、子の姓の文字数を参考にスペースを入れる
const parentFamilyName = user.parentName.slice(0, familyName.length);
if (familyName === parentFamilyName) {
return `${user.firstName} ${user.parentName.slice(familyName.length)}`;
}
}
// これ以外はそのまま返す
return user.parentName;
Expand Down
Loading