@realfavicongenerator/check-favicon
Version:
Check the favicon of a website
40 lines (39 loc) • 2.03 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkFavicon = exports.extractPageTitle = void 0;
const desktop_1 = require("./desktop/desktop");
const helper_1 = require("./helper");
const touch_icon_1 = require("./touch-icon");
const web_app_manifest_1 = require("./web-app-manifest");
const extractPageTitle = (head) => {
var _a;
if (!head) {
return undefined;
}
const titleElement = head.querySelector('title');
const title = (_a = titleElement === null || titleElement === void 0 ? void 0 : titleElement.text) === null || _a === void 0 ? void 0 : _a.trim();
return title || undefined;
};
exports.extractPageTitle = extractPageTitle;
const checkFavicon = (baseUrl_1, head_1, ...args_1) => __awaiter(void 0, [baseUrl_1, head_1, ...args_1], void 0, function* (baseUrl, head, fetcher = helper_1.fetchFetcher) {
const desktop = yield (0, desktop_1.checkDesktopFavicon)(baseUrl, head, fetcher);
const touchIcon = yield (0, touch_icon_1.checkTouchIcon)(baseUrl, head, fetcher);
const webAppManifest = yield (0, web_app_manifest_1.checkWebAppManifest)(baseUrl, head, fetcher);
const pageTitle = (0, exports.extractPageTitle)(head);
return {
pageTitle,
desktop,
touchIcon,
webAppManifest
};
});
exports.checkFavicon = checkFavicon;