Giải mã ký tự đặc biệt trong JavaScript

Mã hóa văn bản thay thế các ký tự đặc biệt HTML (_______36) cộng với các phạm vi ký tự khác tùy thuộc vào giá trị tùy chọn

import {encode} from 'html-entities';

encode('< > " \' & © ∆');
// -> '< > " ' & © ∆'

encode('< ©', {mode: 'nonAsciiPrintable'});
// -> '< ©'

encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
// -> '< ©'
7

import {encode} from 'html-entities';

encode('< > " \' & © ∆');
// -> '< > " ' & © ∆'

encode('< ©', {mode: 'nonAsciiPrintable'});
// -> '< ©'

encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
// -> '< ©'

Tùy chọn

cấp độ

  • Bí danh
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    8 thành
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    9 (mặc định)
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    9 sử dụng
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    0 tài liệu tham khảo được đặt tên
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    1 sử dụng
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    2 tên tham chiếu
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    3 sử dụng tài liệu tham khảo có tên
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    4

chế độ

  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    5 chỉ mã hóa các ký tự đặc biệt HTML (mặc định)
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    6 mã hóa các ký tự đặc biệt của HTML và mọi thứ bên ngoài phạm vi ký tự ASCII
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    7 mã hóa các ký tự đặc biệt HTML và mọi thứ bên ngoài các ký tự có thể in được ASCII
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    8 mã hóa tất cả các ký tự không in được, ký tự không phải ASCII và tất cả các ký tự có tham chiếu được đặt tên

con số

  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    9 sử dụng số thập phân khi mã hóa các thực thể html. tôi. e.
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    10 (mặc định)
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    11 sử dụng số thập lục phân khi mã hóa các thực thể html. tôi. e.
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    12

giải mã (văn bản, tùy chọn)

Giải mã văn bản thay thế thực thể thành ký tự. Các thực thể không xác định được để nguyên

import {encode} from 'html-entities';

encode('< > " \' & © ∆');
// -> '< > " ' & © ∆'

encode('< ©', {mode: 'nonAsciiPrintable'});
// -> '< ©'

encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
// -> '< ©'
1

Tùy chọn

cấp độ

  • Bí danh
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    8 thành
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    9 (mặc định)
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    9 sử dụng
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    0 tài liệu tham khảo được đặt tên
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    1 sử dụng
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    2 tên tham chiếu
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    3 sử dụng tài liệu tham khảo có tên
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    4

phạm vi

  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    01 mô phỏng hành vi của trình duyệt khi phân tích nội dung thẻ. các thực thể không có dấu chấm phẩy cũng được thay thế (mặc định)
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    02 mô phỏng hành vi của trình duyệt khi phân tích thuộc tính thẻ. các thực thể không có dấu chấm phẩy được thay thế khi không có dấu đẳng thức theo sau
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    03
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    04 bỏ qua các thực thể không có dấu chấm phẩy

decodeEntity(văn bản, tùy chọn)

Giải mã một thực thể HTML duy nhất. Thực thể không xác định được để nguyên

import {encode} from 'html-entities';

encode('< > " \' & © ∆');
// -> '< > " ' & © ∆'

encode('< ©', {mode: 'nonAsciiPrintable'});
// -> '< ©'

encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
// -> '< ©'
0

Tùy chọn

cấp độ

  • Bí danh
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    8 thành
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    9 (mặc định)
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    9 sử dụng
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    0 tài liệu tham khảo được đặt tên
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    1 sử dụng
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    2 tên tham chiếu
  • import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    3 sử dụng tài liệu tham khảo có tên
    import {encode} from 'html-entities';
    
    encode('< > " \' & © ∆');
    // -> '< > " ' & © ∆'
    
    encode('< ©', {mode: 'nonAsciiPrintable'});
    // -> '< ©'
    
    encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
    // -> '< ©'
    4

Hiệu suất

So sánh có ý nghĩa thống kê với các thư viện khác sử dụng

import {encode} from 'html-entities';

encode('< > " \' & © ∆');
// -> '< > " ' & © ∆'

