Skip to content

⬅️ Back to Table of Contents

📄 is

📊 Analysis Summary

Metric Count
🔧 Functions 11
📊 Variables & Constants 3

📚 Table of Contents

🛠️ File Location:

📂 packages/shared/utils/is.ts

Variables & Constants

Name Type Kind Value Exported
isClient boolean const typeof window !== 'undefined' && typeof document !== 'undefined'
isWorker boolean const typeof WorkerGlobalScope !== 'undefined' && globalThis instanceof WorkerGloba...
toString () => string const Object.prototype.toString

Functions

isDef(val: T): val is T

Parameters:

  • val T

Returns: val is T

Code
<T = any>(val?: T): val is T => typeof val !== 'undefined'

notNullish(val: T | null | undefined): val is T

Parameters:

  • val T | null | undefined

Returns: val is T

Code
<T = any>(val?: T | null | undefined): val is T => val != null

assert(condition: boolean, infos: any[]): void

Parameters:

  • condition boolean
  • infos any[]

Returns: void

Calls:

  • console.warn
Code
(condition: boolean, ...infos: any[]) => {
  if (!condition)
    console.warn(...infos)
}

isObject(val: any): val is object

Parameters:

  • val any

Returns: val is object

Code
(val: any): val is object =>
  toString.call(val) === '[object Object]'

now(): number

Returns: number

Calls:

  • Date.now
Code
() => Date.now()

timestamp(): number

Returns: number

Code
() => +Date.now()

clamp(n: number, min: number, max: number): number

Parameters:

  • n number
  • min number
  • max number

Returns: number

Calls:

  • Math.min
Code
(n: number, min: number, max: number) => Math.min(max, Math.max(min, n))

noop(): void

Returns: void

Code
() => {}

rand(min: number, max: number): number

Parameters:

  • min number
  • max number

Returns: number

Calls:

  • Math.ceil
  • Math.floor
  • Math.random
Code
(min: number, max: number) => {
  min = Math.ceil(min)
  max = Math.floor(max)
  return Math.floor(Math.random() * (max - min + 1)) + min
}

hasOwn(val: T, key: K): key is K

Parameters:

  • val T
  • key K

Returns: key is K

Calls:

  • Object.hasOwn
Code
<T extends object, K extends keyof T>(val: T, key: K): key is K => Object.hasOwn(val, key)

getIsIOS(): boolean

Returns: boolean

Calls:

  • /iP(?:ad|hone|od)/.test
  • /iPad|Macintosh/.test

Internal Comments:

// The new iPad Pro Gen3 does not identify itself as iPad, but as Macintosh.
// https://github.com/vueuse/vueuse/issues/3577

Code
function getIsIOS(): boolean {
  return isClient && !!window?.navigator?.userAgent && (
    (/iP(?:ad|hone|od)/.test(window.navigator.userAgent))
    // The new iPad Pro Gen3 does not identify itself as iPad, but as Macintosh.
    // https://github.com/vueuse/vueuse/issues/3577
    || (window?.navigator?.maxTouchPoints > 2 && /iPad|Macintosh/.test(window?.navigator.userAgent))
  )
}

Generated by Syntax Scribe