WebSocket Tool: Fix slug formula (allow _) to fix 'Try It' links

This commit is contained in:
mDuo13
2019-07-02 18:36:04 -07:00
parent 03b16a12d7
commit e0a07a691e

View File

@@ -16,13 +16,13 @@ function slugify(str) {
str = str.toLowerCase() str = str.toLowerCase()
// remove accents, swap ñ for n, etc // remove accents, swap ñ for n, etc
const from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;" const from = "àáäâèéëêìíïîòóöôùúüûñç·/,:;"
const to = "aaaaeeeeiiiioooouuuunc------" const to = "aaaaeeeeiiiioooouuuunc-----"
for (let i=0, l=from.length ; i<l ; i++) { for (let i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i)) str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i))
} }
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars str = str.replace(/[^a-z0-9 _-]/g, '') // remove invalid chars
.replace(/\s+/g, '-') // collapse whitespace and replace by - .replace(/\s+/g, '-') // collapse whitespace and replace by -
.replace(/-+/g, '-'); // collapse dashes .replace(/-+/g, '-'); // collapse dashes