3

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

mayvn
  • 191
  • 1
  • 9
  • AFAIK, `0x...` sequences don't have any special meaning in JavaScript strings. In any case, the library appears to transliterate those characters just fine. I you don't want then transliterated you should remove them before passing them to slugify. – Álvaro González Mar 05 '16 at 08:42

1 Answers1

1

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

Zeeshan Hassan Memon
  • 8,105
  • 4
  • 43
  • 57