src/utils.js
function cleanCode(str) {
  str = str
    .replace(/\r\n|[\r\n\u2028\u2029]/g, '\n') // unify linebreaks
    .replace(/^\uFEFF/, ''); // replace zero-width no-break space

  str = stripFnStart(str) // replace function declaration
    .replace(/\)\s*\)\s*$/, ')') // replace closing paren
    .replace(/\s*};?\s*$/, ''); // replace closing bracket

  // Preserve indentation by finding leading tabs/spaces
  // and removing that amount of space from each line
  const spaces = str.match(/^\n?( *)/)[1].length;
  const tabs = str.match(/^\n?(\t*)/)[1].length;
  /* istanbul ignore next */
  const indentRegex = new RegExp(`^\n?${tabs ? '\t' : ' '}{${tabs || spaces}}`, 'gm');

  str = str.replace(indentRegex, '').trim();
  return str;
}
function cleanCode(str) {
  str = str
    .replace(/\r\n|[\r\n\u2028\u2029]/g, '\n') // unify linebreaks
    .replace(/^\uFEFF/, ''); // replace zero-width no-break space

  str = stripFnStart(str) // replace function declaration
    .replace(/\)\s*\)\s*$/, ')') // replace closing paren
    .replace(/\s*};?\s*$/, ''); // replace closing bracket

  // Preserve indentation by finding leading tabs/spaces
  // and removing that amount of space from each line
  const spaces = str.match(/^\n?( *)/)[1].length;
  const tabs = str.match(/^\n?(\t*)/)[1].length;
  /* istanbul ignore next */
  const indentRegex = new RegExp(`^\n?${tabs ? '\t' : ' '}{${tabs || spaces}}`, 'gm');

  str = str.replace(indentRegex, '').trim();
  return str;
}
function cleanCode ( str ) { str = str . replace ( / \r\n|[\r\n\u2028\u2029] / g , '\n' ) // unify linebreaks . replace ( / ^\uFEFF / , '' ) ; // replace zero-width no-break space str = stripFnStart ( str ) // replace function declaration . replace ( / \)\s*\)\s*$ / , ')' ) // replace closing paren . replace ( / \s*};?\s*$ / , '' ) ; // replace closing bracket // Preserve indentation by finding leading tabs/spaces // and removing that amount of space from each line const spaces = str . match ( / ^\n?( *) / ) [ 1 ] . length ; const tabs = str . match ( / ^\n?(\t*) / ) [ 1 ] . length ; /* istanbul ignore next */ const indentRegex = new RegExp ( ` \n ${ tabs ? '\t' : ' ' } ${ tabs || spaces } ` , 'gm' ) ; str = str . replace ( indentRegex , '' ) . trim ( ) ; return str ; }
Strip the function definition from `str`,
and re-indent for pre whitespace.

@param {String} str - code in

@return {String} cleaned code string
Strip the function definition from str and re - indent for pre whitespace .