1.0.2 • Published 4 years ago

safe-window v1.0.2

Weekly downloads
2,588
License
ISC
Repository
github
Last release
4 years ago

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'
1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago