MCPcopy Index your code
hub / github.com/ddopson/underscore-cli / formatObject

Function formatObject

lib/formatter.js:269–303  ·  view source on GitHub ↗
(ctx, value, type)

Source from the content-addressed store, hash-verified

267}
268
269function formatObject(ctx, value, type) {
270 ctx.seen.push(value);
271
272 var visibleKeys = Object.keys(value);
273 var output = visibleKeys.map(function(key) {
274 if (type === 'array' && key.match(/^\d+$/)) {
275 return null;
276 }
277 return formatProperty(ctx, value, key, false, false);
278 });
279
280 if (ctx.showHidden) {
281 var touched = {};
282 visibleKeys.map(function(key) {
283 touched[key] = true;
284 });
285 var allKeys = Object.getOwnPropertyNames(value);
286 allKeys.map(function (key) {
287 if (! touched[key]) {
288 output.push(formatProperty(ctx, value, key, true, false));
289 }
290 });
291 }
292
293 // skip nulls (keys which are being ignored by current config)
294 output = _.filter(output, function (v) { return v !== null; });
295
296 ctx.seen.pop();
297
298 if (type !== 'object' && output.length === 0) {
299 return '';
300 } else {
301 return joinCollection(ctx, output, '{', '}', true);
302 }
303}
304
305function formatProperty(ctx, obj, key, isPrivate, inside_array) {
306 if (ctx.jsonParity && obj[key] === undefined) {

Callers 1

formatValueFunction · 0.85

Calls 2

formatPropertyFunction · 0.85
joinCollectionFunction · 0.85

Tested by

no test coverage detected