formatFunction.js.flow 607 B

1234567891011121314151617181920212223
  1. import type { Options } from './../options';
  2. function noRefCheck() {}
  3. export const inlineFunction = (fn: any): string =>
  4. fn
  5. .toString()
  6. .split('\n')
  7. .map(line => line.trim())
  8. .join('');
  9. export const preserveFunctionLineBreak = (fn: any): string => fn.toString();
  10. const defaultFunctionValue = inlineFunction;
  11. export default (fn: Function, options: Options): string => {
  12. const { functionValue = defaultFunctionValue, showFunctions } = options;
  13. if (!showFunctions && functionValue === defaultFunctionValue) {
  14. return functionValue(noRefCheck);
  15. }
  16. return functionValue(fn);
  17. };