source: trip-planner-front/node_modules/ent/readme.markdown@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1# ent
2
3Encode and decode HTML entities
4
5[![browser support](http://ci.testling.com/substack/node-ent.png)](http://ci.testling.com/substack/node-ent)
6
7[![build status](https://secure.travis-ci.org/substack/node-ent.png)](http://travis-ci.org/substack/node-ent)
8
9# example
10
11``` js
12var ent = require('ent');
13console.log(ent.encode('<span>©moo</span>'))
14console.log(ent.decode('&pi; &amp; &rho;'));
15```
16
17```
18&#60;span&#62;&#169;moo&#60;/span&#62;
19π & ρ
20```
21
22![ent](http://substack.net/images/ent.png)
23
24# methods
25
26``` js
27var ent = require('ent');
28var encode = require('ent/encode');
29var decode = require('ent/decode');
30```
31
32## encode(str, opts={})
33
34Escape unsafe characters in `str` with html entities.
35
36By default, entities are encoded with numeric decimal codes.
37
38If `opts.numeric` is false or `opts.named` is true, encoding will used named
39codes like `&pi;`.
40
41If `opts.special` is set to an Object, the key names will be forced
42to be encoded (defaults to forcing: `<>'"&`). For example:
43
44``` js
45console.log(encode('hello', { special: { l: true } }));
46```
47
48```
49he&#108;&#108;o
50```
51
52## decode(str)
53
54Convert html entities in `str` back to raw text.
55
56# credits
57
58HTML entity tables shamelessly lifted from perl's
59[HTML::Entities](http://cpansearch.perl.org/src/GAAS/HTML-Parser-3.68/lib/HTML/Entities.pm)
60
61# install
62
63With [npm](https://npmjs.org) do:
64
65```
66npm install ent
67```
68
69# license
70
71MIT
Note: See TracBrowser for help on using the repository browser.