The official JavaScript port of Petrovich.