Skip to main content
Version: 1.0.2

is.iphone

is.iphone(target: unknown)โ€‹

The is.iphone method is used to check if the current device is an iPhone or not. It returns true if the device is an iPhone and false otherwise. The method uses the user agent string of the browser to determine if the device is an iPhone.

Specificationโ€‹

  • Target argument: optional.
  • Return: boolean.

Informationโ€‹

  • Unit tests: โœ…

Examplesโ€‹

is.iphone() // true if the command is executed in a browser running on the iPhone
is.iphone('Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Mobile/15E148 Safari/604.1') // true

// Alternative
IsConfig.state.userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Mobile/15E148 Safari/604.1';
is.iphone() // true

is.iphone(769) // false
is.iphone(false) // false
is.iphone(new Boolean(0)) // false
is.iphone(new Boolean()) // false
is.iphone(0) // false
is.iphone('') // false
is.iphone({}) // false
is.iphone([]) // false
// And all other known types will return false

Reversal boolean resultโ€‹

is.not.iphone() // false if the command is executed in a browser running on the iPhone
is.not.iphone('Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Mobile/15E148 Safari/604.1') // false

// Alternative
IsConfig.state.userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Mobile/15E148 Safari/604.1';
is.not.iphone() // false

is.not.iphone(769) // true
is.not.iphone(false) // true
is.not.iphone(new Boolean(0)) // true
is.not.iphone(new Boolean()) // true
is.not.iphone(0) // true
is.not.iphone('') // true
is.not.iphone({}) // true
is.not.iphone([]) // true
// And all other known types will return true