arabic-to-persian
is a library to convert arabic text to persian.
npm install arabic-to-persian
or
yarn add arabic-to-persian
In most cases you just need to import convert
function as bellow:
import { convert } from "arabic-to-persian";
const arabic = "ﻭاﮊﻩ";
const persian = "واژه";
console.log(arabic === persian); // false
console.log(convert(arabic) === persian); // true
convert
accepts another argument as options
.
In this example you can see how it's possible to set your own charMap
:
import { convert } from "arabic-to-persian";
const arabic = "﷼";
const persian = "ریال";
console.log(arabic === persian); // false
console.log(convert(arabic) === persian); // false
function customConvert(text) {
const options = { charMap: {} };
options.charMap[arabic] = persian;
return convert(text, options);
}
console.log(customConvert(arabic) === persian); // true
A better way to create your own converter is createConverter closure:
import { createConverter } from "arabic-to-persian";
const arabic = "﷼";
const persian = "ریال";
console.log(arabic === persian); // false
const options = { charMap: {} };
options.charMap[arabic] = persian;
const ar2fa = createConverter(options)
console.log(ar2fa(arabic) === persian); // true
See documentation