npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rtl-arabic

v2.1.1

Published

Display Arabic and Farsi text from right to left correctly with harakat, numbers, and symbols. Useful for CLI's/console applications.

Downloads

87

Readme

rtl-arabic

Display arabic text from right to left in console/terminal or browser. It now supports Harakat, Symbols, English, Arabic Numbers, and Farsi.

What is this for?

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.

How does it work?

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.

What are the features of this library?

  • 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 😊

Examples

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");
}

Options

| 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 |

Tests

npm test

Console App Example

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());
});

What's New?

  • 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

Todo:

  • ~~Fix the لا || laa character~~
  • ~~Fix unlinked characters~~
  • ~~Add Harakat Support~~
  • ~~Add Numbers Support~~
  • ~~Display both Arabic and English text correctly~~
  • ~~Support Farsi~~
  • ~~Support Farsi Numbers~~
  • ~~Support 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~~