Skip to content

Commit

Permalink
feat: update util core is to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr.Mao committed Dec 9, 2023
1 parent d31008d commit 3b50f2a
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions packages/util-core/src/is/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
declare const WXEnvironment: any

export const isBrowser = typeof window !== 'undefined'
export const isBrowser = () => typeof window !== 'undefined'

export const isWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform
export const isWeex = () => typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform

export const weexPlatform = isWeex && WXEnvironment.platform.toLowerCase()
export const weexPlatform = () => isWeex() && WXEnvironment.platform.toLowerCase()

export const UA = isBrowser && window.navigator.userAgent.toLowerCase()
export const UA = () => (isBrowser() && window.navigator.userAgent.toLowerCase()) || ''

export const isIE = UA && /msie|trident/.test(UA)
export const isIE = () => UA() && /msie|trident/.test(UA())

export const isIE9 = UA && UA.indexOf('msie 9.0') > 0
export const isIE9 = () => UA() && UA().indexOf('msie 9.0') > 0

export const isIE11 = isBrowser && navigator.userAgent.includes('Trident') && navigator.userAgent.includes('rv:11.0')
export const isIE11 = () => isBrowser() && navigator.userAgent.includes('Trident') && navigator.userAgent.includes('rv:11.0')

export const isEdge = UA && UA.indexOf('edge/') > 0
export const isEdge = () => UA() && UA().indexOf('edge/') > 0

export const isAndroid = (UA && UA.indexOf('android') > 0) || weexPlatform === 'android'
export const isAndroid = () => (UA() && UA().indexOf('android') > 0) || weexPlatform() === 'android'

export const isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || weexPlatform === 'ios'
export const isIOS = () => (UA() && /iphone|ipad|ipod|ios/.test(UA())) || weexPlatform() === 'ios'

export const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge
export const isChrome = () => UA() && /chrome\/\d+/.test(UA()) && !isEdge()

export const isPhantomJS = UA && /phantomjs/.test(UA)
export const isPhantomJS = () => UA() && /phantomjs/.test(UA())

export const isFF = typeof UA == 'string' && UA.match(/firefox\/(\d+)/)
export const isFF = () => typeof UA() === 'string' && UA().match(/firefox\/(\d+)/)

export const isMobile = isBrowser && navigator.userAgent.toLowerCase().includes('mobile')
export const isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes('mobile')

0 comments on commit 3b50f2a

Please sign in to comment.