Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 14, 2018
1 parent b77a6fa commit f3c0214
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
@@ -0,0 +1,2 @@
html-void-elements.js
html-void-elements.min.js
50 changes: 27 additions & 23 deletions build.js
@@ -1,31 +1,35 @@
'use strict';
'use strict'

var fs = require('fs');
var https = require('https');
var concat = require('concat-stream');
var unified = require('unified');
var html = require('rehype-parse');
var q = require('hast-util-select');
var toString = require('hast-util-to-string');
var bail = require('bail');
var list = require('.');
var fs = require('fs')
var https = require('https')
var concat = require('concat-stream')
var unified = require('unified')
var html = require('rehype-parse')
var q = require('hast-util-select')
var toString = require('hast-util-to-string')
var bail = require('bail')
var list = require('.')

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

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

q.selectAll('code', dl).forEach(each);
function onconnection(res) {
res.pipe(concat(onconcat)).on('error', bail)
}

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

function each(node) {
var data = toString(node);
q.selectAll('code', dl).forEach(each)

if (data && !/\s/.test(data) && list.indexOf(data) === -1) {
list.push(data);
}
}
fs.writeFile('index.json', JSON.stringify(list.sort(), 0, 2) + '\n', bail)
}

function each(node) {
var data = toString(node)

if (data && !/\s/.test(data) && list.indexOf(data) === -1) {
list.push(data)
}
});
}
19 changes: 14 additions & 5 deletions package.json
Expand Up @@ -31,6 +31,7 @@
"esmangle": "^1.0.0",
"hast-util-select": "^1.0.1",
"hast-util-to-string": "^1.0.0",
"prettier": "^1.12.0",
"rehype-parse": "^4.0.0",
"remark-cli": "^5.0.0",
"remark-preset-wooorm": "^4.0.0",
Expand All @@ -39,17 +40,25 @@
"xo": "^0.20.0"
},
"scripts": {
"build-md": "remark . -qfo",
"build-crawl": "node build",
"generate": "node build",
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
"build-bundle": "browserify index.json --bare -s htmlVoidElements > html-void-elements.js",
"build-mangle": "esmangle html-void-elements.js > html-void-elements.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"build": "npm run build-bundle && npm run build-mangle",
"lint": "xo",
"test-api": "node test.js",
"test": "npm run build && npm run lint && npm run test-api"
"test": "npm run generate && npm run format && npm run build && npm run test-api"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"space": true,
"prettier": true,
"esnext": false,
"rules": {
"no-var": "off",
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Expand Up @@ -18,9 +18,9 @@ npm install html-void-elements
## Usage

```javascript
var htmlVoidElements = require('html-void-elements');
var htmlVoidElements = require('html-void-elements')

console.log(htmlVoidElements);
console.log(htmlVoidElements)
```

Yields:
Expand Down
27 changes: 10 additions & 17 deletions test.js
@@ -1,21 +1,14 @@
'use strict';
'use strict'

var test = require('tape');
var htmlVoidElements = require('.');
var test = require('tape')
var htmlVoidElements = require('.')

test('htmlVoidElements', function (t) {
t.ok(
Array.isArray(htmlVoidElements),
'should be an `array`'
);
test('htmlVoidElements', function(t) {
t.ok(Array.isArray(htmlVoidElements), 'should be an `array`')

htmlVoidElements.forEach(function (tagName) {
t.equal(
typeof tagName,
'string',
'`' + tagName + '` should be a string'
);
});
htmlVoidElements.forEach(function(tagName) {
t.equal(typeof tagName, 'string', '`' + tagName + '` should be a string')
})

t.end();
});
t.end()
})

0 comments on commit f3c0214

Please sign in to comment.