arabicStrings
An NPM package that extends the native String object with methods to help when dealing with Arabic strings for node and the browser.
NPM updated package of @ahmads/arabicString repo
Usage
node
const arabicString = require('@6degrees/arabic-strings');
String#howArabic()
The percentage of Arabic letters in the String
.
Example
arabicString.howArabic('foobar');
arabicString.howArabic('فوو bar');
arabicString.howArabic('فوبار');
String#howNotArabic()
The percentage of non-Arabic letters in the String
.
Example
arabicString.howNotArabic('فوبار');
arabicString.howNotArabic('فوو bar');
arabicString.howNotArabic('foobar');
String#isArabic(threshold)
Is the String
Arabic, based on a given threshold
between 0
and 1
. Defaults to 0.79
.
Example
arabicString.isArabic('فوو');
arabicString.isArabic('فوو bar baz');
String#hasArabic()
Does the String
have any Arabic letter.
Example
arabicString.hasArabic('فوو bar');
arabicString.hasArabic('foo bar');
String#removeTashkel()
Will return the String
without the diacritics.
Example
arabicString.removeTashkel('مٌحمْد');
arabicString.removeTashkel('وَتُرى الْكَوَاكِبِ فِي الْمَجَرَّةِ شَرَعَا*** مِثْلُ الظِّباءِ كوارعا فِي جَدْوَلِ');
String#removeTatwel()
Will return the String
without the diacritics.
Example
arabicString.removeTatwel('مــرحــبــا');
String#sanitize()
Will return the String
without the diacritics, and clean characters.
Example
arabicString.sanitize(`أَنا الَّذي نَظَرَ الأَعمى إِلى أَدَبي ... وَأَسمَـعَت كَلِماتي مَن بِهِ صَمَمُ
أَنـامُ مِلءَ جُفوني عَن شَوارِدِهــا ... وَيَسهَرُ الخَلقُ جَرّاها وَيَختَصِمُ
وَجـــاهِلٍ مَدَّهُ في جَهلِهِ ضَحِكي ... حَتّى أَتَتهُ يَدٌ فَرّاسَــــــةٌ وَفَـــــمُ
`);
Credits
License
(The MIT License)