UNPKG

string-squish

Version:

Removes all terminal whitespace and replaces all censecutive whitespace from a String.

7 lines (5 loc) 238 B
var CONSECUTIVE_SPACES = /\s+/g; module.exports = function squish (string) { if (typeof string !== 'string') throw 'Invalid \'string\'. Expected String, got ' + typeof string; return string.trim().replace(CONSECUTIVE_SPACES, ' '); }