Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacement and remove (question & suggestion) #95

Closed
proclaim opened this issue Nov 10, 2020 · 3 comments · Fixed by #174
Closed

replacement and remove (question & suggestion) #95

proclaim opened this issue Nov 10, 2020 · 3 comments · Fixed by #174

Comments

@proclaim
Copy link

Because the way slugify checkes for undefined, when we replace char with empty string, things might not work as expected.

for example, I want to replace ☢ with radioactive, and colon with empty space, I'll have to do it in extend and also remove. and before I dive in deep into src code, I was using
slugify.extend({ '&': '', '.': '-', '%': '', ':': '' })
and expect that it will replace the char that I specified will be gone, however, & was not replaced but removed by
.replace(options.remove || /[^\w\s$*_+~.()'"!\-:@]+/g, '')
and because of this, the colon didn't work out for me (colon should be replaced by empty string).

Am I missing something? if not, could we change from:
return result + (locale[ch] || charMap[ch] || ch)
to
return result + (locale[ch] !== undefined ? locale[ch] : charMap[ch] !== undefined ? charMap[ch] : ch)

@Trott
Copy link
Collaborator

Trott commented Nov 10, 2020

Replicated with this:

'use strict';

const slugify = require('slugify');

console.log(slugify('a&b:c')) // aandb:c

slugify.extend({ '&': '', '.': '-', '%': '', ':': '' });

console.log(slugify('a&b:c')) // Expected abc but got ab:c

@Trott
Copy link
Collaborator

Trott commented Nov 10, 2020

Not necessarily a great solution and probably something you already realize, but just in case: You can work around this in your own code by explicitly sending a remove option that omits the ::

slugify(myString, { remove: /[^\w\s$*_+~.()'"!\-@]+/g });

@Leandro-Angeli
Copy link

hello.How can I change the url entirely??For example: I got this: www.random.com/product?id=0 , and I want to change it fot the following: www.random.com/product-name.Is it posible??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants