-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathformatFunction.js
More file actions
37 lines (32 loc) · 920 Bytes
/
formatFunction.js
File metadata and controls
37 lines (32 loc) · 920 Bytes
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
28
29
30
31
32
33
34
35
36
37
import type { Options } from './../options';
import spacer from './spacer';
function noRefCheck() {}
export const inlineFunction = (fn: any): string =>
fn
.toString()
.split('\n')
.map(line => line.trim())
.join('');
export const preserveFunctionLineBreak = (fn: any): string => fn.toString();
export default (
fn: Function,
prop: string,
inline: boolean,
lvl: number,
options: Options
): string => {
const { functionValue, showFunctions } = options;
const functionFn =
functionValue || (inline ? inlineFunction : preserveFunctionLineBreak);
const shouldShowFunction = Boolean(
functionValue ||
(typeof showFunctions === 'function'
? showFunctions(fn, prop)
: showFunctions)
);
return String(functionFn(shouldShowFunction ? fn : noRefCheck, prop))
.split('\n')
.map(ln => spacer(lvl, options.tabStop) + ln)
.join('\n')
.trim();
};