Ported 'pipe' to native JavaScript