added support for commonjs modules

Hey there,

This PR adds support for commonjs modules, browserify etc, sometimes used in environments where the 'window' object isn't available, but JSON is.

Steve
:+1: can confirm that this is necessary to get this working.