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 29, 2018
1 parent 41a01ce commit 6c2c407
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
svg-tag-names.js
svg-tag-names.min.js
72 changes: 39 additions & 33 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
'use strict';
'use strict'

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

var urls = [
'https://www.w3.org/TR/SVG11/eltindex.html',
'https://www.w3.org/TR/SVGTiny12/elementTable.html',
'https://www.w3.org/TR/SVG2/eltindex.html'
]

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

var proc = unified().use(parse);
var count = 0

var count = 0;
urls.forEach(each)

[
"https://www.w3.org/TR/SVG11/eltindex.html",
"https://www.w3.org/TR/SVGTiny12/elementTable.html",
"https://www.w3.org/TR/SVG2/eltindex.html"
].forEach(function (url, c, all) {
https.get(url, function (res) {
res.pipe(concat(onconcat)).on("error", bail);
function each(url) {
https.get(url, onconnection)
}

function onconnection(res) {
res.pipe(concat(onconcat)).on("error", bail)
}

function onconcat(buf) {
selectAll(".element-name", proc.parse(buf)).forEach(each);
function onconcat(buf) {
selectAll(".element-name", proc.parse(buf)).forEach(add)

count++;
count++

if (count === all.length) {
fs.writeFile("index.json", JSON.stringify(list.sort(), 0, 2) + "\n", bail);
}
if (count === urls.length) {
fs.writeFile("index.json", JSON.stringify(list.sort(), 0, 2) + "\n", bail)
}

function each(node) {
var data = toString(node).slice(1, -1);
function add(node) {
var data = toString(node).slice(1, -1)

if (data && list.indexOf(data) === -1) {
list.push(data);
}
}
if (data && list.indexOf(data) === -1) {
list.push(data)
}
});
});
}
}
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"esmangle": "^1.0.1",
"hast-util-select": "^1.0.1",
"hast-util-to-string": "^1.0.0",
"prettier": "^1.12.1",
"rehype-parse": "^4.0.0",
"remark-cli": "^5.0.0",
"remark-preset-wooorm": "^4.0.0",
Expand All @@ -37,17 +38,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 svgTagNames > svg-tag-names.js",
"build-mangle": "esmangle svg-tag-names.js > svg-tag-names.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",
"test": "npm run build && npm run lint && npm run test-api"
"test": "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
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ npm install svg-tag-names
## Usage

```javascript
var svgTagNames = require("svg-tag-names");
var svgTagNames = require("svg-tag-names")

svgTagNames.length; //=> 101
console.log(svgTagNames.length) // => 101

console.log(svgTagNames.slice(0, 20));
console.log(svgTagNames.slice(0, 20))
```

Yields:
Expand Down
20 changes: 10 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use strict";
"use strict"

var test = require("tape");
var svgTagNames = require(".");
var test = require("tape")
var svgTagNames = require(".")

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

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

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

0 comments on commit 6c2c407

Please sign in to comment.