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

Function joinCollection

lib/formatter.js:216–243  ·  view source on GitHub ↗
(ctx, entries, b1, b2, insideObject)

Source from the content-addressed store, hash-verified

214
215
216function joinCollection(ctx, entries, b1, b2, insideObject) {
217 if (entries.length === 0) {
218 return b1 + ctx.space + b2;
219 }
220 var shouldWrap = false;
221 var length = b1.length + b2.length;
222 if (ctx.wrapWidth >= 0) {
223 length += (entries.length - 1) * (1 + ctx.space.length); // separators
224 for(var i = 0, l = entries.length; i < l; i++) {
225 length += (entries[i].real_length || entries[i].length);
226 if (length > ctx.wrapWidth) {
227 shouldWrap = true;
228 break;
229 }
230 }
231 }
232
233 var ret;
234 if (shouldWrap) {
235 ret = b1 + ctx.cr + ctx.indent + entries.join(',' + ctx.cr + ctx.indent) + ctx.cr + b2;
236 } else {
237 var sp = insideObject ? ctx.space : '';
238 ret = b1 + sp + entries.join(',' + ctx.space) + sp + b2;
239 ret = new String(ret);
240 ret.real_length = length; // needed for correct line wrapping in the presence of ANSI color escapes
241 }
242 return ret;
243}
244
245function formatArray(ctx, value) {
246 ctx.seen.push(value);

Callers 2

formatArrayFunction · 0.85
formatObjectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected