-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
61 lines (46 loc) · 1.72 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
const moment = require('moment')
const _ = require('lodash')
moment.suppressDeprecationWarnings = true;
function nFormatter(num, digits) {
const lookup = [
{ value: 1, symbol: "" },
{ value: 1e3, symbol: "k" },
{ value: 1e6, symbol: "M" },
{ value: 1e9, symbol: "G" },
{ value: 1e12, symbol: "T" },
{ value: 1e15, symbol: "P" },
{ value: 1e18, symbol: "E" }
];
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
var item = lookup.slice().reverse().find(function(item) {
return num >= item.value;
});
return item ? (num / item.value).toFixed(digits).replace(rx, "$1") + item.symbol : "0";
}
module.exports = (dataset) => {
var dates = _.uniq(dataset.map(a => moment(a.published)))
var minDate = moment.min(dates).format('LL')
var maxDate = moment.max(dates).format('LLL')
// var moments = this.state.dates.map(d => moment(d)),
var domains = _.uniq(dataset.map(a => a.domain))
var categories = _.uniq(dataset.map(a => a.category))
return `# Headline Dataset
- Dataset: [/headlines.json](https://raw.githubusercontent.com/fwd/news/master/headlines.json)
- Articles: ${nFormatter(dataset.length)}
- File Type: JSON
- File Size: ~**${Math.floor(dataset.size)}MB**
- Sources: ${nFormatter(domains.length)}
- Categories: ${nFormatter(categories.length)}
- Updated: ${dataset.timestamp}
\`\`\`
${JSON.stringify(_.first(dataset), null, 4)}
\`\`\`
---
### Visualization (Coming Soon)
![https://raw.githubusercontent.com/fwd/news/master/charts/chart-1.png](https://raw.githubusercontent.com/fwd/news/master/charts/chart-1.png)
### Contact
Twitter: [@nano2dev](https://twitter.com/nano2dev)
## Github Stars
[![Stargazers over time](https://starchart.cc/fwd/news.svg)](https://starchart.cc/fwd/news)
`
}