|
1 | 1 | import reference from './src/reference.json'
|
2 | 2 |
|
3 | 3 | export interface Directive {
|
4 |
| - name: string |
5 |
| - module: string |
6 |
| - description: string |
7 |
| - syntax: string[] |
8 |
| - contexts: string[] |
9 |
| - isBlock: boolean |
10 |
| - default: string |
| 4 | + name: string |
| 5 | + module: string |
| 6 | + description: string |
| 7 | + syntax: string[] |
| 8 | + contexts: string[] |
| 9 | + isBlock: boolean |
| 10 | + default: string |
| 11 | +} |
| 12 | + |
| 13 | +export interface Variable { |
| 14 | + name: string |
| 15 | + module: string |
| 16 | + description: string |
11 | 17 | }
|
12 | 18 |
|
13 | 19 | export enum Format {
|
@@ -41,37 +47,63 @@ for (const modules of reference.modules) {
|
41 | 47 | * Returns all the nginx directives
|
42 | 48 | *
|
43 | 49 | * @param: format: format of the return type HTML or markdown
|
44 |
| - * |
45 | 50 | * @return: an array of Directives
|
46 | 51 | */
|
47 |
| -export function getDirectives(format=Format.HTML): Directive[] { |
48 |
| - const directives = reference.modules.flatMap((m) => |
49 |
| - m.directives.map((d) => ({...d, module: m.name}))) |
50 |
| - .map ((d) => ({ |
51 |
| - name: d.name, |
52 |
| - module: d.module, |
53 |
| - description: format === Format.HTML ? d.description_html : d.description_md, |
54 |
| - syntax: format === Format.HTML ? d.syntax_html : d.syntax_md, |
55 |
| - contexts: d.contexts, |
56 |
| - isBlock: d.isBlock, |
57 |
| - default: d.default |
58 |
| - } as Directive)) |
59 |
| - return directives |
| 52 | +export function getDirectives(format = Format.HTML): Directive[] { |
| 53 | + const directives = reference.modules |
| 54 | + .flatMap((m) => m.directives.map((d) => ({ ...d, module: m.name }))) |
| 55 | + .map( |
| 56 | + (d) => |
| 57 | + ({ |
| 58 | + name: d.name, |
| 59 | + module: d.module, |
| 60 | + description: |
| 61 | + format === Format.HTML ? d.description_html : d.description_md, |
| 62 | + syntax: format === Format.HTML ? d.syntax_html : d.syntax_md, |
| 63 | + contexts: d.contexts, |
| 64 | + isBlock: d.isBlock, |
| 65 | + default: d.default, |
| 66 | + } as Directive) |
| 67 | + ) |
| 68 | + return directives |
| 69 | +} |
| 70 | + |
| 71 | +/** |
| 72 | + * Returns all variables defined by any moduled |
| 73 | + * |
| 74 | + * @param: format: format of the return type HTML or markdown |
| 75 | + * @return: an array of Variables |
| 76 | + */ |
| 77 | +export function getVariables(format = Format.HTML): Variable[] { |
| 78 | + return reference.modules.flatMap( |
| 79 | + (m) => |
| 80 | + m.variables?.map((v) => ({ |
| 81 | + name: v.name, |
| 82 | + description: |
| 83 | + format === Format.HTML ? v.description_html : v.description_md, |
| 84 | + module: m.name, |
| 85 | + })) ?? [] |
| 86 | + ) |
60 | 87 | }
|
61 | 88 |
|
62 | 89 | /**
|
63 |
| - * Returns the description corresponding to the directive name |
| 90 | + * Returns the description corresponding to the directive or variable name |
64 | 91 | *
|
65 | 92 | * @param: directive: directive name to find
|
66 | 93 | * @param: module: optional name of module
|
67 | 94 | * @param: format: format of the return type HTML or markdown
|
68 | 95 | *
|
69 | 96 | * @return: a string containing the description of the directive in xml or markdown format
|
70 | 97 | */
|
71 |
| -export function find(directive: string, module: string | undefined, format=Format.HTML): string | undefined { |
72 |
| - const data = |
73 |
| - module |
74 |
| - ? refDirectives.get(directive)?.find((d) => d.module.toUpperCase() === module.toUpperCase()) |
75 |
| - : refDirectives.get(directive)?.at(0) |
76 |
| - return (format === Format.HTML ? data?.description_html : data?.description_md) |
| 98 | +export function find( |
| 99 | + directive: string, |
| 100 | + module: string | undefined, |
| 101 | + format = Format.HTML |
| 102 | +): string | undefined { |
| 103 | + const data = module |
| 104 | + ? refDirectives |
| 105 | + .get(directive) |
| 106 | + ?.find((d) => d.module.toUpperCase() === module.toUpperCase()) |
| 107 | + : refDirectives.get(directive)?.at(0) |
| 108 | + return format === Format.HTML ? data?.description_html : data?.description_md |
77 | 109 | }
|
0 commit comments