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.
49 lines • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.rtrim = exports.ltrim = exports.trim = void 0;
function trim(text, pattern) {
if (pattern === void 0) { pattern = " "; }
return ltrim(rtrim(text, pattern));
}
exports.trim = trim;
function ltrim(text, pattern) {
if (pattern === void 0) { pattern = " "; }
if (typeof text === "string") {
if (typeof pattern === "string") {
while (text.startsWith(pattern)) {
text = text.slice(pattern.length);
}
}
else {
var hits = pattern.exec(text) || [];
var hit = hits.find(function (hit) { return text.startsWith(hit); });
while (hit) {
text = text.slice(hit.length);
hit = hits.find(function (hit) { return text.startsWith(hit); });
}
}
}
return text;
}
exports.ltrim = ltrim;
function rtrim(text, pattern) {
if (pattern === void 0) { pattern = " "; }
if (typeof text === "string") {
if (typeof pattern === "string") {
while (text.endsWith(pattern)) {
text = text.slice(0, -1 * pattern.length);
}
}
else {
var hits = pattern.exec(text) || [];
var hit = hits.find(function (hit) { return text.endsWith(hit); });
while (hit) {
text = text.slice(0, -1 * hit.length);
hit = hits.find(function (hit) { return text.endsWith(hit); });
}
}
}
return text;
}
exports.rtrim = rtrim;
//# sourceMappingURL=trim.js.map