-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiff.js
More file actions
53 lines (44 loc) · 1.03 KB
/
diff.js
File metadata and controls
53 lines (44 loc) · 1.03 KB
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
'use strict'
const fs = require('fs')
const path = require('path')
const gfm = require('./gfm.json')
const diff = {
_: {}
}
// function read(name) {
// return fs.readFileSync(path.join(__dirname, name)).toString()
// }
function write(filepath, content) {
fs.writeFileSync(path.join(__dirname, filepath), content)
}
function _set(name, value, pass) {
const count = diff._
if (count[name]) {
count[name].total++
} else {
count[name] = {
total: 1,
pass: 0,
percent: 0,
diff: 0,
diffList: []
}
}
if (pass) {
count[name].pass++
} else {
count[name].diff++
count[name].diffList.push(value.example)
if (diff[name]) {
diff[name].push(value)
} else {
diff[name] = [value]
}
}
count[name].percent = ((count[name].pass / count[name].total) * 100).toFixed(2) + '%'
}
gfm.forEach(item => {
const {section, ...value} = item
_set(section, value, (item._html || item.html) === (item._zzmd || item.zzmd))
})
write('diff.json', JSON.stringify(diff, null, ' '))