Here, this should do all that you need
function doSomething(input) {
return input
.replace(/^\s\s*/, '') // Remove Preceding white space
.replace(/\s\s*$/, '') // Remove Trailing white space
.replace(/([\s]+)/g, '-'); // Replace remaining white space with dashes
}
alert(doSomething(" something with some whitespace "));