Skip to content

Commit

Permalink
Add script to convert RGB to hex
Browse files Browse the repository at this point in the history
  • Loading branch information
spenserblack committed Jul 7, 2022
1 parent 4988dcb commit c745b64
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions rgb-to-hex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node
const yaml = require('js-yaml');
const fs = require('fs');

const input = fs.readFileSync(process.argv[2], 'utf8');
const src = yaml.load(input);

const asHex = (channel) => channel.toString(16).toUpperCase().padStart(2, '0');

const convertedEntries = Object.entries(src)
.map(([language, { type, ascii, colors: { ansi, rgb, chip }}]) => {
const hex = rgb?.map(([r, g, b]) => `#${asHex(r)}${asHex(g)}${asHex(b)}`);
const hexChip = chip.reduce((s, channel) => `${s}${asHex(channel)}`, '#');
return [language, { type, ascii, colors: { ansi, hex, chip: hexChip }}];
});

const converted = yaml.dump(Object.fromEntries(convertedEntries));
console.log(converted);

0 comments on commit c745b64

Please sign in to comment.