Port helper functions to JavaScript