JSFiddle - React, Tailwind, and code Playground
by Manuel Souto Pico
HTML
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="utf-8">
<title>مرحبا يا العالم!</title>
</head>
<body>
<h1>مرحبا يا العالم!</h1>
</body>
</html>
JavaScript
/* change directionality if the target language is Arabic (and derivates) or Hebrew */
const bodyText = document.body.innerText
const regex = /\p{Script=Arabic}|\p{Script=Hebrew}/u
const bidiFound = bodyText.match(regex)
if (bidiFound) { document["dir"] = "rtl" }