Skip to content

Commit

Permalink
feat(helper): add env helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Nov 18, 2024
1 parent 99fe6f8 commit 13daf7e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tools/helper/src/client/utils/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export const checkIsMobile = (ua: string): boolean =>
/\b(?:Android|iPhone)/i.test(ua)

export const checkIsChromeWebView = (ua: string): boolean =>
/ wv\).+(chrome)\/([\w.]+)/i.test(ua)

export const checkIsSafariMobile = (ua: string): boolean =>
/version\/([\w.]+) .*mobile\/\w+ (safari)/i.test(ua)

export const checkIsSafari = (ua: string): boolean =>
/version\/([\w.]+) .*(mobile ?safari|safari)/i.test(ua)

export const checkIsiPhone = (ua: string): boolean =>
/\((ip(?:hone|od)[\w ]*);/i.test(ua)

export const checkIsiPad = (ua: string): boolean =>
[
/\((ipad);[-\w),; ]+apple/i,
/applecoremedia\/[\w.]+ \((ipad)/i,
/\b(ipad)\d\d?,\d\d?[;\]].+ios/i,
].some((item) => item.test(ua))

export const checkIsWindows = (ua: string): boolean =>
[
/microsoft (windows) (vista|xp)/i,
/(win(?=3|9|n)|win 9x )([nt\d.]+)/i,
/(windows) nt 6\.2; (arm)/i,
/(windows (?:phone(?: os)?|mobile))[/ ]?([\d.\w ]*)/i,
/(windows)[/ ]?([ntce\d. ]+\w)(?!.+xbox)/i,
].some((item) => item.test(ua))

export const checkIsIOS = (ua: string): boolean =>
[
/ip[honead]{2,4}\b(?:.*os ([\w]+) like mac|; opera)/i,
/cfnetwork\/.+darwin/i,
].some((item) => item.test(ua))

export const checkIsMacOS = (ua: string): boolean =>
[/(mac os x) ?([\w. ]*)/i, /(macintosh|mac_powerpc\b)(?!.+haiku)/i].some(
(item) => item.test(ua),
)
1 change: 1 addition & 0 deletions tools/helper/src/client/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './data.js'
export * from './env.js'
export * from './getDarkmode.js'
export * from './getHeaders.js'
export * from './hasGlobalComponent.js'
Expand Down

0 comments on commit 13daf7e

Please sign in to comment.