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.

41 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseUrl = exports.parseNumber = exports.parseBoolean = void 0; function parseBoolean(value) { if (typeof value === "boolean") return value; else if (typeof value === "string") return value !== "" && value.trim().toLowerCase() !== "false" && value.trim() !== "0"; else return undefined; } exports.parseBoolean = parseBoolean; function parseNumber(value) { if (typeof value === "number") { return !isNaN(value) ? value : undefined; } if (typeof value === "string") { var _a = /([0-9.,]+)/.exec(value) || [], text = _a[1]; if (/\.\d+$/.test(text)) text = text.replace(/,/g, ""); if (/,\d+$/.test(text)) text = text.replace(/\./g, ""); var result = parseFloat(text); return !isNaN(result) ? result : undefined; } return undefined; } exports.parseNumber = parseNumber; function parseUrl(url) { if (typeof url === "string" && /^https?:\/\//.test(url)) { var _a = url.split("/"), protocol = _a[0], host = _a[2]; var a = host.split(":")[0].split(".").reverse(); return { domain: a.length >= 3 && a[0].length === 2 && a[1].length === 2 ? "".concat(a[2], ".").concat(a[1], ".").concat(a[0]) : a.length >= 2 ? "".concat(a[1], ".").concat(a[0]) : undefined, origin: protocol && host ? "".concat(protocol, "//").concat(host) : undefined }; } return {}; } exports.parseUrl = parseUrl; //# sourceMappingURL=parse.js.map