Make module AMD compatible

Hi,

Wanted to use your module in a browser project using AMD, but found that since it uses node style requires that it didn't work. I've modified it to detect what require loader is available and support that.