Skip to main content
Module

x/nanocolors/test/size.js

2x times faster than chalk and use 5x less space in node_modules
Latest
File
#!/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('colorette') await benchmark('nanocolors')}
start()