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.
160 lines (157 loc) • 4.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isAndroid = isAndroid;
exports.isArray = isArray;
exports.isBlob = isBlob;
exports.isBoolean = isBoolean;
exports.isClassComponent = void 0;
exports.isColor = isColor;
exports.isDOMElement = void 0;
exports.isEmail = isEmail;
exports.isEmptyObject = isEmptyObject;
exports.isEmptyReactNode = isEmptyReactNode;
exports.isExist = isExist;
exports.isFile = isFile;
exports.isFunction = isFunction;
exports.isIOS = isIOS;
exports.isImageLinkAvailable = isImageLinkAvailable;
exports.isLink = void 0;
exports.isMobile = isMobile;
exports.isNull = isNull;
exports.isNullOrUndefined = isNullOrUndefined;
exports.isNumber = isNumber;
exports.isObject = isObject;
exports.isPromise = isPromise;
exports.isReactComponent = void 0;
exports.isRegExp = isRegExp;
exports.isSmsCode = isSmsCode;
exports.isString = isString;
exports.isUndefined = isUndefined;
exports.isUsPhoneNumber = isUsPhoneNumber;
exports.isWindow = isWindow;
var _react = require("react");
var _canUseDom = require("./can-use-dom");
var _dom = require("./dom");
const opt = Object.prototype.toString;
function isArray(obj) {
return opt.call(obj) === "[object Array]";
}
function isObject(obj) {
return opt.call(obj) === "[object Object]";
}
function isString(obj) {
return opt.call(obj) === "[object String]";
}
function isNumber(obj) {
return opt.call(obj) === "[object Number]" && obj === obj;
}
function isRegExp(obj) {
return opt.call(obj) === "[object RegExp]";
}
function isFile(obj) {
return opt.call(obj) === "[object File]";
}
function isBlob(obj) {
return opt.call(obj) === "[object Blob]";
}
function isHex(color) {
return /^#[a-fA-F0-9]{3}$|#[a-fA-F0-9]{6}$/.test(color);
}
function isRgb(color) {
return /^rgb\((\s*\d+\s*,?){3}\)$/.test(color);
}
function isRgba(color) {
return /^rgba\((\s*\d+\s*,\s*){3}\s*\d(\.\d+)?\s*\)$/.test(color);
}
function isColor(color) {
return isHex(color) || isRgb(color) || isRgba(color);
}
function isUndefined(obj) {
return obj === undefined;
}
function isNull(obj) {
return obj === null;
}
function isNullOrUndefined(obj) {
return obj === null || obj === undefined;
}
function isFunction(obj) {
return typeof obj === "function";
}
function isEmptyObject(obj) {
return isObject(obj) && Object.keys(obj).length === 0;
}
function isEmptyReactNode(content, trim) {
if (content === null || content === undefined || content === false) {
return true;
}
if (typeof content === "string" && (trim ? content.trim() === "" : content === "")) {
return true;
}
return false;
}
function isExist(obj) {
return obj || obj === 0;
}
function isWindow(el) {
return el === window;
}
function isBoolean(value) {
return typeof value === "boolean";
}
const isReactComponent = element => {
return element && /*#__PURE__*/(0, _react.isValidElement)(element) && typeof element.type === "function";
};
exports.isReactComponent = isReactComponent;
const isClassComponent = element => {
var _element$type$prototy;
return isReactComponent(element) && !!((_element$type$prototy = element.type.prototype) !== null && _element$type$prototy !== void 0 && _element$type$prototy.isReactComponent);
};
// element 是合成的 dom 元素或者字符串,数字等
exports.isClassComponent = isClassComponent;
const isDOMElement = element => {
return /*#__PURE__*/(0, _react.isValidElement)(element) && typeof element.type === "string";
};
exports.isDOMElement = isDOMElement;
const isLink = text => {
return isString(text) && (text.startsWith("http") || text.startsWith("https"));
};
exports.isLink = isLink;
async function isImageLinkAvailable(url) {
return new Promise(resolve => {
const img = new Image();
img.onload = () => resolve(true);
img.onerror = () => resolve(false);
img.src = url;
});
}
function isMobile() {
return _dom.clientWindow && /Android|iPhone|iPad|iPod|Windows Phone|BlackBerry|Mobile/i.test(_dom.clientWindow === null || _dom.clientWindow === void 0 ? void 0 : _dom.clientWindow.navigator.userAgent);
}
function isEmail(email) {
const emailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
return emailReg.test(email);
}
function isSmsCode(code) {
const codeReg = /\d{6}/;
return codeReg.test(code);
}
function isUsPhoneNumber(phone) {
const phoneRegex = /^[2-9]\d{2}[2-9]\d{6}$/;
return phoneRegex.test(phone);
}
function isPromise(obj) {
return !!obj && typeof obj === "object" && typeof obj.then === "function";
}
/**
* 判断是否为Android设备
* @returns 是否为Android设备
*/
function isAndroid() {
return _canUseDom.canUseDom ? /android/.test(navigator.userAgent.toLowerCase()) : false;
}
function isIOS() {
return _canUseDom.canUseDom ? /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()) : false;
}