├── README.md └── slug.js /README.md: -------------------------------------------------------------------------------- 1 | # JavaScript convert string to URL slug with Persian support (تولید اسلاگ مناسب URL با پشتیبانی از زبان فارسی) 2 | 3 | ## Introduction 4 | 5 | > if you want to convert string to slug and make a slugify URL with Persian support you could use this function 6 | 7 | > به کمک تابع زیر میتوانید رشته خود را به یک متن اسلاگ تبدیل کنید که برای تولید لینک ها بسیار کاربردی است این تابع زبان فارسی را نیز پشتیبانی میکند 8 | 9 | ## Code Samples 10 | 11 | > 12 | function slug(titleStr){ 13 | titleStr = titleStr.replace(/^\s+|\s+$/g, ''); 14 | titleStr = titleStr.toLowerCase(); 15 | //persian support 16 | titleStr = titleStr.replace(/[^a-z0-9_\s-ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/, '') 17 | // Collapse whitespace and replace by - 18 | .replace(/\s+/g, '-') 19 | // Collapse dashes 20 | .replace(/-+/g, '-'); 21 | return titleStr; 22 | } 23 | 24 | ## Installation 25 | 26 | > use this function at the end of your scripts and call it everywhere you want, so your string converts to slug and you could use that for creating links and URLs 27 | -------------------------------------------------------------------------------- /slug.js: -------------------------------------------------------------------------------- 1 | function slug(titleStr){ 2 | titleStr = titleStr.replace(/^\s+|\s+$/g, ''); 3 | titleStr = titleStr.toLowerCase(); 4 | //persian support 5 | titleStr = titleStr.replace(/[^a-z0-9_\s-ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/, '') 6 | // Collapse whitespace and replace by - 7 | .replace(/\s+/g, '-') 8 | // Collapse dashes 9 | .replace(/-+/g, '-'); 10 | slugStr=titleStr; 11 | return slugStr; 12 | } --------------------------------------------------------------------------------