Display arabic text from right to left in console/terminal or browser. It now supports Harakat, Symbols, English, Arabic Numbers, and Farsi.
This library is created to help arab programmers to display the Arabic text correctly in the applications that don't support the Arabic language such as in the command prompt or linux terminals and many other applications.
Sure, most applications don't support the Arabic language, but they support the Unicode. But, most of the western languages are written from left to right, so that's why you find the Arabic text gets displayed in reverse in most terminals. So, all we need is a library that would organize the characters such that they get displayed in the correct way and this is what this library is for.
- Does not need fonts to support it
- Supports Arabic
- Letters
- Numbers & Conversion
- Symbols
- Harakat
- Supports English
- Letters
- Numbers
- Symbols
- Supports Farsi
- Numbers & Conversion
- Letters
- Harakat
- Symbols
- Can be used in a browser
- All it needs is an application that supports unicode 😊
const RTLArabic = require("rtl-arabic");
// These are the default options
const options = {
harakat: true,
numbers: false,
multiline: true,
};
let convertedText = new RTLArabic("احبكم", options).convert();
console.log(convertedText); // احبكم
// Convert English numbers to Arabic
convertedText = new RTLArabic("السلام عليكم - 2022", {
numbers: true,
}).convert();
console.log(convertedText); // السلام عليكم - ٢٠٢٢
// Check if text is Arabic
const isArabic = RTLArabic.isArabic("كيف الحال؟");
if (isArabic) {
// Do something
console.log("The text is indeed Arabic");
}
Option | Description | Default Value | Type |
---|---|---|---|
harakat | Enable harakat support | True | Boolean |
multiline | Enable multiline support | True | Boolean |
numbers | Enable English to Arabic numbers conversion | False | Boolean |
npm test
const RTLArabic = require("rtl-arabic");
console.log("Enter something:");
// Tell the input stream we're ready to start reading
process.stdin.resume();
// Set the default encoding
process.stdin.setEncoding("utf8");
// Ouput the transformed data as it comes in chunks
process.stdin.on("data", function (text) {
// Check if text is Arabic
if (RTLArabic.isArabic(text)) {
const convertedText = new RTLArabic(text, {
numbers: true,
multiline: false,
}).convert();
process.stdout.write(convertedText);
return;
}
process.stdout.write(text.toUpperCase());
});
- Fixed the لا || laa character
- Fixed unlinked characters
- Added Harakat Support
- Added English Support
- Added Arabic Numbers Support
- Added Symbols Support
- Added Farsi Support
- Displays Arabic and English Text Properly
- Check if text is Arabic
Fix the لا || laa characterFix unlinked charactersAdd Harakat SupportAdd Numbers SupportDisplay both Arabic and English text correctlySupport FarsiSupport Farsi NumbersSupport English (I couldn't think of a scenario where you'd use that but I'll add it for your convenience!)Add options object for flexibility