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.
28 lines • 1.13 kB
JavaScript
import { Controller } from "./controller.js";
import { merge, unpatch } from "./lib/index.js";
import { unwrap } from "./lib/unwrap.js";
export function extractSync(state) {
const controller = new Controller(state);
if (controller.state.unpatch) {
unpatch(controller.state.unpatch);
controller.log(`UNPATCHED ${controller.state.unpatch.join(", ")}`);
}
try {
for (const action of controller.state.actions) {
if (action.hasOwnProperty("select")) {
const data = controller.select(action.select);
controller.state.data = merge(controller.state.data, data);
}
else if (action.hasOwnProperty("transform")) {
controller.transform(action.transform);
}
}
}
catch (err) {
controller.appendError("fatal-error", err instanceof Error ? err.message : JSON.stringify(err), 0, err instanceof Error ? err.stack : undefined);
}
if (state.unwrap)
controller.state.data = unwrap(controller.state.data);
return controller.state;
}
//# sourceMappingURL=extract-sync.js.map