(target)
| 55 | |
| 56 | // return nearest color from array |
| 57 | function nearestColor(target) { |
| 58 | var lowest = Number.POSITIVE_INFINITY; |
| 59 | var tmp; |
| 60 | let res; |
| 61 | for (let color in colors) { |
| 62 | tmp = distance(target, hexToRgb(color)); |
| 63 | if (tmp < lowest) { |
| 64 | lowest = tmp; |
| 65 | res = color; |
| 66 | } |
| 67 | } |
| 68 | return colors[res]; |
| 69 | } |
| 70 | |
| 71 | function hexToRgb(hex) { |
| 72 | var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; |
no test coverage detected