Safe Type

Safe access to browser globals (window, document, navigator, Element, File, etc.) without throwing in Node or unsupported environments.

Usage

  1. You can import in your js file es6 (modules,vue,react,...)
import { WINDOW } from 'helping-js/core/safe-types'

console.log(WINDOW) //{all data in window object OR empty object(if not support window)}
  1. You can import in your js file es5 (nodejs)
var { WINDOW } = require('helping-js/core/safe-types')

console.log(WINDOW) // {all data in window object OR empty object (if window is not supported)}
  1. You can use from CDN (ESM only)
import { WINDOW } from 'https://unpkg.com/helping-js/core/safe-types.js'

console.log(WINDOW) // {all data in window object OR empty object (if window is not supported)}

Options

FunctionsDescription
WINDOWsafe call to window object (doesn't throw an error if the window doesn't exist)
DOCUMENTsafe call to document object (doesn't throw an error if the document doesn't exist)
NAVIGATORsafe call to navigator object (doesn't throw an error if the navigator doesn't exist)
USER_AGENTsafe call to navigator.userAgent object (doesn't throw an error if the userAgent doesn't exist)
Elementsafe call to Element object (doesn't throw an error if the window doesn't exist)
HTMLElementsafe call to HTMLElement object (doesn't throw an error if the window doesn't exist)
SVGElementsafe call to SVGElement object (doesn't throw an error if the window doesn't exist)
Filesafe call to File object (doesn't throw an error if the window doesn't exist)
Last Updated:
Contributors: parsa jiravand, parsajiravand