-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,38 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var http = require('http'); | ||
var bail = require('bail'); | ||
var jsdom = require('jsdom'); | ||
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'); | ||
|
||
jsdom.env('http://www.readabilityformulas.com/articles/spache-formula-word-list.php', read); | ||
http.get('http://www.readabilityformulas.com/articles/spache-formula-word-list.php', function (res) { | ||
res.pipe(concat(onconcat)).on('error', bail); | ||
|
||
function read(err, window) { | ||
bail(err); | ||
function onconcat(buf) { | ||
var tree = unified().use(parse).parse(buf); | ||
var values = selectAll('td p', tree) | ||
.map(toString) | ||
.join('|') | ||
.replace(/\\/g, '$&\'') | ||
.trim() | ||
.split(/\s*\|\s*/g) | ||
.filter(Boolean) | ||
.map(lower) | ||
.filter(unique) | ||
.sort(); | ||
|
||
var values = [].slice.call(window.document.querySelectorAll('td p')) | ||
.map(function (node) { | ||
return node.textContent; | ||
}) | ||
.join('|') | ||
.replace(/\\/g, '$&\'') | ||
.trim() | ||
.split(/\s*\|\s*/g) | ||
.filter(Boolean) | ||
.map(function (value) { | ||
return value.toLowerCase(); | ||
}) | ||
.sort(); | ||
fs.writeFile('index.json', JSON.stringify(values, 0, 2) + '\n', bail); | ||
} | ||
}); | ||
|
||
values = values.filter(function (value, index) { | ||
return values.indexOf(value, index + 1) === -1; | ||
}); | ||
function lower(value) { | ||
return value.toLowerCase(); | ||
} | ||
|
||
fs.writeFileSync('index.json', JSON.stringify(values, 0, 2) + '\n'); | ||
function unique(value, index, all) { | ||
return all.indexOf(value, index + 1) === -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters