pay-sdk-react
Version:
A cross-platform payment SDK for React, supporting Alipay, WeChat Pay, PayPal, Stripe, Payssion, and Airwallex, compatible with H5, PC, and App environments.
86 lines (85 loc) • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.open = exports.on = exports.off = exports.location = exports.localStorage = exports.isServerRendering = exports.clientWindow = exports.clientDocument = void 0;
const NOOP = () => {};
const isServerRendering = exports.isServerRendering = function () {
try {
return !(typeof window !== "undefined" && document !== undefined);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return true;
}
}();
const clientWindow = exports.clientWindow = function () {
if (isServerRendering) {
return undefined;
}
return window;
}();
const clientDocument = exports.clientDocument = function () {
if (isServerRendering) {
return undefined;
}
return document;
}();
const localStorage = exports.localStorage = function () {
if (isServerRendering) {
return NOOP;
}
return window.localStorage;
}();
const location = exports.location = function () {
if (isServerRendering) {
return NOOP;
}
return function (action, value) {
if (action === "replace") {
window.location.replace(value);
}
if (action === "href") {
window.location.href = value;
}
if (action === "reload") {
window.location.reload();
}
if (action === "protocol") {
return window.location.protocol;
}
if (action === "host") {
return window.location.host;
}
if (action === "search") {
var _window$location$sear;
return (_window$location$sear = window.location.search) !== null && _window$location$sear !== void 0 ? _window$location$sear : "";
}
};
}();
const open = exports.open = function () {
if (isServerRendering) {
return NOOP;
}
return function (url) {
let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "_blank";
window.open(url, target);
};
}();
const on = exports.on = function () {
if (isServerRendering) {
return NOOP;
}
return function (element, event, handler, options) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
element && element.addEventListener(event, handler, options || false);
};
}();
const off = exports.off = function () {
if (isServerRendering) {
return NOOP;
}
return function (element, event, handler, options) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
element && element.removeEventListener(event, handler, options || false);
};
}();