From https://github.com/sfioritto/charlie.js