forked from words/buzzwords
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
65 lines (56 loc) · 1.65 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import fs from 'fs'
import https from 'https'
import {bail} from 'bail'
import concat from 'concat-stream'
import unified from 'unified'
import parse from 'rehype-parse'
// @ts-ignore remove when typed
import $ from 'hast-util-select'
// @ts-ignore remove when typed
import toString from 'hast-util-to-string'
https.get('https://en.wikipedia.org/wiki/Buzzword', onresponse)
/**
* @param {import('http').IncomingMessage} response
*/
function onresponse(response) {
response.pipe(concat(onconcat)).on('error', bail)
}
/**
* @param {Buffer} buf
*/
function onconcat(buf) {
var tree = unified().use(parse).parse(buf)
var values = $.selectAll('.div-col > ul li', tree)
.map(function (/** @type {import('hast').Element} */ node) {
return toString(node.children[0])
})
.map(function (/** @type {string} */ value) {
// Split comment from buzzword.
var match = value.match(/^([\s\S+]+?)( [-–/] ?|\(|,)/)
if (match) {
value = match[1]
}
// Remove abbreviation from buzzword.
value = value.replace(/^[A-Z]+[-–/] /, '')
// Remove multiple cases.
value = value.replace(/\/\w.+/, '')
return value.toLowerCase().trim()
})
.filter(function (/** @type {string} */ value) {
var head = value.charAt(0)
return value !== 'uc' && head !== '-' && head !== '_'
})
.filter(function (
/** @type {string} */ value,
/** @type {number} */ index,
/** @type {Array.<string>} */ all
) {
return all.indexOf(value) === index
})
.sort()
fs.writeFile(
'index.js',
'export var buzzwords = ' + JSON.stringify(values, null, 2) + '\n',
bail
)
}