All files / src/utils stringifyWithFnName.ts

92.86% Statements 13/14
66.67% Branches 4/6
100% Functions 2/2
92.86% Lines 13/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  15x 15x 15x   2x 2x   154x   43x 43x 43x             111x   154x   2x   15x  
import isFn from "../preds/isFn";
import fnName from "./fnName";
 
export default function stringifyWithFnName( subject, currTransform?, indent? ) {
 
  const newArgs = Array.prototype.slice.call( arguments );
 
  newArgs[ 1 ] = ( key, val ) => {
    let r;
    if ( isFn( val ) ) {
      // implicitly `toString` it
      const En = fnName( val );
      if ( n ) {
        r = `${n}()`;
      } else {
        r = val.toString();
      }
    } else {
      r = val;
    }
    return currTransform ? currTransform( r ) : r;
  };
 
  return JSON.stringify.apply( this, newArgs );
 
}