Plato on Github
Report Home
node_modules/cli-color/lib/xterm-match.js
Maintainability
75.26
Lines of code
40
Difficulty
21.80
Estimated Errors
0.36
Function weight
By Complexity
By SLOC
'use strict'; var push = Array.prototype.push, reduce = Array.prototype.reduce, abs = Math.abs , colors, match, result, i; colors = require('./xterm-colors').map(function (color) { return { r: parseInt(color.slice(0, 2), 16), g: parseInt(color.slice(2, 4), 16), b: parseInt(color.slice(4), 16) }; }); match = colors.slice(0, 16); module.exports = result = []; i = 0; while (i < 8) { result.push(30 + i++); } i = 0; while (i < 8) { result.push(90 + i++); } push.apply(result, colors.slice(16).map(function (data) { var index, diff = Infinity; match.every(function (match, i) { var ndiff = reduce.call('rgb', function (diff, channel) { diff += abs(match[channel] - data[channel]); return diff; }, 0); if (ndiff < diff) { index = i; diff = ndiff; } return ndiff; }); return result[index]; }));