Skip to content

Commit d882552

Browse files
authored
updated the readme for the latest changes.
1 parent 2d0ded9 commit d882552

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

README.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ load('lean-he.js');
3838

3939
## API
4040

41-
### `lean_he.encode(text, options)`
41+
### `leanHe.encode(text, options)`
4242

4343
This function takes a string of text and encodes (by default) any symbols that aren’t printable ASCII symbols and `&`, `<`, `>`, `"`, `'`, and `` ` ``, replacing them with character references.
4444

45-
>Can also use `var encode = require('lean-he/encode');` instead to reduce the imported file size if the only need is to encode.
45+
>Can also use `var encode = require('leanHe/encode');` instead to reduce the imported file size if the only need is to encode.
4646
4747
```js
48-
lean_he.encode('foo © bar ≠ baz 𝌆 qux');
48+
leanHe.encode('foo © bar ≠ baz 𝌆 qux');
4949
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'
5050
```
5151

5252
As long as the input string contains [allowed code points](https://html.spec.whatwg.org/multipage/parsing.html#preprocessing-the-input-stream) only, the return value of this function is always valid HTML. Any [(invalid) code points that cannot be represented using a character reference](https://html.spec.whatwg.org/multipage/syntax.html#table-charref-overrides) in the input are not encoded:
5353

5454
```js
55-
lean_he.encode('foo \0 bar');
55+
leanHe.encode('foo \0 bar');
5656
// → 'foo \0 bar'
5757
```
5858

@@ -68,17 +68,17 @@ The default value for the `useNamedReferences` option is `false`. This means tha
6868

6969
```js
7070
// Using the global default setting (defaults to `false`):
71-
lean_he.encode('foo © bar ≠ baz 𝌆 qux');
71+
leanHe.encode('foo © bar ≠ baz 𝌆 qux');
7272
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'
7373

