syphonx-core
Version:
SyphonX is a template-driven solution for extracting data from HTML in a highly efficient way. It combines the power of jQuery, Regular Expressions, and Javascript into a declarative template-driven format that extracts and reshapes HTML data into JSON.
27 lines • 827 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.collapseWhitespace = void 0;
function collapseWhitespace(text, newlines) {
if (newlines === void 0) { newlines = true; }
if (typeof text === "string" && text.trim().length === 0) {
return null;
}
else if (typeof text === "string" && newlines) {
return text
.replace(/\s*\n\s*/gm, "\n")
.replace(/\n{2,}/gm, "\n")
.replace(/\s{2,}/gm, " ")
.trim();
}
else if (typeof text === "string" && !newlines) {
return text
.replace(/\n/gm, " ")
.replace(/\s{2,}/gm, " ")
.trim();
}
else {
return text;
}
}
exports.collapseWhitespace = collapseWhitespace;
//# sourceMappingURL=collapseWhitespace.js.map