JS port from Ruby