Skip to content

Vajehyab/arabic-to-persian.js

Repository files navigation

arabic-to-persian

Build Status Coverage Status PRs Welcome

arabic-to-persian is a library to convert arabic text to persian.

Install

npm install arabic-to-persian

or

yarn add arabic-to-persian

Usage

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

Api

See documentation

Contributing

See contributing guide