Skip to content

Commit

Permalink
Feat: #24 객체 동결 기능과 공통 validation 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Seok93 committed Jun 24, 2024
1 parent 97edf25 commit 882da0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Empty file removed src/utils/.gitkeep
Empty file.
15 changes: 15 additions & 0 deletions src/utils/Validator.tsx
Original file line number Diff line number Diff line change
@@ -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);
}
}
6 changes: 6 additions & 0 deletions src/utils/deepFreeze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const deepFreeze = <T extends object>(obj: T) => {
Object.keys(obj).forEach((prop) => {
if (typeof prop === 'object' && !Object.isFrozen(prop)) deepFreeze(prop);
});
return Object.freeze(obj);
};

0 comments on commit 882da0a

Please sign in to comment.