Parameterize string in JavaStript
It is nice to know how to convert any text into hyphenated string.
const parameterize = (string) =>
string
.toLowerCase()
.replace(/[^a-zA-Z0-9 -]/g, ' ') // convert unwanted chars to spaces
.replace(/\s\s+/g, ' ') // convert multi spaces to single space
.replace(/\s/g, '-') // convert spaces to hyphens
.replace(/--+/g, '-'); // convert multi hyphens to single hyphen
parameterize('Masatoshi.Nishiguchi:;Software Engineer');
parameterize('Masatoshi/Nishiguchi~^Software Engineer');
parameterize('Masatoshi|Nishiguchi-=Software Engineer');
parameterize('Masatoshi%Nishiguchi_+Software Engineer');
//=> "masatoshi-nishiguchi-software-engineer"