src/serialize.js
function serializeList( elements, indent = INDENT, pad = 0, space ) {
   if( elements.length === 0 ) {
      return '';
   }

   const length = elements.reduce( ( sum, e ) => sum + e.length + 2, pad );
   const multiline = elements.some( element => /\n/.test( element ) );
   const compact = length < LIST_LENGTH && !multiline;

   const leader = compact ? ' ' : `\n${spaces( pad + indent, space )}`;
   const trailer = compact ? ' ' : `\n${spaces( pad, space )}`;
   const separator = `,${leader}`;

   const body = elements.join( separator );

   return `${leader}${body}${trailer}`;
}
function serializeList( elements, indent = INDENT, pad = 0, space ) {
   if( elements.length === 0 ) {
      return '';
   }

   const length = elements.reduce( ( sum, e ) => sum + e.length + 2, pad );
   const multiline = elements.some( element => /\n/.test( element ) );
   const compact = length < LIST_LENGTH && !multiline;

   const leader = compact ? ' ' : `\n${spaces( pad + indent, space )}`;
   const trailer = compact ? ' ' : `\n${spaces( pad, space )}`;
   const separator = `,${leader}`;

   const body = elements.join( separator );

   return `${leader}${body}${trailer}`;
}
function serializeList ( elements , indent = INDENT , pad = 0 , space ) { if ( elements . length === 0 ) { return '' ; } const length = elements . reduce ( ( sum , e ) => sum + e . length + 2 , pad ) ; const multiline = elements . some ( element => / \n / . test ( element ) ) ; const compact = length < LIST_LENGTH && ! multiline ; const leader = compact ? ' ' : ` \n ${ spaces ( pad + indent , space ) } ` ; const trailer = compact ? ' ' : ` \n ${ spaces ( pad , space ) } ` ; const separator = ` ${ leader } ` ; const body = elements . join ( separator ) ; return ` ${ leader } ${ body } ${ trailer } ` ; }
Serialize the body of a list or object.
@private
@param {Array<String>} elements the serialized elements or key-value pairs
@param {Number} [indent] the number of spaces to use for indent
@param {Number} [pad] the initial left padding
@param {String} [space] the character(s) to use for padding
@return {String} the serialized JavaScript code
Serialize the body of a list or object .