Something went wrong on our end
Select Git revision
target-jsdoc-build.mk
-
Volker Schukai authoredVolker Schukai authored
util.mjs 6.76 KiB
/**
* Copyright schukai GmbH and contributors 2023. All Rights Reserved.
* Node module: @schukai/monster
* This file is licensed under the AGPLv3 License.
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
*/
import { getGlobal } from "../types/global.mjs";
import { validateString } from "../types/validate.mjs";
export { getDocument, getWindow, getDocumentFragmentFromString, findElementWithIdUpwards, getContainingDocument };
/**
* This method fetches the document object
*
* In nodejs this functionality can be performed with [jsdom](https://www.npmjs.com/package/jsdom).
*
* ```
* import {JSDOM} from "jsdom"
* if (typeof window !== "object") {
* const {window} = new JSDOM('', {
* url: 'http://example.com/',
* pretendToBeVisual: true
* });
*
* [
* 'self',
* 'document',
* 'Document',
* 'Node',
* 'Element',
* 'HTMLElement',
* 'DocumentFragment',
* 'DOMParser',
* 'XMLSerializer',
* 'NodeFilter',
* 'InputEvent',
* 'CustomEvent'
* ].forEach(key => (getGlobal()[key] = window[key]));
* }
* ```
*
* @returns {object}
* @license AGPLv3
* @since 1.6.0
* @copyright schukai GmbH
* @memberOf Monster.DOM
* @throws {Error} not supported environment
*/
function getDocument() {
let document = getGlobal()?.["document"];
if (typeof document !== "object") {
throw new Error("not supported environment");
}
return document;
}
/**
* This method fetches the window object
*
* In nodejs this functionality can be performed with [jsdom](https://www.npmjs.com/package/jsdom).
*
* ```
* import {JSDOM} from "jsdom"
* if (typeof window !== "object") {
* const {window} = new JSDOM('', {
* url: 'http://example.com/',
* pretendToBeVisual: true
* });