You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35-35Lines changed: 35 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,21 +38,21 @@ load('lean-he.js');
38
38
39
39
## API
40
40
41
-
### `lean_he.encode(text, options)`
41
+
### `leanHe.encode(text, options)`
42
42
43
43
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.
44
44
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.
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:
53
53
54
54
```js
55
-
lean_he.encode('foo \0 bar');
55
+
leanHe.encode('foo \0 bar');
56
56
// → 'foo \0 bar'
57
57
```
58
58
@@ -68,17 +68,17 @@ The default value for the `useNamedReferences` option is `false`. This means tha
68
68
69
69
```js
70
70
// Using the global default setting (defaults to `false`):
@@ -142,17 +142,17 @@ The default value for the `strict` option is `false`. This means that `encode()`
142
142
143
143
```js
144
144
// Using the global default setting (defaults to `false`, i.e. error-tolerant mode):
145
-
lean_he.encode('\x01');
145
+
leanHe.encode('\x01');
146
146
// → ''
147
147
148
148
// Passing an `options` object to `encode`, to explicitly enable error-tolerant mode:
149
-
lean_he.encode('\x01', {
149
+
leanHe.encode('\x01', {
150
150
'strict':false
151
151
});
152
152
// → ''
153
153
154
154
// Passing an `options` object to `encode`, to explicitly enable strict mode:
155
-
lean_he.encode('\x01', {
155
+
leanHe.encode('\x01', {
156
156
'strict':true
157
157
});
158
158
// → Parse error
@@ -163,7 +163,7 @@ lean_he.encode('\x01', {
163
163
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.
@@ -205,17 +205,17 @@ The default value for the `isAttributeValue` option is `false`. This means that
205
205
206
206
```js
207
207
// Using the global default setting (defaults to `false`, i.e. HTML text context):
208
-
lean_he.decode('foo&bar');
208
+
leanHe.decode('foo&bar');
209
209
// → 'foo&bar'
210
210
211
211
// Passing an `options` object to `decode`, to explicitly assume an HTML text context:
212
-
lean_he.decode('foo&bar', {
212
+
leanHe.decode('foo&bar', {
213
213
'isAttributeValue':false
214
214
});
215
215
// → 'foo&bar'
216
216
217
217
// Passing an `options` object to `decode`, to explicitly assume an HTML attribute value context:
218
-
lean_he.decode('foo&bar', {
218
+
leanHe.decode('foo&bar', {
219
219
'isAttributeValue':true
220
220
});
221
221
// → 'foo&bar'
@@ -227,17 +227,17 @@ The default value for the `strict` option is `false`. This means that `decode()`
227
227
228
228
```js
229
229
// Using the global default setting (defaults to `false`, i.e. error-tolerant mode):
230
-
lean_he.decode('foo&bar');
230
+
leanHe.decode('foo&bar');
231
231
// → 'foo&bar'
232
232
233
233
// Passing an `options` object to `decode`, to explicitly enable error-tolerant mode:
234
-
lean_he.decode('foo&bar', {
234
+
leanHe.decode('foo&bar', {
235
235
'strict':false
236
236
});
237
237
// → 'foo&bar'
238
238
239
239
// Passing an `options` object to `decode`, to explicitly enable strict mode:
240
-
lean_he.decode('foo&bar', {
240
+
leanHe.decode('foo&bar', {
241
241
'strict':true
242
242
});
243
243
// → Parse error
@@ -249,31 +249,31 @@ The global default settings for the `decode` function can be overridden by modif
249
249
250
250
```js
251
251
// Read the global default setting:
252
-
lean_he.decode.options.isAttributeValue;
252
+
leanHe.decode.options.isAttributeValue;
253
253
// → `false` by default
254
254
255
255
// Override the global default setting:
256
-
lean_he.decode.options.isAttributeValue=true;
256
+
leanHe.decode.options.isAttributeValue=true;
257
257
258
258
// Using the global default setting, which is now `true`:
259
-
lean_he.decode('foo&bar');
259
+
leanHe.decode('foo&bar');
260
260
// → 'foo&bar'
261
261
```
262
262
263
-
### `lean_he.escape(text)`
263
+
### `leanHe.escape(text)`
264
264
265
265
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 `` ` ``.
266
266
267
267
>Can also use `var escape = require('lean-he/escape');` instead to reduce the imported file size if the only need is to escape.
0 commit comments