Added the JS implementation and unit tests missing from the last commit.