Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transliterate Removal of Symbols

I am trying to transliterate ®, ©, ', and ™ into blank characters meaning completely removing them when they are slugified.

The following is what I tried to do:

var tr = require('transliteration');
var slugify = require('transliteration').slugify;

// replacement attempt
tr("0xAE, 0xFEFF"); // ®
tr("0xA9, 0xFEFF"); // ©
tr("0x2122, 0xFEFF"); // ™

slugify(name, { lowercase: true })

For example, when I use slugify on a name like "ABC®: 123", it transliterates to:

abc-r-123

However, I want the resulting name to be like:

abc-123

like image 955
mayvn Avatar asked Dec 31 '25 06:12

mayvn


1 Answers

See following steps, how I did it:

console.log(tr("ABC ©")); //Output: ABC (c)

var test1 = "ABC®: 123©" //test input to see results

var regex = /\((r)\)|\((c)\)/g; //regex to remove ® and ©, update on desire

console.log(tr(test1).replace(regex,'')); //Output: ABC: 123

//now sluggify
console.log(slugify(test1, { lowercase: true, separator: '-' })); //Output: abc-123

Further working can be seen on Github Here

like image 197
Zeeshan Hassan Memon Avatar answered Jan 01 '26 20:01

Zeeshan Hassan Memon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!