6

I have the following tiny nodejs script which just console logs an arabic verb:

var verb = "كتب";
console.log(verb);

However, the console log gives me: output: بتك - which is the verb, but inverted. (So instead of getting abc I get cba).

I guess that this is because nodejs does not know that I am using a right-to-left language, such as Arabic. However, I was not able to find anything online, on how to fix this? Is there some setting I don't know of?

PS: What's interesting is also, that while the letters are inverted, their their form is basically correct - so the first letter, although displayed at the end, still has the correct form of a first letter in Arabic (in Arabic, letters take on different forms, depending on the position in the word)

enter image description here

George Welder
  • 3,787
  • 11
  • 39
  • 75
  • 2
    I think its only because your terminal lacks the support of Arabic. I tested it and it works fine. – Assem Nov 18 '17 at 17:25

3 Answers3

2

Although i am not sure why it is doing that (i cant reproduce it in chrome console).

You could try reverse the string before output like so:

var verb = "كتب";
console.log(verb.split("").reverse().join(""));
Deckerz
  • 2,606
  • 14
  • 33
1

Bro it's just because of the console , your word will still conserved as it is if you try to send it in the response object for testing.

Said Pc
  • 565
  • 7
  • 13
1

There's a package on npm for displaying the Arabic text correctly on consoles/terminals that don't support it.

https://www.npmjs.com/package/rtl-arabic