Skip to content

Commit

Permalink
improvement: api docs (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Oct 26, 2021
1 parent 430e6a5 commit 1fe3188
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 43 deletions.
146 changes: 105 additions & 41 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
- [annotate](#annotate)
- [compile](#compile)
- [format](#format)
- [TypeAlias](#typealias)
- [Interface](#interface)
- [AnnotateOptions](#annotateoptions)
- [CompileOptions](#compileoptions)
- [FormatOptions](#formatoptions)
- [SFCParseError](#sfcparseerror)
- [Enum](#enum)
- [AnnotateWarningCodes](#annotatewarningcodes)
- [CompileErrorCodes](#compileerrorcodes)
- [Interface](#interface)
- [CompileOptions](#compileoptions)
- [SFCParseError](#sfcparseerror)
- [Variable](#variable)
- [DEFAULT_PRETTIER_OPTIONS](#default_prettier_options)
- [Class](#class)
Expand Down Expand Up @@ -95,81 +94,74 @@ declare function format(source: string, filepath: string, options?: FormatOption
Currently, only i18n custom blocks supporting


## TypeAlias
## Interface

### AnnotateOptions

Annotate options of [annotate](#annotate) function

**Signature:**
```typescript
declare type AnnotateOptions = {
type?: string;
force?: boolean;
attrs?: Record<string, any>;
onWarn?: (code: number, args: Record<string, any>, block: SFCBlock) => void;
};
interface AnnotateOptions
```

### FormatOptions

Format options of [format](#format) function
#### Properties

##### attrs

The Attributes to be annotated on the block tag

**Signature:**
```typescript
declare type FormatOptions = {
prettier?: Options;
};
attrs?: Record<string, any>;
```

#### Remarks

## Enum
default as `{}`
### AnnotateWarningCodes
##### force
Annotate Warning Codes
Whether to force annotations
**Signature:**
```typescript
declare const enum AnnotateWarningCodes
force?: boolean;
```

#### Members

| Member | Value| Description |
| --- | --- | --- |
| LANG_MISMATCH_IN_ATTR_AND_CONTENT | 4 | Lang mismatch `lang` and block content |
| LANG_MISMATCH_IN_OPTION_AND_CONTENT | 3 | Lang mismatch option and block content |
| LANG_MISMATCH_IN_SRC_AND_CONTENT | 2 | Lang mismatch block `src` and block content |
| NOT_SUPPORTED_TYPE | 1 | Not supported type |

#### Remarks

The warning codes of [annotate](#annotate) function
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`

### CompileErrorCodes
##### onWarn

Compile Error Codes
The warning handler

**Signature:**
```typescript
declare const enum CompileErrorCodes
onWarn?: (code: number, args: Record<string, any>, block: SFCBlock) => void;
```

#### Members
#### Remarks

| Member | Value| Description |
| --- | --- | --- |
| INTERNAL_COMPILE_ERROR | 3 | Internal compile error |
| INTERNAL_COMPILE_WARNING | 2 | Internal compile warning |
| NOT_SUPPORTED_FORMAT | 1 | Not supported format |
Notify warnings generated by the annotate process

##### type

The type of the block

**Signature:**
```typescript
type?: string;
```

#### Remarks

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

default as `i18n`

## Interface

### CompileOptions

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


### FormatOptions

Format options of [format](#format) function

**Signature:**
```typescript
interface FormatOptions
```


#### Properties

##### prettier

The prettier options

**Signature:**
```typescript
prettier?: Options;
```

#### Remarks

The options for formatting the content of `i18n` custom blocks with prettier default as [DEFAULT_PRETTIER_OPTIONS](#default_prettier_options)


### SFCParseError

Vue SFC compiler error
Expand Down Expand Up @@ -255,6 +273,52 @@ filepath: string;
## Enum
### AnnotateWarningCodes
Annotate Warning Codes
**Signature:**
```typescript
declare const enum AnnotateWarningCodes
```
#### Members
| Member | Value| Description |
| --- | --- | --- |
| LANG_MISMATCH_IN_ATTR_AND_CONTENT | 4 | Lang mismatch `lang` and block content |
| LANG_MISMATCH_IN_OPTION_AND_CONTENT | 3 | Lang mismatch option and block content |
| LANG_MISMATCH_IN_SRC_AND_CONTENT | 2 | Lang mismatch block `src` and block content |
| NOT_SUPPORTED_TYPE | 1 | Not supported type |
#### Remarks
The warning codes of [annotate](#annotate) function
### CompileErrorCodes
Compile Error Codes
**Signature:**
```typescript
declare const enum CompileErrorCodes
```
#### Members
| Member | Value| Description |
| --- | --- | --- |
| INTERNAL_COMPILE_ERROR | 3 | Internal compile error |
| INTERNAL_COMPILE_WARNING | 2 | Internal compile warning |
| NOT_SUPPORTED_FORMAT | 1 | Not supported format |
#### Remarks
The error codes of [compile](#compile) function
## Variable
### DEFAULT_PRETTIER_OPTIONS
Expand Down
2 changes: 1 addition & 1 deletion src/api/annotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const enum AnnotateWarningCodes {
*
* @public
*/
export type AnnotateOptions = {
export interface AnnotateOptions {
/**
* The type of the block
*
Expand Down
2 changes: 1 addition & 1 deletion src/api/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const debug = createDebug('@intlify/cli:api:format')
*
* @public
*/
export type FormatOptions = {
export interface FormatOptions {
/**
* The prettier options
*
Expand Down

0 comments on commit 1fe3188

Please sign in to comment.