@technobuddha/library
Version:
A large library of useful functions
15 lines (14 loc) • 450 B
JavaScript
import { space } from '../constants';
import clean from '../clean';
/**
* Replace all whitespace within a string with a single space
*
* @param input The string
* @param trim If true, remove leading and trailing whitespace
*/
export function collapseWhitespace(input, { trim = true } = {}) {
if (trim)
return clean(input.replace(/\s+/ug, space), space);
return input.replace(/\s+/ug, space);
}
export default collapseWhitespace;