Ported Ruby code to CoffeeScript and Node.Js.