public static function js($string)
    {
        // escape all non-alphanumeric characters
        // into their \xHH or \uHHHH representations
        $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', function ($matches) {
            $char = $matches[0];
            // \xHH
            if (!isset($char[1])) {
                return '\\x' . strtoupper(substr('00' . bin2hex($char), -2));
            }
            // \uHHHH
            $char = iconv('UTF-8', 'UTF-16BE', $char);
            return '\\u' . strtoupper(substr('0000'.bin2hex($char), -4));
        }, $string);

        return $string;
    }