@@ -8,10 +8,30 @@ export function jsDoc(
8
8
description,
9
9
deprecated,
10
10
summary,
11
+ minLength,
12
+ maxLength,
13
+ minimum,
14
+ maximum,
15
+ exclusiveMinimum,
16
+ exclusiveMaximum,
17
+ minItems,
18
+ maxItems,
19
+ nullable,
20
+ pattern,
11
21
} : {
12
22
description ?: string [ ] | string ;
13
23
deprecated ?: boolean ;
14
24
summary ?: string ;
25
+ minLength ?: number ;
26
+ maxLength ?: number ;
27
+ minimum ?: number ;
28
+ maximum ?: number ;
29
+ exclusiveMinimum ?: boolean ;
30
+ exclusiveMaximum ?: boolean ;
31
+ minItems ?: number ;
32
+ maxItems ?: number ;
33
+ nullable ?: boolean ;
34
+ pattern ?: string ;
15
35
} ,
16
36
tryOneLine = false ,
17
37
) : string {
@@ -22,10 +42,21 @@ export function jsDoc(
22
42
: [ description || '' ]
23
43
) . map ( ( line ) => line . replace ( regex , replacement ) ) ;
24
44
25
- const count = [ description , deprecated , summary ] . reduce (
26
- ( acc , it ) => ( it ? acc + 1 : acc ) ,
27
- 0 ,
28
- ) ;
45
+ const count = [
46
+ description ,
47
+ deprecated ,
48
+ summary ,
49
+ minLength ?. toString ( ) ,
50
+ maxLength ?. toString ( ) ,
51
+ minimum ?. toString ( ) ,
52
+ maximum ?. toString ( ) ,
53
+ exclusiveMinimum ?. toString ( ) ,
54
+ exclusiveMaximum ?. toString ( ) ,
55
+ minItems ?. toString ( ) ,
56
+ maxItems ?. toString ( ) ,
57
+ nullable ?. toString ( ) ,
58
+ pattern ,
59
+ ] . reduce ( ( acc , it ) => ( it ? acc + 1 : acc ) , 0 ) ;
29
60
30
61
if ( ! count ) {
31
62
return '' ;
@@ -46,20 +77,46 @@ export function jsDoc(
46
77
doc += ` ${ lines . join ( '\n * ' ) } ` ;
47
78
}
48
79
49
- if ( deprecated ) {
80
+ function appendPrefix ( ) {
50
81
if ( ! oneLine ) {
51
82
doc += `\n${ tryOneLine ? ' ' : '' } *` ;
52
83
}
53
- doc += ' @deprecated' ;
54
84
}
55
85
56
- if ( summary ) {
57
- if ( ! oneLine ) {
58
- doc += `\n${ tryOneLine ? ' ' : '' } *` ;
86
+ function tryAppendStringDocLine ( key : string , value ?: string ) {
87
+ if ( value ) {
88
+ appendPrefix ( ) ;
89
+ doc += ` @${ key } ${ value } ` ;
90
+ }
91
+ }
92
+
93
+ function tryAppendBooleanDocLine ( key : string , value ?: boolean ) {
94
+ if ( value === true ) {
95
+ appendPrefix ( ) ;
96
+ doc += ` @${ key } ` ;
97
+ }
98
+ }
99
+
100
+ function tryAppendNumberDocLine ( key : string , value ?: number ) {
101
+ if ( value !== undefined ) {
102
+ appendPrefix ( ) ;
103
+ doc += ` @${ key } ${ value } ` ;
59
104
}
60
- doc += ` @summary ${ summary . replace ( regex , replacement ) } ` ;
61
105
}
62
106
107
+ tryAppendBooleanDocLine ( 'deprecated' , deprecated ) ;
108
+ tryAppendStringDocLine ( 'summary' , summary ?. replace ( regex , replacement ) ) ;
109
+ tryAppendNumberDocLine ( 'minLength' , minLength ) ;
110
+ tryAppendNumberDocLine ( 'maxLength' , maxLength ) ;
111
+ tryAppendNumberDocLine ( 'minimum' , minimum ) ;
112
+ tryAppendNumberDocLine ( 'maximum' , maximum ) ;
113
+ tryAppendBooleanDocLine ( 'exclusiveMinimum' , exclusiveMinimum ) ;
114
+ tryAppendBooleanDocLine ( 'exclusiveMaximum' , exclusiveMaximum ) ;
115
+ tryAppendNumberDocLine ( 'minItems' , minItems ) ;
116
+ tryAppendNumberDocLine ( 'maxItems' , maxItems ) ;
117
+ tryAppendBooleanDocLine ( 'nullable' , nullable ) ;
118
+ tryAppendStringDocLine ( 'pattern' , pattern ) ;
119
+
63
120
doc += ! oneLine ? `\n ${ tryOneLine ? ' ' : '' } ` : ' ' ;
64
121
65
122
doc += '*/\n' ;
0 commit comments