JavaScript implementation of Homogenius