mirror of
https://github.com/zhigang1992/nearestTailwindColor.git
synced 2026-01-12 22:40:10 +08:00
19 lines
481 B
JavaScript
19 lines
481 B
JavaScript
const {colors} = require('./colors');
|
|
|
|
const flattenedColor = {};
|
|
|
|
for (let colorsKey in colors) {
|
|
if (typeof colors[colorsKey] === "string") {
|
|
flattenedColor[colorsKey] = colors[colorsKey]
|
|
} else {
|
|
for (let nestedKey in colors[colorsKey]) {
|
|
flattenedColor[`${colorsKey}-${nestedKey}`] = colors[colorsKey][nestedKey];
|
|
}
|
|
}
|
|
}
|
|
|
|
const nearestColor = require('nearest-color').from(flattenedColor);
|
|
|
|
console.log(nearestColor('#F2F2F2'));
|
|
|