22 lines
337 B
JavaScript
22 lines
337 B
JavaScript
|
|
var clean = require('to-no-case')
|
|
|
|
/**
|
|
* Export.
|
|
*/
|
|
|
|
module.exports = toSpaceCase
|
|
|
|
/**
|
|
* Convert a `string` to space case.
|
|
*
|
|
* @param {String} string
|
|
* @return {String}
|
|
*/
|
|
|
|
function toSpaceCase(string) {
|
|
return clean(string).replace(/[\W_]+(.|$)/g, function (matches, match) {
|
|
return match ? ' ' + match : ''
|
|
}).trim()
|
|
}
|