question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello,

How can I slugify transform this: السلام عليكم ورحمة الله وبركاته

Into this: السلام-عليكم-ورحمة-الله-وبركاته

shall I add the Arabic characters to charmap.json as below ?

{
"أ": "أ",
"ب": "ب",
"ت": "ت",
"ث": "ث",
"ج": "ج",
"ح": "ح"
}

and so on ?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
simovcommented, Feb 21, 2021

I was about to start working on this feature but I noticed that the issue comes from the default remove regex:

/[^\w\s$*_+~.()'"!\-:@]+/g

This regex removes anything that’s not in that list, meaning it preserves only the listed characters. The \w flag stands for the a-zA-Z range, meaning anything except those characters will be removed.

So instead we can update the remove regex to remove only the listed characters:

slugify('السلام عليكم ورحمة الله وبركاته', {
  remove: /[$*_+~.()'"!\-:@]+/g
})

And this yields the expected result:

السلام-عليكم-ورحمة-الله-وبركاته
1reaction
Trottcommented, Jan 7, 2022

If you’re not trying to get a Latin alphabet result and if you know that your input strings will use a single alphabet, I imagine using String.prototype.replace() might be easier (and have a smaller code footprint) than using slugify().

const regex = /[^\d\u0621-\u064A]+/g;
const string = 'السلام عليكم ورحمة الله وبركاته';

console.log(string.replace(regex, '-')); // 'السلام-عليكم-ورحمة-الله-وبركاته'
Read more comments on GitHub >

github_iconTop Results From Across the Web

Arabic - Wikipedia
Arabic is a Semitic language spoken primarily across the Arab world. Having emerged in the 1st century, it is named after the Arab...
Read more >
Arabic language | History & Alphabet - Britannica
Arabic language, Semitic language spoken in a large area including North Africa, most of the Arabian Peninsula, and other parts of the Middle...
Read more >
The Evolution of the Arabic language in the Silk Roads
Arabic, which first emerged in the northwest of the Arabian Peninsula, is a member of the Semitic family of languages which also includes...
Read more >
Arabic (Overview) - MustGo.com
Arabic (al-'arabiyyah, العربية) is a macrolanguage. As the largest member of the Semitic branch of the Afro-Asiatic language family it includes all ...
Read more >
The Arabic Language
Arabic belongs to the Semitic language family, and is hence closely related to Amharic (spoken in Ethiopia) and Hebrew. Modern Standard Arabic (MSA)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found