@technobuddha/library
Version:
A large library of useful functions
15 lines (14 loc) • 503 B
JavaScript
import { space } from '../constants';
import clean from '../clean';
/**
* Replace all breaking space (space, tab, carriage return, new line) with a single space
*
* @param input The string
* @param trim If true, remove leading and trailing whitespace
*/
export function collapseBreakingspace(input, { trim = true } = {}) {
if (trim)
return clean(input.replace(/[\t\r\n ]+/ug, space), '\t\r\n ');
return input.replace(/[\t\r\n ]+/ug, space);
}
export default collapseBreakingspace;