Skip to content

Commit db654bd

Browse files
committed
Refactor code-style
1 parent bc0393a commit db654bd

16 files changed

+428
-346
lines changed

lib/element.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* @typedef {import('./index.js').State} State
44
*/
55

6-
import {all} from './one.js'
76
import {name} from './name.js'
7+
import {all} from './one.js'
88
import {value} from './value.js'
99

1010
const own = {}.hasOwnProperty

lib/index.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,37 @@
44
*/
55

66
/**
7-
* @typedef {Literal & {type: 'raw'}} Raw
8-
* To do: improved `Raw` type?
9-
*
10-
* @typedef {'"' | "'"} Quote
11-
* XML quotes for attribute values.
12-
*
137
* @typedef Options
148
* Configuration.
159
* @property {boolean | null | undefined} [allowDangerousXml=false]
16-
* Allow `raw` nodes and insert them as raw XML.
10+
* Allow `raw` nodes and insert them as raw XML (default: `false`).
1711
*
1812
* When `false`, `Raw` nodes are encoded.
1913
*
2014
* > ⚠️ **Danger**: only set this if you completely trust the content.
2115
* @property {boolean | null | undefined} [closeEmptyElements=false]
2216
* Close elements without any content with slash (`/`) on the opening tag
23-
* instead of an end tag: `<circle />` instead of `<circle></circle>`.
17+
* instead of an end tag: `<circle />` instead of `<circle></circle>`
18+
* (default: `false`).
2419
*
2520
* See `tightClose` to control whether a space is used before the slash.
2621
* @property {Quote | null | undefined} [quote='"']
27-
* Preferred quote to use.
22+
* Preferred quote to use (default: `'"'`).
2823
* @property {boolean | null | undefined} [quoteSmart=false]
29-
* Use the other quote if that results in less bytes.
24+
* Use the other quote if that results in less bytes (default: `false`).
3025
* @property {boolean | null | undefined} [tightClose=false]
3126
* Do not use an extra space when closing self-closing elements: `<circle/>`
32-
* instead of `<circle />`.
27+
* instead of `<circle />` (default: `false`).
3328
*
3429
* > 👉 **Note**: only used if `closeEmptyElements: true`.
3530
*
31+
* @typedef {'"' | "'"} Quote
32+
* XML quotes for attribute values.
33+
*
34+
* @typedef {Literal & {type: 'raw'}} Raw
35+
* To do: improved `Raw` type?
36+
*
37+
*
3638
* @typedef State
3739
* Info passed around about the current state.
3840
* @property {Options} options
@@ -47,7 +49,7 @@ import {one} from './one.js'
4749
* @param {Array<Nodes> | Nodes} tree
4850
* xast node(s) to serialize.
4951
* @param {Options | null | undefined} [options]
50-
* Configuration.
52+
* Configuration (optional).
5153
* @returns {string}
5254
* Serialized XML.
5355
*/

lib/instruction.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @typedef {import('xast').Instruction} Instruction
33
*/
44

5-
import {escape} from './util-escape.js'
65
import {name} from './name.js'
6+
import {escape} from './util-escape.js'
77

88
const unsafe = /\?>/g
99
const subset = ['>']

lib/one.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
* @typedef {import('./index.js').State} State
66
*/
77

8-
import {element} from './element.js'
9-
import {text} from './text.js'
8+
import {cdata} from './cdata.js'
109
import {comment} from './comment.js'
1110
import {doctype} from './doctype.js'
11+
import {element} from './element.js'
1212
import {instruction} from './instruction.js'
13-
import {cdata} from './cdata.js'
1413
import {raw} from './raw.js'
14+
import {text} from './text.js'
1515

1616
const own = {}.hasOwnProperty
1717

1818
const handlers = {
19-
root: all,
20-
element,
21-
text,
19+
cdata,
2220
comment,
2321
doctype,
22+
element,
2423
instruction,
25-
cdata,
26-
raw
24+
raw,
25+
root: all,
26+
text
2727
}
2828

2929
/**

lib/text.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const subset = ['&', '<']
1010
/**
1111
* Serialize a text.
1212
*
13-
* @param {Text | Raw} node
13+
* @param {Raw | Text} node
1414
* xast text node (or raw).
1515
* @returns {string}
1616
* Serialized XML.

lib/util-escape.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {stringifyEntitiesLight} from 'stringify-entities'
22

3-
// eslint-disable-next-line no-control-regex
3+
// eslint-disable-next-line no-control-regex -- XO is wrong.
44
const noncharacter = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g
55

66
/**
@@ -11,7 +11,7 @@ const noncharacter = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g
1111
* @param {Array<string>} subset
1212
* Characters to escape.
1313
* @param {RegExp | null | undefined} [unsafe]
14-
* Regex to scope `subset` to.
14+
* Regex to scope `subset` to (optional).
1515
* @returns {string}
1616
* Escaped string.
1717
*/

0 commit comments

Comments
 (0)