safe-window
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

safe-window

npm version

A utility for safely getting properties from the window object in projects that render on both the server and the client.

Installation

npm i -S safe-window

Usage

import safeWindow from 'safe-window';

window.foo = {bar: 'baz'}
safeWindow('foo.bar')
=> 'baz'
Works with arrays
window.foo = [{bar: 'baz'}]
safeWindow('foo.0.bar')
=> 'baz'
Window doesn't exist (server side)
safeWindow('foo.bar')
=> null

// With default
safeWindow('foo.bar', 'qux')
=> 'qux'

Readme

Keywords

none

Package Sidebar

Install

npm i safe-window

Weekly Downloads

674

Version

1.0.2

License

ISC

Unpacked Size

2.9 kB

Total Files

5

Last publish

Collaborators

  • chardos