-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.ts
47 lines (37 loc) · 1.02 KB
/
info.ts
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
38
39
40
41
42
43
44
45
46
47
/* tslint:disable no-magic-numbers */
export interface IStylableAPI {
values: string[];
prefix?: string;
postfix?: string;
indent?: number;
}
function formatValue(value: string, prefix: string, postfix: string) {
const formatedValue = prefix.replace(/:/g, '').length
? value.replace(value[0], value[0].toUpperCase())
: value;
const formatedPostfix = postfix && postfix.replace(postfix[0], postfix[0].toUpperCase());
return `${prefix}${formatedValue}${formatedPostfix}`;
}
export function buildInfo(stylableApi: IStylableAPI[]): string {
return stylableApi.map(({
values,
prefix = '',
postfix = '',
indent = 0
}) =>
values.map(_ =>
`${'\t'.repeat(indent)}- ${formatValue(_, prefix, postfix)}`
).join('\n')
).join('\n');
}
export function extendInfo(params: Record<string, any>, stylableApi: IStylableAPI[]): Record<string, any> {
let sourceInfo: string = params.info;
if (sourceInfo.length) {
sourceInfo += '\n';
}
sourceInfo += buildInfo(stylableApi);
return {
...params,
info: sourceInfo
};
}