rewrite to js