7474
// Passing an `options` object to `encode`, to explicitly disallow named references:
75-
lean_he.encode('foo © bar ≠ baz 𝌆 qux', {
75+
leanHe.encode('foo © bar ≠ baz 𝌆 qux', {
7676
'useNamedReferences': false
7777
});
7878
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'
7979

8080
// Passing an `options` object to `encode`, to explicitly allow named references:
81-
lean_he.encode('foo © bar ≠ baz 𝌆 qux', {
81+
leanHe.encode('foo © bar ≠ baz 𝌆 qux', {
8282
'useNamedReferences': true
8383
});
8484
// → 'foo &copy; bar &ne; baz &#x1D306; qux'
@@ -90,23 +90,23 @@ The default value for the `decimal` option is `false`. If the option is enabled,
9090

9191
```js
9292
// Using the global default setting (defaults to `false`):
93-
lean_he.encode('foo © bar ≠ baz 𝌆 qux');
93+
leanHe.encode('foo © bar ≠ baz 𝌆 qux');
9494
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'
9595

9696
// Passing an `options` object to `encode`, to explicitly disable decimal escapes:
97-
lean_he.encode('foo © bar ≠ baz 𝌆 qux', {
97+
leanHe.encode('foo © bar ≠ baz 𝌆 qux', {
9898
'decimal': false
9999
});
100100
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'
101101

102102
// Passing an `options` object to `encode`, to explicitly enable decimal escapes:
103-
lean_he.encode('foo © bar ≠ baz 𝌆 qux', {
103+
leanHe.encode('foo © bar ≠ baz 𝌆 qux', {
104104
'decimal': true
105105
});
106106
// → 'foo &#169; bar &#8800; baz &#119558; qux'
107107

108108
// Passing an `options` object to `encode`, to explicitly allow named references and decimal escapes:
109-
lean_he.encode('foo © bar ≠ baz 𝌆 qux', {
109+
leanHe.encode('foo © bar ≠ baz 𝌆 qux', {
110110
'useNamedReferences': true,
111111
'decimal': true
112112
});
@@ -119,17 +119,17 @@ The default value for the `encodeEverything` option is `false`. This means that
119119

120120
```js
121121
// Using the global default setting (defaults to `false`):
122-
lean_he.encode('foo © bar ≠ baz 𝌆 qux');
122+
leanHe.encode('foo © bar ≠ baz 𝌆 qux');
123123
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'
124124

125125
// Passing an `options` object to `encode`, to explicitly encode all symbols:
126-
lean_he.encode('foo © bar ≠ baz 𝌆 qux', {
126+
leanHe.encode('foo © bar ≠ baz 𝌆 qux', {
127127
'encodeEverything': true
128128
});
129129
// → '&#x66;&#x6F;&#x6F;&#x20;&#xA9;&#x20;&#x62;&#x61;&#x72;&#x20;&#x2260;&#x20;&#x62;&#x61;&#x7A;&#x20;&#x1D306;&#x20;&#x71;&#x75;&#x78;'
130130

131131
// This setting can be combined with the `useNamedReferences` option:
132-
lean_he.encode('foo © bar ≠ baz 𝌆 qux', {
132+
leanHe.encode('foo © bar ≠ baz 𝌆 qux', {
133133
'encodeEverything': true,
134134
'useNamedReferences': true
135135
});
@@ -142,17 +142,17 @@ The default value for the `strict` option is `false`. This means that `encode()`
142142

143143
```js
144144
// Using the global default setting (defaults to `false`, i.e. error-tolerant mode):
145-
lean_he.encode('\x01');
145+
leanHe.encode('\x01');
146146
// → '&#x1;'
147147

148148
// Passing an `options` object to `encode`, to explicitly enable error-tolerant mode:
149-
lean_he.encode('\x01', {
149+
leanHe.encode('\x01', {
150150
'strict': false
151151
});
152152
// → '&#x1;'
153153

154154
// Passing an `options` object to `encode`, to explicitly enable strict mode:
155-
lean_he.encode('\x01', {
155+
leanHe.encode('\x01', {
156156
'strict': true
157157
});
158158
// → Parse error
@@ -163,7 +163,7 @@ lean_he.encode('\x01', {
163163
The default value for the `allowUnsafeSymbols` option is `false`. This means that characters that are unsafe for use in HTML content (`&`, `<`, `>`, `"`, `'`, and `` ` ``) will be encoded. When set to `true`, only non-ASCII characters will be encoded. If the `encodeEverything` option is set to `true`, this option will be ignored.
164164

165165
```js
166-
lean_he.encode('foo © and & ampersand', {
166+
leanHe.encode('foo © and & ampersand', {
167167
'allowUnsafeSymbols': true
168168
});
169169
// → 'foo &#xA9; and & ampersand'
@@ -175,14 +175,14 @@ The global default setting can be overridden by modifying the `he.encode.options
175175

176176
```js
177177
// Read the global default setting:
178-
lean_he.encode.options.useNamedReferences;
178+
leanHe.encode.options.useNamedReferences;
179179
// → `false` by default
180180

181181
// Override the global default setting:
182-
lean_he.encode.options.useNamedReferences = true;
182+
leanHe.encode.options.useNamedReferences = true;
183183

184184
// Using the global default setting, which is now `true`:
185-
lean_he.encode('foo © bar ≠ baz 𝌆 qux');
185+
leanHe.encode('foo © bar ≠ baz 𝌆 qux');
186186
// → 'foo &copy; bar &ne; baz &#x1D306; qux'
187187
```
188188

@@ -193,7 +193,7 @@ This function takes a string of HTML and decodes any named and numerical charact
193193
>Can also use `var decode = require('lean-he/decode');` instead to reduce the imported file size if the only need is to decode.
194194
195195
```js
196-
lean_he.decode('foo &copy; bar &ne; baz &#x1D306; qux');
196+
leanHe.decode('foo &copy; bar &ne; baz &#x1D306; qux');
197197
// → 'foo © bar ≠ baz 𝌆 qux'
198198
```
199199

@@ -205,17 +205,17 @@ The default value for the `isAttributeValue` option is `false`. This means that
205205

206206
```js
207207
// Using the global default setting (defaults to `false`, i.e. HTML text context):
208-
lean_he.decode('foo&ampbar');
208+
leanHe.decode('foo&ampbar');
209209
// → 'foo&bar'
210210

211211
// Passing an `options` object to `decode`, to explicitly assume an HTML text context:
212-
lean_he.decode('foo&ampbar', {
212+
leanHe.decode('foo&ampbar', {
213213
'isAttributeValue': false
214214
});
215215
// → 'foo&bar'
216216

217217
// Passing an `options` object to `decode`, to explicitly assume an HTML attribute value context:
218-
lean_he.decode('foo&ampbar', {
218+
leanHe.decode('foo&ampbar', {
219219
'isAttributeValue': true
220220
});
221221
// → 'foo&ampbar'
@@ -227,17 +227,17 @@ The default value for the `strict` option is `false`. This means that `decode()`
227227

228228
```js
229229
// Using the global default setting (defaults to `false`, i.e. error-tolerant mode):
230-
lean_he.decode('foo&ampbar');
230+
leanHe.decode('foo&ampbar');
231231
// → 'foo&bar'
232232

233233
// Passing an `options` object to `decode`, to explicitly enable error-tolerant mode:
234-
lean_he.decode('foo&ampbar', {
234+
leanHe.decode('foo&ampbar', {
235235
'strict': false
236236
});
237237
// → 'foo&bar'
238238

239239
// Passing an `options` object to `decode`, to explicitly enable strict mode:
240-
lean_he.decode('foo&ampbar', {
240+
leanHe.decode('foo&ampbar', {
241241
'strict': true
242242
});
243243
// → Parse error
@@ -249,31 +249,31 @@ The global default settings for the `decode` function can be overridden by modif
249249

250250
```js
251251
// Read the global default setting:
252-
lean_he.decode.options.isAttributeValue;
252+
leanHe.decode.options.isAttributeValue;
253253
// → `false` by default
254254

255255
// Override the global default setting:
256-
lean_he.decode.options.isAttributeValue = true;
256+
leanHe.decode.options.isAttributeValue = true;
257257

258258
// Using the global default setting, which is now `true`:
259-
lean_he.decode('foo&ampbar');
259+
leanHe.decode('foo&ampbar');
260260
// → 'foo&ampbar'
261261
```
262262

263-
### `lean_he.escape(text)`
263+
### `leanHe.escape(text)`
264264

265265
This function takes a string of text and escapes it for use in text contexts in XML or HTML documents. Only the following characters are escaped: `&`, `<`, `>`, `"`, `'`, and `` ` ``.
266266

267267
>Can also use `var escape = require('lean-he/escape');` instead to reduce the imported file size if the only need is to escape.
268268
269269
```js
270-
lean_he.escape('<img src=\'x\' onerror="prompt(1)">');
270+
leanHe.escape('<img src=\'x\' onerror="prompt(1)">');
271271
// → '&lt;img src=&#x27;x&#x27; onerror=&quot;prompt(1)&quot;&gt;'
272272
```
273273

274-
### `lean_he.unescape(html, options)`
274+
### `leanHe.unescape(html, options)`
275275

276-
`lean_he.unescape` is an alias for `lean_he.decode`. It takes a string of HTML and decodes any named and numerical character references in it.
276+
`leanHe.unescape` is an alias for `leanHe.decode`. It takes a string of HTML and decodes any named and numerical character references in it.
277277

278278
>Can also use `var unescape = require('lean-he/unescape');` instead to reduce the imported file size if the only need is to unescape.
279279

0 commit comments

Comments
 (0)