UNPKG

html-colors

Version:

Get a list of all the HTML and CSS color names and their hex values.

32 lines (26 loc) 603 B
'use strict'; const uniqueRandomArray = require('unique-random-array'); const htmlColors = require('./html-colors.json'); function names() { return Object.keys(htmlColors); } function hex(name) { if (typeof name !== 'string') { throw new TypeError('htmlColors.hex expected a string, got ' + typeof name); } return htmlColors[name.toLowerCase()]; } function all() { return htmlColors; } function random() { const keys = Object.keys(htmlColors); const randomColor = uniqueRandomArray(keys); return randomColor(); } module.exports = { names: names, hex: hex, all: all, random: random };