Last change
on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | # ent
|
---|
| 2 |
|
---|
| 3 | Encode 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
|
---|
| 12 | var ent = require('ent');
|
---|
| 13 | console.log(ent.encode('<span>©moo</span>'))
|
---|
| 14 | console.log(ent.decode('π & ρ'));
|
---|
| 15 | ```
|
---|
| 16 |
|
---|
| 17 | ```
|
---|
| 18 | <span>©moo</span>
|
---|
| 19 | π & ρ
|
---|
| 20 | ```
|
---|
| 21 |
|
---|
| 22 | ![ent](http://substack.net/images/ent.png)
|
---|
| 23 |
|
---|
| 24 | # methods
|
---|
| 25 |
|
---|
| 26 | ``` js
|
---|
| 27 | var ent = require('ent');
|
---|
| 28 | var encode = require('ent/encode');
|
---|
| 29 | var decode = require('ent/decode');
|
---|
| 30 | ```
|
---|
| 31 |
|
---|
| 32 | ## encode(str, opts={})
|
---|
| 33 |
|
---|
| 34 | Escape unsafe characters in `str` with html entities.
|
---|
| 35 |
|
---|
| 36 | By default, entities are encoded with numeric decimal codes.
|
---|
| 37 |
|
---|
| 38 | If `opts.numeric` is false or `opts.named` is true, encoding will used named
|
---|
| 39 | codes like `π`.
|
---|
| 40 |
|
---|
| 41 | If `opts.special` is set to an Object, the key names will be forced
|
---|
| 42 | to be encoded (defaults to forcing: `<>'"&`). For example:
|
---|
| 43 |
|
---|
| 44 | ``` js
|
---|
| 45 | console.log(encode('hello', { special: { l: true } }));
|
---|
| 46 | ```
|
---|
| 47 |
|
---|
| 48 | ```
|
---|
| 49 | hello
|
---|
| 50 | ```
|
---|
| 51 |
|
---|
| 52 | ## decode(str)
|
---|
| 53 |
|
---|
| 54 | Convert html entities in `str` back to raw text.
|
---|
| 55 |
|
---|
| 56 | # credits
|
---|
| 57 |
|
---|
| 58 | HTML 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 |
|
---|
| 63 | With [npm](https://npmjs.org) do:
|
---|
| 64 |
|
---|
| 65 | ```
|
---|
| 66 | npm install ent
|
---|
| 67 | ```
|
---|
| 68 |
|
---|
| 69 | # license
|
---|
| 70 |
|
---|
| 71 | MIT
|
---|
Note:
See
TracBrowser
for help on using the repository browser.