Masatoshi Nishiguchi
Software Engineer

JS - Parameterize String

javascript
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::web developer');
parameterize('Masatoshi Nishiguchi, web developer');
parameterize('Masatoshi Nishiguchi -- web developer');
//=> "masatoshi-nishiguchi-web-developer"