Skip to content

Commit a75b405

Browse files
committed
Refactor code-style
1 parent a168fa1 commit a75b405

File tree

5 files changed

+49
-51
lines changed

5 files changed

+49
-51
lines changed

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
mdast-util-to-string.js
3+
mdast-util-to-string.min.js

index.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
'use strict';
1+
'use strict'
22

3-
/* Expose. */
4-
module.exports = toString;
3+
module.exports = toString
54

65
/* Get the text content of a node. If the node itself
76
* does not expose plain-text fields, `toString` will
87
* recursivly try its children. */
98
function toString(node) {
10-
return valueOf(node) ||
9+
return (
10+
valueOf(node) ||
1111
(node.children && node.children.map(toString).join('')) ||
12-
'';
12+
''
13+
)
1314
}
1415

1516
/* Get the value of `node`. Checks, `value`,
1617
* `alt`, and `title`, in that order. */
1718
function valueOf(node) {
18-
if (!node) {
19-
return '';
20-
}
21-
return node.value ? node.value : (node.alt ? node.alt : node.title) || '';
19+
return (
20+
(node && node.value ? node.value : node.alt ? node.alt : node.title) || ''
21+
)
2222
}

package.json

+14-6
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,32 @@
2525
"devDependencies": {
2626
"browserify": "^16.0.0",
2727
"nyc": "^12.0.0",
28+
"prettier": "^1.14.2",
2829
"remark-cli": "^5.0.0",
2930
"remark-preset-wooorm": "^4.0.0",
3031
"tape": "^4.4.0",
3132
"tinyify": "^2.4.3",
3233
"xo": "^0.22.0"
3334
},
3435
"scripts": {
35-
"build-md": "remark . --quiet --frail --output",
36+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3637
"build-bundle": "browserify . -s mdastUtilToString > mdast-util-to-string.js",
3738
"build-mangle": "browserify . -s mdastUtilToString -p tinyify > mdast-util-to-string.min.js",
38-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
39-
"lint": "xo",
40-
"test-api": "node test.js",
39+
"build": "npm run build-bundle && npm run build-mangle",
40+
"test-api": "node test",
4141
"test-coverage": "nyc --reporter lcov tape test.js",
42-
"test": "npm run build && npm run lint && npm run test-coverage"
42+
"test": "npm run format && npm run build && npm run test-coverage"
43+
},
44+
"prettier": {
45+
"tabWidth": 2,
46+
"useTabs": false,
47+
"singleQuote": true,
48+
"bracketSpacing": false,
49+
"semi": false,
50+
"trailingComma": "none"
4351
},
4452
"xo": {
45-
"space": true,
53+
"prettier": true,
4654
"esnext": false,
4755
"ignore": [
4856
"mdast-util-to-string.js"

readme.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ npm install mdast-util-to-string
1313
## Usage
1414

1515
```js
16-
var unified = require('unified');
17-
var parse = require('remark-parse');
18-
var toString = require('mdast-util-to-string');
16+
var unified = require('unified')
17+
var parse = require('remark-parse')
18+
var toString = require('mdast-util-to-string')
1919

2020
var tree = unified()
2121
.use(parse)
22-
.parse('Some _emphasis_, **importance**, and `code`.');
22+
.parse('Some _emphasis_, **importance**, and `code`.')
2323

24-
console.log(toString(tree)); //=> 'Some emphasis, importance, and code.'
24+
console.log(toString(tree)) // => 'Some emphasis, importance, and code.'
2525
```
2626

2727
## API

test.js

+18-31
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
'use strict';
1+
'use strict'
22

3-
var test = require('tape');
4-
var toString = require('.');
3+
var test = require('tape')
4+
var toString = require('.')
55

6-
test('mdast-util-to-string', function (t) {
7-
t.throws(
8-
function () {
9-
toString();
10-
},
11-
'should fail without node'
12-
);
6+
test('mdast-util-to-string', function(t) {
7+
t.throws(function() {
8+
toString()
9+
}, 'should fail without node')
1310

1411
t.equal(
1512
toString({value: 'foo'}),
1613
'foo',
1714
'should not fail on unrecognised nodes'
18-
);
15+
)
1916

2017
t.equal(
2118
toString({
@@ -24,23 +21,19 @@ test('mdast-util-to-string', function (t) {
2421
}),
2522
'foo',
2623
'should prefer `value` over all others'
27-
);
24+
)
2825

2926
t.equal(
30-
toString({
31-
value: 'foo',
32-
alt: 'bar',
33-
title: 'baz'
34-
}),
27+
toString({value: 'foo', alt: 'bar', title: 'baz'}),
3528
'foo',
3629
'should prefer `value` over `alt` or `title`'
37-
);
30+
)
3831

3932
t.equal(
4033
toString({alt: 'bar', title: 'baz'}),
4134
'bar',
4235
'should prefer `alt` over `title`'
43-
);
36+
)
4437

4538
t.equal(
4639
toString({
@@ -49,21 +42,15 @@ test('mdast-util-to-string', function (t) {
4942
}),
5043
'baz',
5144
'should use `title` over `children`'
52-
);
45+
)
5346

5447
t.equal(
55-
toString({
56-
children: [{value: 'foo'}, {alt: 'bar'}, {title: 'baz'}]
57-
}),
48+
toString({children: [{value: 'foo'}, {alt: 'bar'}, {title: 'baz'}]}),
5849
'foobarbaz',
5950
'should prefer `children`'
60-
);
51+
)
6152

62-
t.equal(
63-
toString({}),
64-
'',
65-
'should fall back on an empty string'
66-
);
53+
t.equal(toString({}), '', 'should fall back on an empty string')
6754

68-
t.end();
69-
});
55+
t.end()
56+
})

0 commit comments

Comments
 (0)