File tree 3 files changed +62
-60
lines changed
3 files changed +62
-60
lines changed Original file line number Diff line number Diff line change 1
- /**
2
- * @typedef {import('xast').Root } Root
3
- * @typedef {import('xast').Element } Element
4
- * @typedef {import('xast').RootChildMap } RootChildMap
5
- */
6
-
7
- /**
8
- * @typedef {RootChildMap[keyof RootChildMap] } Child
9
- * @typedef {Root | Child } Node
10
- * @typedef {Root | Element } Parent
11
- */
12
-
13
- /**
14
- * Get the plain-text value of a node.
15
- *
16
- * @param {Node } node
17
- * Node to serialize.
18
- * @returns {string }
19
- * Serialized node.
20
- */
21
- export function toString ( node ) {
22
- // A root or an element
23
- if ( 'children' in node ) return all ( node )
24
- return 'value' in node ? node . value : ''
25
- }
26
-
27
- /**
28
- * Serialize a child.
29
- *
30
- * @param {Node } node
31
- * Child to serialize.
32
- * @returns {string }
33
- * Serialized node.
34
- */
35
- function one ( node ) {
36
- if ( node . type === 'text' ) return node . value
37
- // Ignore things like comments, instruction, cdata.
38
- return 'children' in node ? all ( node ) : ''
39
- }
40
-
41
- /**
42
- * Serialize a parent.
43
- *
44
- * @param {Parent } node
45
- * Parent to serialize.
46
- * @returns {string }
47
- * Serialized node.
48
- */
49
- function all ( node ) {
50
- const children = node . children
51
- let index = - 1
52
- /** @type {Array<string> } */
53
- const result = [ ]
54
-
55
- while ( ++ index < children . length ) {
56
- result [ index ] = one ( children [ index ] )
57
- }
58
-
59
- return result . join ( '' )
60
- }
1
+ export { toString } from './lib/index.js'
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @typedef {import('xast').Root } Root
3
+ * @typedef {import('xast').Element } Element
4
+ * @typedef {import('xast').RootChildMap } RootChildMap
5
+ */
6
+
7
+ /**
8
+ * @typedef {RootChildMap[keyof RootChildMap] } Child
9
+ * @typedef {Root | Child } Node
10
+ * @typedef {Root | Element } Parent
11
+ */
12
+
13
+ /**
14
+ * Get the plain-text value of a node.
15
+ *
16
+ * @param {Node } node
17
+ * Node to serialize.
18
+ * @returns {string }
19
+ * Serialized node.
20
+ */
21
+ export function toString ( node ) {
22
+ // A root or an element
23
+ if ( 'children' in node ) return all ( node )
24
+ return 'value' in node ? node . value : ''
25
+ }
26
+
27
+ /**
28
+ * Serialize a child.
29
+ *
30
+ * @param {Node } node
31
+ * Child to serialize.
32
+ * @returns {string }
33
+ * Serialized node.
34
+ */
35
+ function one ( node ) {
36
+ if ( node . type === 'text' ) return node . value
37
+ // Ignore things like comments, instruction, cdata.
38
+ return 'children' in node ? all ( node ) : ''
39
+ }
40
+
41
+ /**
42
+ * Serialize a parent.
43
+ *
44
+ * @param {Parent } node
45
+ * Parent to serialize.
46
+ * @returns {string }
47
+ * Serialized node.
48
+ */
49
+ function all ( node ) {
50
+ const children = node . children
51
+ let index = - 1
52
+ /** @type {Array<string> } */
53
+ const result = [ ]
54
+
55
+ while ( ++ index < children . length ) {
56
+ result [ index ] = one ( children [ index ] )
57
+ }
58
+
59
+ return result . join ( '' )
60
+ }
Original file line number Diff line number Diff line change 29
29
"main" : " index.js" ,
30
30
"types" : " index.d.ts" ,
31
31
"files" : [
32
+ " lib/" ,
32
33
" index.d.ts" ,
33
34
" index.js"
34
35
],
You can’t perform that action at this time.
0 commit comments