forked from ai/nanocolors
/
size.js
executable file
·47 lines (41 loc) · 1015 Bytes
/
size.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
#!/usr/bin/env node
import { get } from 'https'
import { bold, gray } from '../index.js'
async function getJSON(url) {
return new Promise(resolve => {
get(url, res => {
let text = ''
res.on('data', chunk => {
text += chunk
})
res.on('end', () => {
resolve(JSON.parse(text))
})
})
})
}
async function benchmark(lib) {
let data = await getJSON(`https://packagephobia.com/v2/api.json?p=${lib}`)
let size = data.install.bytes
process.stdout.write(
lib.padEnd('ansi-colors '.length) +
bold(
Math.round(size / 1024)
.toString()
.padStart(4)
) +
' kB\n'
)
}
async function start() {
process.stdout.write(gray('Data from packagephobia.com\n'))
await benchmark('chalk')
await benchmark('cli-color')
await benchmark('ansi-colors')
await benchmark('kleur')
await benchmark('felt-pen')
await benchmark('colorette')
await benchmark('nanocolors')
await benchmark('forkcolours')
}
start()