use window instead of this

to fix compatibility with browserify or webpack
add browser environment setting
add main field

to allow publishing to npm