Skip to content

Commit 451c1e0

Browse files
add toOldArabicAndTashfeerPannedWords() function
1 parent de8b6cf commit 451c1e0

6 files changed

Lines changed: 40 additions & 3 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Can be used in Node.js and the browser.
3232
- **Tashkeel Removal**: Easily remove Tashkeel from Arabic text.
3333
- **Tatweel Removal**: Remove unnecessary Tatweel characters from Arabic phrases.
3434
- **Convert To Old Arabic**: Transform Arabic text into old script.
35+
- **Convert To Old Arabic And Tashfeer Panned Words**: Transform Arabic text into old script and replace Panned Arabic text with visually similar characters for encoding purposes. (Panned words are words that considered as hate speech in social media)
3536
- **Tashfeer**: Replaces Arabic text with visually similar characters for encoding purposes.
3637
- **Tashfeer Panned Words**: Replaces Panned Arabic text with visually similar characters for encoding purposes. (Panned words are words that considered as hate speech in social media)
3738
- **Remove Arabic Affixes**: Removes predefined affixes (prefixes and suffixes) from an Arabic word if it starts or ends with those affixes.
@@ -104,6 +105,14 @@ console.log(ArabicServices.toOldArabic('الخَيْلُ وَاللّيْلُ و
104105
// Output: 'الحىل واللىل والٮىدا ٮعرڡٮى'
105106
```
106107

108+
### Convert To Old Arabic And Tashfeer Panned Words
109+
110+
```javascript
111+
const { ArabicServices } = require('arabic-services');
112+
console.log(ArabicServices.toOldArabicAndTashfeerPannedWords('جيش العدو يقتل الأطفال'));
113+
// Output: 'چـێـݭ !ڵعـݚۉ ی۪ـڨـټل الاطڡال'
114+
```
115+
107116
### Tashfeer
108117

109118
```javascript

example.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
`الخَيْـلُ وَاللّيْـلُ وَالبَيْـداءُ تَعرِفُني وَالسّيفُ وَالرّمحُ والقرْطاسُ وَالقَلَـمُ`,
2525
),
2626
);
27+
console.log(
28+
'toOldArabicAndTashfeerPannedWords:',
29+
ArabicServices.toOldArabicAndTashfeerPannedWords('جيش العدو يقتل الأطفال'),
30+
);
2731
console.log('Tashfeer:', ArabicServices.tashfeer('هذا النص مشفر'));
2832
console.log('tashfeerPannedWords:', ArabicServices.tashfeerPannedWords('جيش العدو يقتل الأطفال'));
2933
console.log('wordToLetters:', ArabicServices.wordToLetters('شجرة'));

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arabic-services",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Utility functions on Arabic text",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/scripts/scripts.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ export function toOldArabic(sentence: string): string {
5959
return newSentence;
6060
}
6161

62+
export function toOldArabicAndTashfeerPannedWords(sentence: string, levelOfTashfeer: number = 2): string {
63+
let new_sentence = '';
64+
for (const word of sentence.split(' ')) {
65+
if (checkIfPannedWord(word)) {
66+
new_sentence += tashfeerHandler(word, levelOfTashfeer) + ' ';
67+
} else {
68+
new_sentence += toOldArabic(word) + ' ';
69+
}
70+
}
71+
return new_sentence.trim();
72+
}
73+
6274
/**
6375
* Remove all tatweel from text
6476
* @param text string to remove tatweel from

tests/scripts.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ describe('#toOldArabic()', () => {
5858
});
5959
});
6060

61+
describe('#toOldArabicAndTashfeerPannedWords()', () => {
62+
it('should perform tashfeer encryption on panned words only and convert the rest to old arabic script', () => {
63+
const sentence = 'جيش العدو يقتل الأطفال';
64+
const result = ArabicServices.toOldArabicAndTashfeerPannedWords(sentence);
65+
expect(result).not.toEqual(sentence);
66+
expect(result).toMatch(/الاطڡال/);
67+
expect(result).not.toMatch(/جيش/);
68+
expect(result).not.toMatch(/العدو/);
69+
expect(result).not.toMatch(/يقتل/);
70+
});
71+
});
72+
6173
describe('#removeTatweel()', () => {
6274
it("should remove all tatweel 'ـ' from text", () => {
6375
const text = 'رائـــــــع';

0 commit comments

Comments
 (0)