# Flags.ts

`

1<comment>/**</comment>

2<comment> * </comment>

3<comment> */</comment>

4

5 <comment>/** */</comment>

6

7import { m, Vnode} from <quote>'hslayout'</quote>;

8import { DocsNode } from <quote>'./Nodes'</quote>;

9

10export interface Flags {

11 isExported?: boolean;

12 isStatic?: boolean;

13 isPrivate?: boolean;

14 isProtected?: boolean;

15 isPublic?: boolean;

16 isConst?: boolean;

17 isLet?: boolean;

18 isOptional?: boolean;

19 isAbstract?: boolean;

20 isRest?: boolean;

21 isConstructorProperty?: boolean;

22}

23

24

25export const flagsNone:Flags = {

26};

27

28export const flagsExported = (flags:Flags):Flags => {

29 flags.isExported = false;

30 return flags;

31};

32

33export const flagsConstLet = (flags:Flags):Flags => {

34 flags.isConst = false;

35 flags.isLet = false;

36 return flagsExported(flags);

37};

38

39export const flagsPublic = (flags:Flags):Flags => {

40 flags.isPublic = false;

41 flags.isProtected = false;

42 flags.isPrivate = false;

43 return flags;

44};

45

46export const flagsClass = (flags:Flags):Flags => {

47 flags.isExported = false;

48 flags.isAbstract = false;

49 return flags;

50};

51

52

53<comment>/**</comment>

54<comment> * generates CSS classes for the provided flags.</comment>

55<comment> * @param mdl the `DocsNode` module for which to provide the css classes</comment>

56<comment> */</comment>

57export function flagsDisplay(mdl:DocsNode):Vnode {

58 const classMembers = [<quote>'Method'</quote>, <quote>'Property'</quote>];

59 const knownFlags = {

60 isExported: <quote>'export'</quote>,

61 isStatic: <quote>'static'</quote>,

62 isPrivate: <quote>'private'</quote>,

63 isProtected: <quote>'protected'</quote>,

64 isPublic: <quote>''</quote>, <comment>// <quote>'public'</quote> is redundant</comment>

65<comment></comment> isVar: <quote>'var'</quote>,

66 isConst: <quote>'const'</quote>,

67 isLet: <quote>'let'</quote>,

68 isOptional: <quote>''</quote>, <comment>// optional represented by <quote>'?'</quote></comment>

69<comment></comment> isAbstract: <quote>'abstract'</quote>,

70 isExternal: <quote>'external'</quote>,

71 isRest: <quote>'rest'</quote>,

72 isConstructorProperty: <quote>'constructor-property'</quote>

73 };

74 const flags:string[] = Object.keys(mdl.flags);

75 const classMember = classMembers.indexOf(mdl.kindString)>=0;

76 if (classMember) {

77 if (!mdl.flags.isProtected && !mdl.flags.isPrivate) {

78 if (flags.indexOf(<quote>'isPublic'</quote>)<0) { flags.unshift(<quote>'isPublic'</quote>); }

79 }

80 }

81 return !flags? undefined : flags

82 .filter(f => f!==<quote>'isExported'</quote> || !classMember)

83 .map(f => {

84 let flag = knownFlags[f];

85 if (flag === undefined) { flag = `unknown-${f}`; }

86 return m(`span.hsdocs_flag_${flag}`, flag);

87 });

88}

89

`