webforai
Version:
A library that provides a web interface for AI
72 lines (71 loc) • 2.37 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var hast_utils_exports = {};
__export(hast_utils_exports, {
getLangFromHast: () => getLangFromHast,
getLangFromStr: () => getLangFromStr,
getUrlFromHast: () => getUrlFromHast
});
module.exports = __toCommonJS(hast_utils_exports);
var import_hast_util_select = require("hast-util-select");
const getLangFromHast = (node) => {
const html = (0, import_hast_util_select.select)("html", node);
if (html && typeof html.properties.lang === "string") {
return html.properties.lang;
}
if (node.type !== "element") {
return;
}
const element = node;
if (element.tagName !== "html") {
return;
}
const langAttr = element.properties.lang || element.properties["xml:lang"];
if (langAttr) {
return langAttr;
}
return void 0;
};
const getLangFromStr = (str) => {
const match = str.match(/lang=["']([^"']+)["']/);
if (match) {
return match[1];
}
return void 0;
};
const getUrlFromHast = (node) => {
if (node.type !== "element") {
return void 0;
}
const metaTagAttributes = ["og:url", "twitter:url"];
const metaTags = (0, import_hast_util_select.selectAll)("meta", node);
for (const meta of metaTags) {
const property = meta.properties.property || meta.properties.name;
if (typeof property === "string" && metaTagAttributes.includes(property)) {
return typeof meta.properties.content === "string" ? meta.properties.content : void 0;
}
}
return void 0;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getLangFromHast,
getLangFromStr,
getUrlFromHast
});