Skip to content

Commit 454e368

Browse files
committed
Refactor code-style
1 parent 17dbde1 commit 454e368

File tree

5 files changed

+70
-72
lines changed

5 files changed

+70
-72
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
nlcst-to-string.js
3+
nlcst-to-string.min.js

index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
'use strict';
1+
'use strict'
22

3-
module.exports = nlcstToString;
3+
module.exports = nlcstToString
44

55
/* Stringify a NLCST node or list of nodes. */
66
function nlcstToString(node, separator) {
7-
var sep = separator || '';
8-
var values;
9-
var length;
10-
var children;
7+
var sep = separator || ''
8+
var values
9+
var length
10+
var children
1111

1212
if (!node || (!('length' in node) && !node.type)) {
13-
throw new Error('Expected node, not `' + node + '`');
13+
throw new Error('Expected node, not `' + node + '`')
1414
}
1515

1616
if (typeof node.value === 'string') {
17-
return node.value;
17+
return node.value
1818
}
1919

20-
children = 'length' in node ? node : node.children;
21-
length = children.length;
20+
children = 'length' in node ? node : node.children
21+
length = children.length
2222

2323
/* Shortcut: This is pretty common, and a small performance win. */
2424
if (length === 1 && 'value' in children[0]) {
25-
return children[0].value;
25+
return children[0].value
2626
}
2727

28-
values = [];
28+
values = []
2929

3030
while (length--) {
31-
values[length] = nlcstToString(children[length], sep);
31+
values[length] = nlcstToString(children[length], sep)
3232
}
3333

34-
return values.join(sep);
34+
return values.join(sep)
3535
}

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,38 @@
2424
"browserify": "^16.0.0",
2525
"esmangle": "^1.0.1",
2626
"nyc": "^11.0.0",
27+
"prettier": "^1.12.1",
2728
"remark-cli": "^5.0.0",
2829
"remark-preset-wooorm": "^4.0.0",
2930
"tape": "^4.0.0",
3031
"unist-builder": "^1.0.1",
3132
"xo": "^0.20.0"
3233
},
3334
"scripts": {
34-
"build-md": "remark . --quiet --frail --output",
35+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3536
"build-bundle": "browserify index.js --bare -s nlcstToString > nlcst-to-string.js",
3637
"build-mangle": "esmangle nlcst-to-string.js > nlcst-to-string.min.js",
37-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
38-
"lint": "xo",
39-
"test-api": "node test.js",
38+
"build": "npm run build-bundle && npm run build-mangle",
39+
"test-api": "node test",
4040
"test-coverage": "nyc --reporter lcov tape test.js",
41-
"test": "npm run build && npm run lint && npm run test-coverage"
41+
"test": "npm run format && npm run build && npm run test-coverage"
4242
},
4343
"nyc": {
4444
"check-coverage": true,
4545
"lines": 100,
4646
"functions": 100,
4747
"branches": 100
4848
},
49+
"prettier": {
50+
"tabWidth": 2,
51+
"useTabs": false,
52+
"singleQuote": true,
53+
"bracketSpacing": false,
54+
"semi": false,
55+
"trailingComma": "none"
56+
},
4957
"xo": {
50-
"space": true,
58+
"prettier": true,
5159
"esnext": false,
5260
"rules": {
5361
"guard-for-in": "off",

readme.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ npm install nlcst-to-string
1313
## Usage
1414

1515
```javascript
16-
var toString = require('nlcst-to-string');
17-
18-
console.log(toString({
19-
type: 'WordNode',
20-
children: [
21-
{type: 'TextNode', value: 'AT'},
22-
{type: 'PunctuationNode', value: '&'},
23-
{type: 'TextNode', value: 'T'}
24-
]
25-
})); //=> 'AT&T'
16+
var toString = require('nlcst-to-string')
17+
18+
console.log(
19+
toString({
20+
type: 'WordNode',
21+
children: [
22+
{type: 'TextNode', value: 'AT'},
23+
{type: 'PunctuationNode', value: '&'},
24+
{type: 'TextNode', value: 'T'}
25+
]
26+
})
27+
) // => 'AT&T'
2628
```
2729

2830
## API

test.js

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,56 @@
1-
'use strict';
1+
'use strict'
22

3-
var test = require('tape');
4-
var u = require('unist-builder');
5-
var toString = require('.');
3+
var test = require('tape')
4+
var u = require('unist-builder')
5+
var toString = require('.')
66

7-
test('toString()', function (t) {
7+
test('toString()', function(t) {
88
t.throws(
9-
function () {
10-
toString();
9+
function() {
10+
toString()
1111
},
1212
/undefined/,
1313
'should throw when not given a node (#1)'
14-
);
14+
)
1515

1616
t.throws(
17-
function () {
18-
toString({value: 'foo'});
17+
function() {
18+
toString({value: 'foo'})
1919
},
2020
/\[object Object]/,
2121
'should throw when not given a node (#2)'
22-
);
22+
)
2323

24-
t.equal(
25-
toString(u('foo', 'AT')),
26-
'AT',
27-
'should support texts'
28-
);
24+
t.equal(toString(u('foo', 'AT')), 'AT', 'should support texts')
2925

3026
t.equal(
31-
toString(u('foo', [
32-
u('bar', 'AT'),
33-
u('bar', '&'),
34-
u('bar', 'T')
35-
])),
27+
toString(u('foo', [u('bar', 'AT'), u('bar', '&'), u('bar', 'T')])),
3628
'AT&T',
3729
'should support parents'
38-
);
30+
)
3931

4032
t.equal(
41-
toString([
42-
u('bar', 'AT'),
43-
u('bar', '&'),
44-
u('bar', 'T')
45-
]),
33+
toString([u('bar', 'AT'), u('bar', '&'), u('bar', 'T')]),
4634
'AT&T',
4735
'should support nodes'
48-
);
36+
)
4937

5038
t.equal(
51-
toString(u('foo', [
52-
u('bar', 'AT'),
53-
u('foo', [u('bar', '&')]),
54-
u('bar', 'T')
55-
])),
39+
toString(
40+
u('foo', [u('bar', 'AT'), u('foo', [u('bar', '&')]), u('bar', 'T')])
41+
),
5642
'AT&T',
5743
'should support parents with mixed children'
58-
);
44+
)
5945

6046
t.equal(
61-
toString(u('foo', [
62-
u('bar', 'AT'),
63-
u('foo', [u('bar', '&')]),
64-
u('bar', 'T')
65-
]), ','),
47+
toString(
48+
u('foo', [u('bar', 'AT'), u('foo', [u('bar', '&')]), u('bar', 'T')]),
49+
','
50+
),
6651
'AT,&,T',
6752
'should support separators'
68-
);
53+
)
6954

70-
t.end();
71-
});
55+
t.end()
56+
})

0 commit comments

Comments
 (0)