@technobuddha/library
Version:
A large library of useful functions
23 lines (22 loc) • 889 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.collapseWhitespace = void 0;
var constants_1 = require("../constants");
var clean_1 = __importDefault(require("../clean"));
/**
* Replace all whitespace within a string with a single space
*
* @param input The string
* @param trim If true, remove leading and trailing whitespace
*/
function collapseWhitespace(input, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.trim, trim = _c === void 0 ? true : _c;
if (trim)
return clean_1.default(input.replace(/\s+/ug, constants_1.space), constants_1.space);
return input.replace(/\s+/ug, constants_1.space);
}
exports.collapseWhitespace = collapseWhitespace;
exports.default = collapseWhitespace;