MCPcopy Create free account
hub / github.com/binux/qiandao / formatProperty

Function formatProperty

web/static/node_components.js:3210–3266  ·  view source on GitHub ↗
(ctx, value, recurseTimes, visibleKeys, key, array)

Source from the content-addressed store, hash-verified

3208
3209
3210function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
3211 var name, str, desc;
3212 desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
3213 if (desc.get) {
3214 if (desc.set) {
3215 str = ctx.stylize('[Getter/Setter]', 'special');
3216 } else {
3217 str = ctx.stylize('[Getter]', 'special');
3218 }
3219 } else {
3220 if (desc.set) {
3221 str = ctx.stylize('[Setter]', 'special');
3222 }
3223 }
3224 if (!hasOwnProperty(visibleKeys, key)) {
3225 name = '[' + key + ']';
3226 }
3227 if (!str) {
3228 if (ctx.seen.indexOf(desc.value) < 0) {
3229 if (isNull(recurseTimes)) {
3230 str = formatValue(ctx, desc.value, null);
3231 } else {
3232 str = formatValue(ctx, desc.value, recurseTimes - 1);
3233 }
3234 if (str.indexOf('\n') > -1) {
3235 if (array) {
3236 str = str.split('\n').map(function(line) {
3237 return ' ' + line;
3238 }).join('\n').substr(2);
3239 } else {
3240 str = '\n' + str.split('\n').map(function(line) {
3241 return ' ' + line;
3242 }).join('\n');
3243 }
3244 }
3245 } else {
3246 str = ctx.stylize('[Circular]', 'special');
3247 }
3248 }
3249 if (isUndefined(name)) {
3250 if (array && key.match(/^\d+$/)) {
3251 return str;
3252 }
3253 name = JSON.stringify('' + key);
3254 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
3255 name = name.substr(1, name.length - 2);
3256 name = ctx.stylize(name, 'name');
3257 } else {
3258 name = name.replace(/'/g, "\\'")
3259 .replace(/\\"/g, '"')
3260 .replace(/(^"|"$)/g, "'");
3261 name = ctx.stylize(name, 'string');
3262 }
3263 }
3264
3265 return name + ': ' + str;
3266}
3267

Callers 2

formatValueFunction · 0.85
formatArrayFunction · 0.85

Calls 5

hasOwnPropertyFunction · 0.85
isNullFunction · 0.85
formatValueFunction · 0.85
joinMethod · 0.80
isUndefinedFunction · 0.70

Tested by

no test coverage detected