Skip to content

Commit

Permalink
added try catch to JSON.parse block
Browse files Browse the repository at this point in the history
  • Loading branch information
roienatan committed Dec 5, 2023
1 parent b7759ca commit 7d1cfe2
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/shared/utils/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,34 @@ export const isRTL = (text = ""): boolean => {
};

export const isRtlText = (text = ""): boolean => {
const parsedText = JSON.parse(text);
const textWithNoMentions = JSON.stringify(
parsedText[0].children?.filter((item) => item.type !== ElementType.Mention),
);
try {
const parsedText = JSON.parse(text);
const textWithNoMentions = JSON.stringify(
parsedText[0].children?.filter(
(item) => item.type !== ElementType.Mention,
),
);

for (let i = 0; i < textWithNoMentions.length; i++) {
const charCode = textWithNoMentions.charCodeAt(i);
for (let i = 0; i < textWithNoMentions.length; i++) {
const charCode = textWithNoMentions.charCodeAt(i);

// Hebrew Block
if (charCode >= 0x0590 && charCode <= 0x05ff) return true;
// Hebrew Block
if (charCode >= 0x0590 && charCode <= 0x05ff) return true;

// Arabic Block
if (charCode >= 0x0600 && charCode <= 0x06ff) return true;
// Arabic Block
if (charCode >= 0x0600 && charCode <= 0x06ff) return true;

// Arabic Supplement Block
if (charCode >= 0x0750 && charCode <= 0x077f) return true;
// Arabic Supplement Block
if (charCode >= 0x0750 && charCode <= 0x077f) return true;

// Arabic Extended-A Block
if (charCode >= 0x08a0 && charCode <= 0x08ff) return true;
// Arabic Extended-A Block
if (charCode >= 0x08a0 && charCode <= 0x08ff) return true;
}
return false;
} catch (error) {
console.error(error);
return false;
}
return false;
};

/**
Expand Down

0 comments on commit 7d1cfe2

Please sign in to comment.