Skip to content

Commit

Permalink
feat: add regex mapping for category parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
keemsebin committed Nov 9, 2024
1 parent 933b72c commit 1f84dfc
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/utils/parseCategory.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
export const parseCategory = (categoryName: string) => {
if (categoryName.includes('식')) {
return 'restaurant';
}
if (categoryName.includes('카페') || categoryName.includes('디저트')) {
return 'cafe';
}
if (categoryName.includes('술집')) {
return 'bar';
}
if (categoryName.includes('쇼핑') || categoryName.includes('유통')) {
return 'shopping';
}
if (categoryName.includes('여행') || categoryName.includes('명소')) {
return 'travel';
}
if (categoryName.includes('공공') || categoryName.includes('사회')) {
return 'public';
}
if (categoryName.includes('병원') || categoryName.includes('의원')) {
return 'hospital';
const CATEGORY_REGEX_MAPPING: { [key: string]: RegExp } = {
restaurant: /||||/,
cafe: /|/,
bar: //,
shopping: /|/,
public: /||/,
travel: /|/,
hospital: /|/,
};

export const parseCategory = (categoryName: string): string => {
for (const [category, regex] of Object.entries(CATEGORY_REGEX_MAPPING)) {
if (regex.test(categoryName)) {
return category;
}
}

return 'other';
Expand Down

0 comments on commit 1f84dfc

Please sign in to comment.