source: frontend/node_modules/html-entities/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 7.0 KB
Line 
1html-entities
2=============
3
4Fastest HTML entities library.
5
6Comes with both TypeScript and Flow types.
7
8Installation
9------------
10
11```bash
12$ npm install html-entities
13```
14
15Usage
16-----
17
18### encode(text, options)
19
20Encodes text replacing HTML special characters (`<>&"'`) and/or other character ranges depending on `mode` option value.
21
22```js
23import {encode} from 'html-entities';
24
25encode('< > " \' & © ∆');
26// -> '&lt; &gt; &quot; &apos; &amp; © ∆'
27
28encode('< ©', {mode: 'nonAsciiPrintable'});
29// -> '&lt; &copy;'
30
31encode('< ©', {mode: 'nonAsciiPrintable', level: 'xml'});
32// -> '&lt; &#169;'
33
34encode('< > " \' & ©', {mode: 'nonAsciiPrintableOnly', level: 'xml'});
35// -> '< > " \' & &#169;'
36```
37
38Options:
39
40#### level
41
42 * `all` alias to `html5` (default).
43 * `html5` uses `HTML5` named references.
44 * `html4` uses `HTML4` named references.
45 * `xml` uses `XML` named references.
46
47#### mode
48
49 * `specialChars` encodes only HTML special characters (default).
50 * `nonAscii` encodes HTML special characters and everything outside the [ASCII character range](https://en.wikipedia.org/wiki/ASCII).
51 * `nonAsciiPrintable` encodes HTML special characters and everything outiside of the [ASCII printable characters](https://en.wikipedia.org/wiki/ASCII#Printable_characters).
52 * `nonAsciiPrintableOnly` everything outiside of the [ASCII printable characters](https://en.wikipedia.org/wiki/ASCII#Printable_characters) keeping HTML special characters intact.
53 * `extensive` encodes all non-printable characters, non-ASCII characters and all characters with named references.
54
55#### numeric
56
57 * `decimal` uses decimal numbers when encoding html entities. i.e. `&#169;` (default).
58 * `hexadecimal` uses hexadecimal numbers when encoding html entities. i.e. `&#xa9;`.
59
60
61### decode(text, options)
62
63Decodes text replacing entities to characters. Unknown entities are left as is.
64
65```js
66import {decode} from 'html-entities';
67
68decode('&lt; &gt; &quot; &apos; &amp; &#169; &#8710;');
69// -> '< > " \' & © ∆'
70
71decode('&copy;', {level: 'html5'});
72// -> '©'
73
74decode('&copy;', {level: 'xml'});
75// -> '&copy;'
76```
77
78Options:
79
80#### level
81
82 * `all` alias to `html5` (default).
83 * `html5` uses `HTML5` named references.
84 * `html4` uses `HTML4` named references.
85 * `xml` uses `XML` named references.
86
87#### scope
88
89 * `body` emulates behavior of browser when parsing tag bodies: entities without semicolon are also replaced (default).
90 * `attribute` emulates behavior of browser when parsing tag attributes: entities without semicolon are replaced when not followed by equality sign `=`.
91 * `strict` ignores entities without semicolon.
92
93### decodeEntity(text, options)
94
95Decodes a single HTML entity. Unknown entitiy is left as is.
96
97```js
98import {decodeEntity} from 'html-entities';
99
100decodeEntity('&lt;');
101// -> '<'
102
103decodeEntity('&copy;', {level: 'html5'});
104// -> '©'
105
106decodeEntity('&copy;', {level: 'xml'});
107// -> '&copy;'
108```
109
110Options:
111
112#### level
113
114 * `all` alias to `html5` (default).
115 * `html5` uses `HTML5` named references.
116 * `html4` uses `HTML4` named references.
117 * `xml` uses `XML` named references.
118
119Performance
120-----------
121
122Statistically significant comparison with other libraries using `benchmark.js`.
123Results by this library are marked with `*`.
124The source code of the benchmark is available at `benchmark/benchmark.ts`.
125
126```
127Common
128
129 Initialization / Load speed
130
131 #1: he x 516 ops/sec ±5.71% (78 runs sampled)
132 * #2: html-entities x 407 ops/sec ±5.64% (81 runs sampled)
133 #3: entities x 352 ops/sec ±4.16% (80 runs sampled)
134
135HTML5
136
137 Encode test
138
139 * #1: html-entities.encode - html5, extensive x 437,236 ops/sec ±0.90% (98 runs sampled)
140 #2: entities.encodeHTML x 335,714 ops/sec ±0.87% (92 runs sampled)
141
142 Encode non-ASCII test
143
144 * #1: html-entities.encode - html5, nonAscii x 749,246 ops/sec ±0.61% (96 runs sampled)
145 #2: entities.encodeNonAsciiHTML x 706,984 ops/sec ±1.06% (98 runs sampled)
146 * #3: html-entities.encode - html5, nonAsciiPrintable x 691,193 ops/sec ±4.47% (90 runs sampled)
147 #4: he.encode x 141,105 ops/sec ±0.87% (92 runs sampled)
148
149 Decode test
150
151 #1: entities.decodeHTML x 678,595 ops/sec ±1.28% (92 runs sampled)
152 #2: entities.decodeHTMLStrict x 684,372 ops/sec ±2.76% (82 runs sampled)
153 * #3: html-entities.decode - html5, strict x 485,664 ops/sec ±0.80% (94 runs sampled)
154 * #4: html-entities.decode - html5, body x 463,074 ops/sec ±1.11% (93 runs sampled)
155 * #5: html-entities.decode - html5, attribute x 456,185 ops/sec ±2.24% (91 runs sampled)
156 #6: he.decode x 302,668 ops/sec ±2.73% (90 runs sampled)
157
158HTML4
159
160 Encode test
161
162 * #1: html-entities.encode - html4, nonAscii x 737,475 ops/sec ±1.04% (95 runs sampled)
163 * #2: html-entities.encode - html4, nonAsciiPrintable x 649,866 ops/sec ±4.28% (79 runs sampled)
164 * #3: html-entities.encode - html4, extensive x 202,337 ops/sec ±3.66% (64 runs sampled)
165
166 Decode test
167
168 * #1: html-entities.decode - html4, attribute x 529,674 ops/sec ±0.90% (90 runs sampled)
169 * #2: html-entities.decode - html4, body x 499,135 ops/sec ±2.27% (80 runs sampled)
170 * #3: html-entities.decode - html4, strict x 489,806 ops/sec ±4.37% (84 runs sampled)
171
172XML
173
174 Encode test
175
176 * #1: html-entities.encode - xml, nonAscii x 823,097 ops/sec ±0.75% (81 runs sampled)
177 * #2: html-entities.encode - xml, nonAsciiPrintable x 764,638 ops/sec ±0.93% (93 runs sampled)
178 #3: entities.encodeXML x 672,186 ops/sec ±1.51% (92 runs sampled)
179 * #4: html-entities.encode - xml, extensive x 376,870 ops/sec ±0.76% (77 runs sampled)
180
181 Decode test
182
183 #1: entities.decodeXML x 930,758 ops/sec ±2.90% (90 runs sampled)
184 * #2: html-entities.decode - xml, body x 617,321 ops/sec ±0.74% (83 runs sampled)
185 * #3: html-entities.decode - xml, attribute x 611,598 ops/sec ±0.50% (92 runs sampled)
186 * #4: html-entities.decode - xml, strict x 607,191 ops/sec ±2.30% (85 runs sampled)
187
188Escaping
189
190 Escape test
191
192 #1: entities.escapeUTF8 x 1,930,874 ops/sec ±0.80% (95 runs sampled)
193 #2: he.escape x 1,717,522 ops/sec ±0.75% (84 runs sampled)
194 * #3: html-entities.encode - xml, specialChars x 1,611,374 ops/sec ±1.30% (92 runs sampled)
195 #4: entities.escape x 673,710 ops/sec ±1.30% (94 runs sampled)
196```
197
198License
199-------
200
201MIT
202
203Security contact information
204----------------------------
205
206To report a security vulnerability, please use the
207[Tidelift security contact](https://tidelift.com/security). Tidelift will
208coordinate the fix and disclosure.
209
210`html-entities` for enterprise
211------------------------------
212
213Available as part of the Tidelift Subscription
214
215The maintainers of `html-entities` and thousands of other packages are working with
216Tidelift to deliver commercial support and maintenance for the open source
217dependencies you use to build your applications. Save time, reduce risk, and
218improve code health, while paying the maintainers of the exact dependencies you
219use.
220[Learn more.](https://tidelift.com/subscription/pkg/npm-html-entities?utm_source=npm-html-entities&utm_medium=referral&utm_campaign=enterprise)
Note: See TracBrowser for help on using the repository browser.