FarsiTyper is a modern JavaScript utility that allows Persian (Farsi) text typing on English keyboards. It supports dynamic character conversion, direction toggling (RTL/LTR), and real-time input enhancement on <input>
and <textarea>
elements with lang="fa"
.
- 🔤 Realtime Farsi keyboard emulation
- 🔁 Direction toggle: RTL
↔️ LTR - 🌐 Language toggle button (FA / EN)
- 📱 Mobile and desktop compatible
- 🧠 Static conversion method (
convertString
) for non-DOM text processing - 📦 Available via NPM and browser build
npm install farsityper
Download or include the built file:
<script src="dist/farsityper.min.js"></script>
import { FarsiTyper } from 'farsityper';
window.addEventListener('DOMContentLoaded', () => {
const farsiTyper = new FarsiTyper({
showLangButton: true, // Show FA/EN toggle button
changeDir: true, // Show RTL/LTR direction button
patternFA: true // Convert digits and characters fully
});
});
Or in browser:
<script>
const farsiTyper = new FarsiTyper({ showLangButton: true });
</script>
Add lang="fa"
or lang="fa-ir"
to any <input>
or <textarea>
field to enable typing support.
<input type="text" lang="fa" placeholder="Type Farsi here...">
<textarea lang="fa"></textarea>
You can convert any English-typed Farsi string directly without touching the DOM:
import { FarsiTyper } from 'farsityper';
const input = "sghl"; // User typed this using English layout
const result = FarsiTyper.convertString(input);
console.log(result); // Output: "سلام"
Or in browser:
<script>
const result = FarsiTyper.convertString("sghl");
console.log(result); // "سلام"
</script>
This method does not require creating an instance of
FarsiTyper
and does not attach any DOM listeners.
- Press Ctrl + Space in an active Farsi field to toggle between FA/EN mode (works via
keydown
)
Use nomask="true"
on any input/textarea to prevent character conversion:
<input type="text" lang="fa" nomask="true" placeholder="No Farsi conversion here...">
The script automatically detects mobile devices and switches to keyup
-based processing.
GPL - Free to use, modify, and distribute under the terms of the GNU General Public License.
Originally inspired by Kaveh Ahmadi's farsityper
, now refactored and modernized.