Skip to content

Commit 1fe3188

Browse files
authored
improvement: api docs (#46)
1 parent 430e6a5 commit 1fe3188

File tree

3 files changed

+107
-43
lines changed

3 files changed

+107
-43
lines changed

api.md

Lines changed: 105 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
- [annotate](#annotate)
77
- [compile](#compile)
88
- [format](#format)
9-
- [TypeAlias](#typealias)
9+
- [Interface](#interface)
1010
- [AnnotateOptions](#annotateoptions)
11+
- [CompileOptions](#compileoptions)
1112
- [FormatOptions](#formatoptions)
13+
- [SFCParseError](#sfcparseerror)
1214
- [Enum](#enum)
1315
- [AnnotateWarningCodes](#annotatewarningcodes)
1416
- [CompileErrorCodes](#compileerrorcodes)
15-
- [Interface](#interface)
16-
- [CompileOptions](#compileoptions)
17-
- [SFCParseError](#sfcparseerror)
1817
- [Variable](#variable)
1918
- [DEFAULT_PRETTIER_OPTIONS](#default_prettier_options)
2019
- [Class](#class)
@@ -95,81 +94,74 @@ declare function format(source: string, filepath: string, options?: FormatOption
9594
Currently, only i18n custom blocks supporting
9695

9796

98-
## TypeAlias
97+
## Interface
9998

10099
### AnnotateOptions
101100

102101
Annotate options of [annotate](#annotate) function
103102

104103
**Signature:**
105104
```typescript
106-
declare type AnnotateOptions = {
107-
type?: string;
108-
force?: boolean;
109-
attrs?: Record<string, any>;
110-
onWarn?: (code: number, args: Record<string, any>, block: SFCBlock) => void;
111-
};
105+
interface AnnotateOptions
112106
```
113107

114-
### FormatOptions
115108

116-
Format options of [format](#format) function
109+
#### Properties
110+
111+
##### attrs
112+
113+
The Attributes to be annotated on the block tag
117114

118115
**Signature:**
119116
```typescript
120-
declare type FormatOptions = {
121-
prettier?: Options;
122-
};
117+
attrs?: Record<string, any>;
123118
```
124119

120+
#### Remarks
125121

126-
## Enum
122+
default as `{}`
127123
128-
### AnnotateWarningCodes
124+
##### force
129125
130-
Annotate Warning Codes
126+
Whether to force annotations
131127
132128
**Signature:**
133129
```typescript
134-
declare const enum AnnotateWarningCodes
130+
force?: boolean;
135131
```
136132

137-
#### Members
138-
139-
| Member | Value| Description |
140-
| --- | --- | --- |
141-
| LANG_MISMATCH_IN_ATTR_AND_CONTENT | 4 | Lang mismatch `lang` and block content |
142-
| LANG_MISMATCH_IN_OPTION_AND_CONTENT | 3 | Lang mismatch option and block content |
143-
| LANG_MISMATCH_IN_SRC_AND_CONTENT | 2 | Lang mismatch block `src` and block content |
144-
| NOT_SUPPORTED_TYPE | 1 | Not supported type |
145-
146133
#### Remarks
147134

148-
The warning codes of [annotate](#annotate) function
135+
Force annotation of the attribute values of `attrs` option to the block tag. Even if the actual `lang` of the block content in the `lang` attribute is different, it will be enforced if this flag is turned on. default as `false`
149136

150-
### CompileErrorCodes
137+
##### onWarn
151138

152-
Compile Error Codes
139+
The warning handler
153140

154141
**Signature:**
155142
```typescript
156-
declare const enum CompileErrorCodes
143+
onWarn?: (code: number, args: Record<string, any>, block: SFCBlock) => void;
157144
```
158145

159-
#### Members
146+
#### Remarks
160147

161-
| Member | Value| Description |
162-
| --- | --- | --- |
163-
| INTERNAL_COMPILE_ERROR | 3 | Internal compile error |
164-
| INTERNAL_COMPILE_WARNING | 2 | Internal compile warning |
165-
| NOT_SUPPORTED_FORMAT | 1 | Not supported format |
148+
Notify warnings generated by the annotate process
149+
150+
##### type
151+
152+
The type of the block
153+
154+
**Signature:**
155+
```typescript
156+
type?: string;
157+
```
166158

167159
#### Remarks
168160

169-
The error codes of [compile](#compile) function
161+
Only `i18n` type is supported, if you don't specify it. If any other type is specified, the function will raise the [SFCAnnotateError](#sfcannotateerror).
170162

163+
default as `i18n`
171164

172-
## Interface
173165

174166
### CompileOptions
175167

@@ -219,6 +211,32 @@ onError?: (code: number, source: string, output: string, msg?: string) => void;
219211
```
220212

221213

214+
### FormatOptions
215+
216+
Format options of [format](#format) function
217+
218+
**Signature:**
219+
```typescript
220+
interface FormatOptions
221+
```
222+
223+
224+
#### Properties
225+
226+
##### prettier
227+
228+
The prettier options
229+
230+
**Signature:**
231+
```typescript
232+
prettier?: Options;
233+
```
234+
235+
#### Remarks
236+
237+
The options for formatting the content of `i18n` custom blocks with prettier default as [DEFAULT_PRETTIER_OPTIONS](#default_prettier_options)
238+
239+
222240
### SFCParseError
223241

224242
Vue SFC compiler error
@@ -255,6 +273,52 @@ filepath: string;
255273
256274
257275
276+
## Enum
277+
278+
### AnnotateWarningCodes
279+
280+
Annotate Warning Codes
281+
282+
**Signature:**
283+
```typescript
284+
declare const enum AnnotateWarningCodes
285+
```
286+
287+
#### Members
288+
289+
| Member | Value| Description |
290+
| --- | --- | --- |
291+
| LANG_MISMATCH_IN_ATTR_AND_CONTENT | 4 | Lang mismatch `lang` and block content |
292+
| LANG_MISMATCH_IN_OPTION_AND_CONTENT | 3 | Lang mismatch option and block content |
293+
| LANG_MISMATCH_IN_SRC_AND_CONTENT | 2 | Lang mismatch block `src` and block content |
294+
| NOT_SUPPORTED_TYPE | 1 | Not supported type |
295+
296+
#### Remarks
297+
298+
The warning codes of [annotate](#annotate) function
299+
300+
### CompileErrorCodes
301+
302+
Compile Error Codes
303+
304+
**Signature:**
305+
```typescript
306+
declare const enum CompileErrorCodes
307+
```
308+
309+
#### Members
310+
311+
| Member | Value| Description |
312+
| --- | --- | --- |
313+
| INTERNAL_COMPILE_ERROR | 3 | Internal compile error |
314+
| INTERNAL_COMPILE_WARNING | 2 | Internal compile warning |
315+
| NOT_SUPPORTED_FORMAT | 1 | Not supported format |
316+
317+
#### Remarks
318+
319+
The error codes of [compile](#compile) function
320+
321+
258322
## Variable
259323
260324
### DEFAULT_PRETTIER_OPTIONS

src/api/annotate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const enum AnnotateWarningCodes {
4545
*
4646
* @public
4747
*/
48-
export type AnnotateOptions = {
48+
export interface AnnotateOptions {
4949
/**
5050
* The type of the block
5151
*

src/api/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const debug = createDebug('@intlify/cli:api:format')
1414
*
1515
* @public
1616
*/
17-
export type FormatOptions = {
17+
export interface FormatOptions {
1818
/**
1919
* The prettier options
2020
*

0 commit comments

Comments
 (0)