convert to javascript: class Highliter
{
    protected $where_search;
    protected $any_patterns;

    public function __construct(string $where_search, array $any_patterns) {
        $this->where_search = $where_search;
        $this->any_patterns = $any_patterns;
    }


    protected function search_for_replace() {
        $where_search = json_encode($this->where_search);
        $where_search = json_decode($where_search);
        $where_search = str_replace("\n"," ",$where_search);
        //NewLogger::info(json_encode($where_search));
        $ready_all_patterns = array();
        $ready_for_replace_style = array();
        
        NewLogger::info(json_encode(["any_patterns", $this->any_patterns]));
        NewLogger::info(json_encode(["where_search", $where_search]));
        
        foreach ($this->any_patterns as $key => $value) {
            if (preg_match_all($key, $where_search, $matches, PREG_SET_ORDER)) {
                NewLogger::info(json_encode($matches));
                foreach ($matches as $elem) {
                    $for_replace = $elem[0];
                    $what_search_for_replace = $elem[0];
                    $replace_style = "<span class='" . $value . "'>" . $for_replace . "</span>";
                        
                    //NewLogger::info(json_encode($what_search_for_replace));
                    if (!in_array($what_search_for_replace, $ready_all_patterns)) {
                        array_push($ready_all_patterns, $what_search_for_replace);
                        array_push($ready_for_replace_style, $replace_style);
                    }
                }
            }
        }
        //NewLogger::info(json_encode($ready_all_patterns));
        //NewLogger::info(json_encode($ready_for_replace_style));
        $res = array();
        $res["ready_all_patterns"] = $ready_all_patterns;
        $res["ready_for_replace_style"] = $ready_for_replace_style;
        $res["where_search"] = $where_search;
        //NewLogger::info("search_for_replace(), " . json_encode($res));
        return $res;
    }

    public function string_replace_run() {
        $data = $this->search_for_replace();
        //NewLogger::info("string_replace_run() ," . json_encode($data));
        $res = str_replace($data["ready_all_patterns"], $data["ready_for_replace_style"], $data["where_search"]);
        return $res;
    }

    public function regex_replace_run() {
        $data = $this->search_for_replace();
        $ready_regex_patterns = array();
        foreach ($data["ready_all_patterns"] as $pattern) {
            $regex_pattern = '/\b' . $pattern . '\b/';
            array_push($ready_regex_patterns, $regex_pattern);
        }
        NewLogger::info(json_encode(["ready_regex_patterns: ", json_encode($ready_regex_patterns)]));
        $res = preg_replace($ready_regex_patterns, $data["ready_for_replace_style"], $data["where_search"]);
        NewLogger::info(json_encode(["$res", $res]));
        return $res;
    }
    
    public function regex_replace_run_lookbehind() {
        $data = $this->search_for_replace();
        $ready_regex_patterns = array();
        $new_style = array();
        foreach ($data["ready_for_replace_style"] as $pattern) {
			if (str_contains($pattern, '$')) {
			    $pattern = str_replace(['$', '</span>',], ['\\$', ''], $pattern);
			    $pattern = $pattern . '</span>';
			    
		    }
		    
		    array_push($new_style, $pattern);

		}
        $data["ready_for_replace_style"] = $new_style;
        
        foreach ($data["ready_all_patterns"] as $pattern) {


            if (str_contains($pattern, '$')) {
			    $pattern = str_replace(['$', '.', ], ['\\$', '\.',], $pattern);
                $regex_pattern = '#(?<!par\s\s\svalue\s|par\s\svalue\s|par\svalue\s|par\s\s\svalue\s\s|par\s\svalue\s\s|par\svalue\s\s)' . $pattern . '#';
		    }
            //elseif
            
            array_push($ready_regex_patterns, $regex_pattern);
        }
        //NewLogger::info(json_encode($ready_regex_patterns));
        $res = preg_replace($ready_regex_patterns, $data["ready_for_replace_style"], $data["where_search"]);
        return $res;
    }
}