import Taro from '@tarojs/taro' import { PropsWithChildren } from 'react' export const noop = () => {} export function wrapProps(props: PropsWithChildren) { let { adpId, width, onEmitOpenMiniProgram = noop, onError = noop, onLoad = noop, onClose = noop } = props if (!width) { const windowInfo = Taro.getWindowInfo() width = windowInfo?.windowWidth } return { adpId, width, onEmitOpenMiniProgram, onError, onLoad, onClose } } export function generateUUID () { let d = new Date().getTime(); let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { let r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c === 'x' ? r : (r & 0x7) | 0x8).toString(16); }); return uuid; } export function parseURLParams(url) { const search = {} let hash = '' let href = '' url.replace(/([^?=&#]+)=([^?=&#]+)/g, (_, key, value) => search[key] = value) url.replace(/#([^?=&#]+)/g, (_, h) => hash = h) href = url.split(/[\?|#]/)[0] return { href, search, hash } } export function queryURLParams(params) { let search = Object.entries(params).reduce((cac, cur) => { const [key, val] = cur return cac += `${key}=${val}&` }, '') return search.slice(0, -1) }