forked from 1995parham/github-do-not-ban-us
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.js
26 lines (25 loc) · 834 Bytes
/
sort.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
const { promises: { readFile, writeFile } } = require('fs');
(async () => {
let supportorsStart = false
let supporters = []
const readme = await readFile('README.md')
let newReadme = []
String(readme)
.split('\n')
.forEach(line => {
if (line === '## Supporters (list sorted alphabetically)') {
supportorsStart = true
newReadme.push(line)
}
if (!supportorsStart) {
newReadme.push(line)
} else if (line.startsWith('- ')) {
supporters.push(line)
}
})
await writeFile('README.md', newReadme.concat('', supporters
.sort((a, b) => {
let [bufa, bufb] = [Buffer.from(a.toLowerCase()), Buffer.from(b.toLowerCase())]
return Number(bufa.readBigUInt64BE(2) - bufb.readBigUInt64BE(2))
})).join('\n').concat('\n'))
})().catch(console.error)