From 882da0a7faddab71d100124923e459232d2a9334 Mon Sep 17 00:00:00 2001 From: Seok93 Date: Mon, 24 Jun 2024 22:19:53 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20#24=20=EA=B0=9D=EC=B2=B4=20=EB=8F=99?= =?UTF-8?q?=EA=B2=B0=20=EA=B8=B0=EB=8A=A5=EA=B3=BC=20=EA=B3=B5=ED=86=B5=20?= =?UTF-8?q?validation=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/.gitkeep | 0 src/utils/Validator.tsx | 15 +++++++++++++++ src/utils/deepFreeze.ts | 6 ++++++ 3 files changed, 21 insertions(+) delete mode 100644 src/utils/.gitkeep create mode 100644 src/utils/Validator.tsx create mode 100644 src/utils/deepFreeze.ts diff --git a/src/utils/.gitkeep b/src/utils/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/utils/Validator.tsx b/src/utils/Validator.tsx new file mode 100644 index 00000000..7a42041d --- /dev/null +++ b/src/utils/Validator.tsx @@ -0,0 +1,15 @@ +export default class Validator { + public static isEmptyString(value: string) { + return value.trim().length === 0; + } + + // ToDo: 정말로 공용 Validation 기능인가 생각해보기 + public static isDuplicatedName(nameList: string[], name: string, ignoreCase: boolean = true) { + if (ignoreCase) { + const lowerCaseNameList = nameList.map((n) => n.toLowerCase().trim()); + const lowerCaseName = name.toLowerCase().trim(); + return lowerCaseNameList.includes(lowerCaseName); + } + return nameList.includes(name); + } +} diff --git a/src/utils/deepFreeze.ts b/src/utils/deepFreeze.ts new file mode 100644 index 00000000..c47e567c --- /dev/null +++ b/src/utils/deepFreeze.ts @@ -0,0 +1,6 @@ +export const deepFreeze = (obj: T) => { + Object.keys(obj).forEach((prop) => { + if (typeof prop === 'object' && !Object.isFrozen(prop)) deepFreeze(prop); + }); + return Object.freeze(obj); +};