Skip to content

Commit 6323315

Browse files
committed
refactor: isLexicalContent 유틸 함수를 early return 방식으로 변경
1 parent 1344fc1 commit 6323315

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

services/one-app/src/common/utils/validate.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ export function isLexicalContent(content: unknown): content is LexicalNode {
1212
try {
1313
const parsed = JSON.parse(content);
1414

15-
return (
16-
parsed !== null &&
17-
typeof parsed === 'object' &&
18-
'root' in parsed &&
19-
typeof parsed.root === 'object' &&
20-
parsed.root !== null &&
21-
'children' in parsed.root &&
22-
Array.isArray(parsed.root.children)
23-
);
15+
if (!parsed || typeof parsed !== 'object') return false;
16+
17+
const { root } = parsed;
18+
19+
if (!root || typeof root !== 'object') return false;
20+
21+
const { children } = root;
22+
23+
if (!children || !Array.isArray(children)) return false;
24+
25+
return true;
2426
} catch {
2527
return false;
2628
}

0 commit comments

Comments
 (0)