Skip to content

Commit b1ba622

Browse files
committed
Remove separator
1 parent a20f14d commit b1ba622

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

lib/index.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ const emptyNodes = []
1313
*
1414
* @param {Array<Nodes> | Nodes} value
1515
* Node or list of nodes to serialize.
16-
* @param {string | null | undefined} [separator='']
17-
* Separator to use (default: `''`).
1816
* @returns {string}
1917
* Result.
2018
*/
21-
// To do next major: remove `separator`.
22-
export function toString(value, separator) {
19+
export function toString(value) {
2320
let index = -1
2421

2522
if (!value || (!Array.isArray(value) && !value.type)) {
@@ -34,8 +31,8 @@ export function toString(value, separator) {
3431
const values = []
3532

3633
while (++index < children.length) {
37-
values[index] = toString(children[index], separator)
34+
values[index] = toString(children[index])
3835
}
3936

40-
return values.join(separator || '')
37+
return values.join('')
4138
}

readme.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`toString(value[, separator])`](#tostringvalue-separator)
20+
* [`toString(value)`](#tostringvalue)
2121
* [Types](#types)
2222
* [Compatibility](#compatibility)
2323
* [Contribute](#contribute)
@@ -65,7 +65,7 @@ console.log(
6565
type: 'WordNode',
6666
children: [
6767
{type: 'TextNode', value: 'AT'},
68-
{type: 'PunctuationNode', value: '&'},
68+
{type: 'SymbolNode', value: '&'},
6969
{type: 'TextNode', value: 'T'}
7070
]
7171
})
@@ -74,10 +74,10 @@ console.log(
7474

7575
## API
7676

77-
This package exports the identifier [`toString`][tostring].
77+
This package exports the identifier [`toString`][api-to-string].
7878
There is no default export.
7979

80-
### `toString(value[, separator])`
80+
### `toString(value)`
8181

8282
Get the text content of a node or list of nodes.
8383

@@ -86,10 +86,8 @@ if the given value is an array, serialize the nodes in it.
8686

8787
###### Parameters
8888

89-
* `node` ([`Node`][node] or `Array<Node>`)
90-
— node to serialize.
91-
* `separator` (`string`, default: `''`)
92-
— value to delimit each item
89+
* `node` ([`Array<Node>`][node] or `Node`)
90+
— node or list of nodes to serialize
9391

9492
###### Returns
9593

@@ -173,4 +171,4 @@ abide by its terms.
173171

174172
[node]: https://github.com/syntax-tree/nlcst#nodes
175173

176-
[tostring]: #tostringvalue-separator
174+
[api-to-string]: #tostringvalue

test.js

+2-16
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ test('toString', async function (t) {
1414
assert.throws(function () {
1515
// @ts-expect-error: check how the runtime handles no node.
1616
toString()
17-
})
17+
}, /Expected node/)
1818
})
1919

2020
await t.test('should throw when not given a node (#2)', async function () {
2121
assert.throws(function () {
2222
// @ts-expect-error: check how the runtime handles no `type`.
2323
toString({value: 'foo'})
24-
})
24+
}, /Expected node/)
2525
})
2626

2727
await t.test('should support texts', async function () {
@@ -61,20 +61,6 @@ test('toString', async function (t) {
6161
)
6262
})
6363

64-
await t.test('should support separators', async function () {
65-
assert.equal(
66-
toString(
67-
u('WordNode', [
68-
u('TextNode', 'AT'),
69-
u('SymbolNode', '&'),
70-
u('TextNode', 'T')
71-
]),
72-
','
73-
),
74-
'AT,&,T'
75-
)
76-
})
77-
7864
await t.test('should support voids', async function () {
7965
assert.equal(
8066
toString(

0 commit comments

Comments
 (0)