encode('< ©', {mode: 'nonAsciiPrintable'});
// -> '< ©'

encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
// -> '< ©'
03. Kết quả của thư viện này được đánh dấu bằng
import {encode} from 'html-entities';

encode('< > " \' & © ∆');
// -> '< > " ' & © ∆'

encode('< ©', {mode: 'nonAsciiPrintable'});
// -> '< ©'

encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
// -> '< ©'
04. Mã nguồn của điểm chuẩn có sẵn tại
import {encode} from 'html-entities';

encode('< > " \' & © ∆');
// -> '< > " ' & © ∆'

encode('< ©', {mode: 'nonAsciiPrintable'});
// -> '< ©'

encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
// -> '< ©'
05

import {encode} from 'html-entities';

encode('< > " \' & © ∆');
// -> '< > " ' & © ∆'

encode('< ©', {mode: 'nonAsciiPrintable'});
// -> '< ©'

encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
// -> '< ©'
0

Giấy phép

MIT

Thông tin liên hệ bảo mật

Để báo cáo lỗ hổng bảo mật, vui lòng sử dụng liên hệ bảo mật Tidelift. Tidelift sẽ phối hợp khắc phục và tiết lộ

import {encode} from 'html-entities'; encode('< > " \' & © ∆'); // -> '< > " ' & © ∆' encode('< ©', {mode: 'nonAsciiPrintable'}); // -> '< ©' encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'}); // -> '< ©'06 cho doanh nghiệp

Có sẵn như là một phần của Đăng ký Tidelift

Những người bảo trì của

import {encode} from 'html-entities';

encode('< > " \' & © ∆');
// -> '< > " ' & © ∆'

encode('< ©', {mode: 'nonAsciiPrintable'});
// -> '< ©'

encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
// -> '< ©'
06 và hàng nghìn gói khác đang làm việc với Tidelift để cung cấp hỗ trợ thương mại và bảo trì cho các phần phụ thuộc nguồn mở mà bạn sử dụng để xây dựng các ứng dụng của mình. Tiết kiệm thời gian, giảm rủi ro và cải thiện tình trạng của mã, đồng thời trả tiền cho người duy trì chính xác các phụ thuộc mà bạn sử dụng. Tìm hiểu thêm

Làm cách nào để phân tích các ký tự đặc biệt trong JavaScript?

JavaScript cho phép chúng ta thêm các ký tự đặc biệt vào Chuỗi văn bản bằng cách sử dụng dấu gạch chéo ngược (\) . Chúng tôi có thể thêm các loại ký tự đặc biệt khác nhau, bao gồm trích dẫn đơn, trích dẫn kép, dấu và, dòng mới, tab, xóa lùi, nguồn cấp biểu mẫu, v.v. , sử dụng dấu gạch chéo ngược ngay trước các ký tự.

Làm cách nào để mã hóa và giải mã các ký tự đặc biệt trong JavaScript?

Phương thức encodeURI() mã hóa một URI. .
Ghi chú. Sử dụng phương thức decodeURI() để giải mã URI
Ký tự đặc biệt. Phương thức encodeURI() không mã hóa các ký tự như. , / ?. @ & = + $ * #.
Xem thêm. Phương thức encodeURIComponent() để mã hóa URI. Phương thức decodeURIComponent() để giải mã URI

Làm cách nào để xử lý các ký tự đặc biệt trong ví dụ JavaScript?

Để sử dụng ký tự đặc biệt làm ký tự thông thường, hãy thêm dấu gạch chéo ngược vào trước ký tự đó. \. . Đó cũng được gọi là "thoát khỏi một nhân vật". Ví dụ. cảnh báo ("Chương 5. 1"

Làm cách nào để giải mã văn bản được mã hóa trong JavaScript?

Giải mã. Trong JavaScript, để giải mã một chuỗi phương thức unescape() được sử dụng . Phương thức này lấy một chuỗi, được mã hóa bởi phương thức escape() và giải mã nó. Các ký tự thập lục phân trong một chuỗi sẽ được thay thế bằng các ký tự thực mà chúng đại diện bằng phương thức unescape().