Skip to content

Instantly share code, notes, and snippets.

@kurt-liao
Created October 12, 2022 07:04
Show Gist options
  • Save kurt-liao/4eb87ee5b1b1a01b4cfc3d25a8493c65 to your computer and use it in GitHub Desktop.
Save kurt-liao/4eb87ee5b1b1a01b4cfc3d25a8493c65 to your computer and use it in GitHub Desktop.
常用的 helper methods
/**
* 判斷變數值是否是 Primitive
*/
const isPrimitive = (val: any) => {
if (val == null) return true
if (typeof val === 'object' || typeof val === 'function') return false
return true
}
/**
* 判斷網頁是否是用 webview 開啟的
*/
const isWebView = () => {
const userAgent = window.navigator.userAgent.toLowerCase()
const safari = /safari/.test(userAgent)
const ios = /iphone|ipod|ipad/.test(userAgent)
return typeof window.Android !== 'undefined' || (ios && !safari)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment