UNPKG

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.

40 lines 1.24 kB
export function trim(text, pattern = " ") { return ltrim(rtrim(text, pattern)); } export function ltrim(text, pattern = " ") { if (typeof text === "string") { if (typeof pattern === "string") { while (text.startsWith(pattern)) { text = text.slice(pattern.length); } } else { const hits = pattern.exec(text) || []; let hit = hits.find(hit => text.startsWith(hit)); while (hit) { text = text.slice(hit.length); hit = hits.find(hit => text.startsWith(hit)); } } } return text; } export function rtrim(text, pattern = " ") { if (typeof text === "string") { if (typeof pattern === "string") { while (text.endsWith(pattern)) { text = text.slice(0, -1 * pattern.length); } } else { const hits = pattern.exec(text) || []; let hit = hits.find(hit => text.endsWith(hit)); while (hit) { text = text.slice(0, -1 * hit.length); hit = hits.find(hit => text.endsWith(hit)); } } } return text; } //# sourceMappingURL=trim.js.map