2025-04-19 15:38:48 +08:00

60 lines
2.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLocalStorage = exports.getLocalStorageOrThrow = exports.getCrypto = exports.getCryptoOrThrow = exports.getLocation = exports.getLocationOrThrow = exports.getNavigator = exports.getNavigatorOrThrow = exports.getDocument = exports.getDocumentOrThrow = exports.getFromWindowOrThrow = exports.getFromWindow = void 0;
function getFromWindow(name) {
let res = undefined;
if (typeof window !== "undefined" && typeof window[name] !== "undefined") {
res = window[name];
}
return res;
}
exports.getFromWindow = getFromWindow;
function getFromWindowOrThrow(name) {
const res = getFromWindow(name);
if (!res) {
throw new Error(`${name} is not defined in Window`);
}
return res;
}
exports.getFromWindowOrThrow = getFromWindowOrThrow;
function getDocumentOrThrow() {
return getFromWindowOrThrow("document");
}
exports.getDocumentOrThrow = getDocumentOrThrow;
function getDocument() {
return getFromWindow("document");
}
exports.getDocument = getDocument;
function getNavigatorOrThrow() {
return getFromWindowOrThrow("navigator");
}
exports.getNavigatorOrThrow = getNavigatorOrThrow;
function getNavigator() {
return getFromWindow("navigator");
}
exports.getNavigator = getNavigator;
function getLocationOrThrow() {
return getFromWindowOrThrow("location");
}
exports.getLocationOrThrow = getLocationOrThrow;
function getLocation() {
return getFromWindow("location");
}
exports.getLocation = getLocation;
function getCryptoOrThrow() {
return getFromWindowOrThrow("crypto");
}
exports.getCryptoOrThrow = getCryptoOrThrow;
function getCrypto() {
return getFromWindow("crypto");
}
exports.getCrypto = getCrypto;
function getLocalStorageOrThrow() {
return getFromWindowOrThrow("localStorage");
}
exports.getLocalStorageOrThrow = getLocalStorageOrThrow;
function getLocalStorage() {
return getFromWindow("localStorage");
}
exports.getLocalStorage = getLocalStorage;
//# sourceMappingURL=index.js.map