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.
84 lines (83 loc) • 2.3 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') {
return window.location.search ?? '';
}
};
}();
const open = exports.open = function () {
if (isServerRendering) {
return NOOP;
}
return function (url, target = '_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);
};
}();