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.
80 lines • 2.15 kB
JavaScript
var NOOP = function NOOP() {};
export var isServerRendering = function () {
try {
return !(typeof window !== 'undefined' && document !== undefined);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return true;
}
}();
export var clientWindow = function () {
if (isServerRendering) {
return undefined;
}
return window;
}();
export var clientDocument = function () {
if (isServerRendering) {
return undefined;
}
return document;
}();
export var localStorage = function () {
if (isServerRendering) {
return NOOP;
}
return window.localStorage;
}();
export var 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 : '';
}
};
}();
export var open = function () {
if (isServerRendering) {
return NOOP;
}
return function (url) {
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '_blank';
window.open(url, target);
};
}();
export var 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);
};
}();
export var 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);
};
}();