ayakashi
Version:
The next generation web scraping framework
33 lines (32 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.domQuery = void 0;
const walking_1 = require("./walking");
function domQuery(query, options = {}) {
let env;
if (options.env) {
env = options.env;
}
else if (typeof window !== "undefined") {
env = window;
}
else {
throw new Error("No suitable env found");
}
if (!query || typeof query !== "object") {
throw new Error("Query format is invalid. Learn more at https://ayakashi-io.github.io/docs/guide/querying-with-domql.html");
}
if (query.where && typeof query.where !== "object") {
throw new Error("Query format is invalid. Learn more at https://ayakashi-io.github.io/docs/guide/querying-with-domql.html");
}
if (query.where && typeof query.where === "object" && Object.keys(query.where).length === 0) {
throw new Error("Query format is invalid. Learn more at https://ayakashi-io.github.io/docs/guide/querying-with-domql.html");
}
if (options.recursive === false) {
return walking_1.tagWalk(env, query, options.scope || env.document.body);
}
else {
return walking_1.domWalk(env, query, options.scope || env.document.body);
}
}
exports.domQuery = domQuery;