Ports common Python functions to JavaScript