A comparator function for comparing two persian strings with correct alphabetic order.
$ npm install persian-alphabetic-compare
import persianAlphabeticCompare from 'persian-alphabetic-compare';
['پاوه', 'تهران', 'بهشهر', 'گرگان',
'کرمانشاه', 'کردکوی', 'یاسوج', 'اهواز'].sort(persianAlphabeticCompare);
// => ["اهواز", "بهشهر", "پاوه", "تهران", "کردکوی", "کرمانشاه", "گرگان", "یاسوج"]
If you don't have <IE11 requirement, you don't need this library. Most major browsers support Intl API, which provides Locale-aware string comparison among other neat features.
var collator = new Intl.Collator('fa');
['پاوه', 'تهران', 'بهشهر', 'گرگان',
'کرمانشاه', 'كردکوی', 'ياسوج', 'اهواز'].sort(collator.compare);
// => ["اهواز", "بهشهر", "پاوه", "تهران", "كردکوی", "کرمانشاه", "گرگان", "ياسوج"]