protected function escapeJS(): string
    {
        $value = $this->validateEncoding();
        $value = htmlspecialchars($value, ENT_COMPAT);

        $value = preg_replace('/&#(x)?0*(?(1)27|39);?/i', '\'', stripslashes($value));
        $value = str_replace("\r", '', $value);

        return str_replace("\n", '\\n', addslashes($value));
    }