Ports common PHP functions to JavaScript