UNPKG

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