import { envVar } from "../enums/index" ; declare let Page ; declare let Component ; export const ismp = typeof Page === "function" && typeof Component === "function" ; export function getEnv ( ) { if ( ismp ) { return envVar . wx ; } else { return envVar . web ; } } export function processCss ( styles ) { let css = "" ; for ( const prop in styles ) { css += `${ prop }: ${ styles [ prop ] };` ; if ( styles [ prop ] === "flex" ) { css += "display: -ms-flexbox;" ; } } return css ; } export function validateUrl ( url , type = "http" ) { if ( type === "http" ) { return /^(http|https):\/\/.*/i . test ( url ) ; } else if ( type === "websocket" ) { return /^(ws|wss):\/\/.*/i . test ( url ) ; } return undefined ; } export function getType ( data ) { return Object . prototype . toString . call ( data ) . slice ( 8 , - 1 ) ; } export function convertObjectValueToString ( object ) { return Object . keys ( object ) . reduce ( ( ret , key ) => { if ( typeof object [ key ] === "string" ) { ret [ key ] = object [ key ] ; } else if ( typeof object [ key ] === "number" ) { ret [ key ] = object [ key ] + "" ; } else { ret [ key ] = Object . prototype . toString . apply ( object [ key ] ) ; } return ret ; } , { } ) ; } export function addQueryStringToUrl ( url , data ) { if ( typeof url === "string" && typeof data === "object" && data !== null && Object . keys ( data ) . length > 0 ) { const parts = url . split ( "?" ) ; const path = parts [ 0 ] ; const query = ( parts [ 1 ] || "" ) . split ( "&" ) . reduce ( ( pre , cur ) => { if ( typeof cur === "string" && cur . length > 0 ) { const parts = cur . split ( "=" ) ; const key = parts [ 0 ] ; const value = parts [ 1 ] ; pre [ key ] = value ; } return pre ; } , { } ) ; const encodedData = Object . keys ( data ) . reduce ( ( ret , key ) => { if ( typeof data [ key ] === "object" ) { ret [ encodeURIComponent ( key ) ] = encodeURIComponent ( JSON . stringify ( data [ key ] ) ) ; } else { ret [ encodeURIComponent ( key ) ] = encodeURIComponent ( data [ key ] ) ; } return ret ; } , { } ) ; return path + "?" + urlEncodeFormData ( Object . assign ( query , encodedData ) ) ; } else { return url ; } } export function urlEncodeFormData ( data , needEncode = false ) { if ( typeof data !== "object" ) { return data ; } const dataArray = [ ] ; for ( const k in data ) { if ( data . hasOwnProperty ( k ) ) { if ( needEncode ) { try { dataArray . push ( `${ encodeURIComponent ( k ) }=${ encodeURIComponent ( data [ k ] ) }` ) ; } catch ( e ) { dataArray . push ( `${ k }=${ data [ k ] }` ) ; } } else { dataArray . push ( `${ k }=${ data [ k ] }` ) ; } } } return dataArray . join ( "&" ) ; } export function bindApis ( ) { }