Skip to content

Commit f3c0214

Browse files
committed
Refactor code-style
1 parent b77a6fa commit f3c0214

File tree

5 files changed

+55
-47
lines changed

5 files changed

+55
-47
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
html-void-elements.js
2+
html-void-elements.min.js

build.js

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

3-
var fs = require('fs');
4-
var https = require('https');
5-
var concat = require('concat-stream');
6-
var unified = require('unified');
7-
var html = require('rehype-parse');
8-
var q = require('hast-util-select');
9-
var toString = require('hast-util-to-string');
10-
var bail = require('bail');
11-
var list = require('.');
3+
var fs = require('fs')
4+
var https = require('https')
5+
var concat = require('concat-stream')
6+
var unified = require('unified')
7+
var html = require('rehype-parse')
8+
var q = require('hast-util-select')
9+
var toString = require('hast-util-to-string')
10+
var bail = require('bail')
11+
var list = require('.')
1212

13-
https.get('https://html.spec.whatwg.org/multipage/syntax.html#elements-2', function (res) {
14-
res.pipe(concat(onconcat)).on('error', bail);
13+
var proc = unified().use(html)
1514

16-
function onconcat(buf) {
17-
var dl = q.select('#elements-2 ~ dl dd', unified().use(html).parse(buf));
15+
https.get('https://html.spec.whatwg.org/multipage/syntax.html', onconnection)
1816

19-
q.selectAll('code', dl).forEach(each);
17+
function onconnection(res) {
18+
res.pipe(concat(onconcat)).on('error', bail)
19+
}
2020

21-
fs.writeFile('index.json', JSON.stringify(list.sort(), 0, 2) + '\n', bail);
21+
function onconcat(buf) {
22+
var dl = q.select('#elements-2 ~ dl dd', proc.parse(buf))
2223

23-
function each(node) {
24-
var data = toString(node);
24+
q.selectAll('code', dl).forEach(each)
2525

26-
if (data && !/\s/.test(data) && list.indexOf(data) === -1) {
27-
list.push(data);
28-
}
29-
}
26+
fs.writeFile('index.json', JSON.stringify(list.sort(), 0, 2) + '\n', bail)
27+
}
28+
29+
function each(node) {
30+
var data = toString(node)
31+
32+
if (data && !/\s/.test(data) && list.indexOf(data) === -1) {
33+
list.push(data)
3034
}
31-
});
35+
}

package.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"esmangle": "^1.0.0",
3232
"hast-util-select": "^1.0.1",
3333
"hast-util-to-string": "^1.0.0",
34+
"prettier": "^1.12.0",
3435
"rehype-parse": "^4.0.0",
3536
"remark-cli": "^5.0.0",
3637
"remark-preset-wooorm": "^4.0.0",
@@ -39,17 +40,25 @@
3940
"xo": "^0.20.0"
4041
},
4142
"scripts": {
42-
"build-md": "remark . -qfo",
43-
"build-crawl": "node build",
43+
"generate": "node build",
44+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
4445
"build-bundle": "browserify index.json --bare -s htmlVoidElements > html-void-elements.js",
4546
"build-mangle": "esmangle html-void-elements.js > html-void-elements.min.js",
46-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
47+
"build": "npm run build-bundle && npm run build-mangle",
4748
"lint": "xo",
4849
"test-api": "node test.js",
49-
"test": "npm run build && npm run lint && npm run test-api"
50+
"test": "npm run generate && npm run format && npm run build && npm run test-api"
51+
},
52+
"prettier": {
53+
"tabWidth": 2,
54+
"useTabs": false,
55+
"singleQuote": true,
56+
"bracketSpacing": false,
57+
"semi": false,
58+
"trailingComma": "none"
5059
},
5160
"xo": {
52-
"space": true,
61+
"prettier": true,
5362
"esnext": false,
5463
"rules": {
5564
"no-var": "off",

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ npm install html-void-elements
1818
## Usage
1919

2020
```javascript
21-
var htmlVoidElements = require('html-void-elements');
21+
var htmlVoidElements = require('html-void-elements')
2222

23-
console.log(htmlVoidElements);
23+
console.log(htmlVoidElements)
2424
```
2525

2626
Yields:

test.js

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

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

6-
test('htmlVoidElements', function (t) {
7-
t.ok(
8-
Array.isArray(htmlVoidElements),
9-
'should be an `array`'
10-
);
6+
test('htmlVoidElements', function(t) {
7+
t.ok(Array.isArray(htmlVoidElements), 'should be an `array`')
118

12-
htmlVoidElements.forEach(function (tagName) {
13-
t.equal(
14-
typeof tagName,
15-
'string',
16-
'`' + tagName + '` should be a string'
17-
);
18-
});
9+
htmlVoidElements.forEach(function(tagName) {
10+
t.equal(typeof tagName, 'string', '`' + tagName + '` should be a string')
11+
})
1912

20-
t.end();
21-
});
13+
t.end()
14+
})

0 commit comments

Comments
 (0)