MCPcopy Create free account
hub / github.com/rafeca/prettyjson / addColorToData

Function addColorToData

lib/prettyjson.js:41–78  ·  view source on GitHub ↗
(input, options)

Source from the content-addressed store, hash-verified

39};
40
41var addColorToData = function(input, options) {
42 if (options.noColor) {
43 return input;
44 }
45
46 if (typeof input === 'string') {
47 // Print strings in regular terminal color
48 return options.stringColor ? colors[options.stringColor](input) : input;
49 }
50
51 var sInput = input + '';
52
53 if (input === true) {
54 return colors.green(sInput);
55 }
56 if (input === false) {
57 return colors.red(sInput);
58 }
59 if (input === null || input === undefined) {
60 return colors.grey(sInput);
61 }
62 if (typeof input === 'number') {
63 if (input >= 0) {
64 return colors[options.positiveNumberColor](sInput);
65 } else {
66 return colors[options.negativeNumberColor](sInput);
67 }
68 }
69 if (typeof input === 'function') {
70 return 'function() {}';
71 }
72
73 if (Array.isArray(input)) {
74 return input.join(', ');
75 }
76
77 return sInput;
78};
79
80var colorMultilineString = function(options, line) {
81 if (options.multilineStringColor === null || options.noColor) {

Callers 1

renderToArrayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…