-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
72 lines (66 loc) · 2.47 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema';
export type JSONCommentType = 'block' | 'line' | 'end';
export type IJSONComment = {
/**
* @description Type of the comment:
* * `block` - block comment wrapped with '/\*' and '\*\/' before the item
* * `line` - line comment beginning with '//' before the item
* * `end` - line comment at the end of the item on the same line
*
* `line` and `end` are not supported if `space` when calling `stringify` is 0.
* (Except for comments of root object)
*/
type: JSONCommentType;
/**
* @description Content of the comment. Could be:
* * A single-line or multi-line string
* * A function to be called when stringifying the matched field.
* Return `undefined` to omit.
* '*\/' will be escaped automatically if type is `block`.
*/
content: ((matchedFieldPath: (string | number)[]) => string | undefined) | string;
} | string;
export interface IJSONCommentConfiguration {
/**
* @description Add a blank line before every `block` and `line` comment,
* except comments of the followings:
* * The root object
* * The first item in array
* * The first key-value pair in object
* Not supported if `space` when calling `stringify` is 0.
*
* @default true
*/
emptyLineBeforeComments: boolean;
/**
* @description Add space around '//', '/\*' and '\*\/'.
* '/\*' and '\*\/' will not be affected by this
* configuration if `styledBlockComment` is true.
*
* @default true
*/
spaceAroundCommentSymbol: boolean;
/**
* @description Make block comment styled:
* * Asterisk (' \* ') at the beginning of each line
* * The first line being '/\*\*'
* * The last line being ' \*\/'
* Not supported if `space` when calling `stringify` is 0.
* (Except for comments of root object)
*
* @default true
*/
styledBlockComment: boolean;
/**
* @description Maximum line length of each line of comment.
* Lines will be auto wrapped if exceeded.
* If any non-positive number is specified, auto wrapping will be disabled.
* Not supported if `space` when calling `stringify` is 0.
* (Except for comments of root object)
*
* @default 80
*/
maxLineLength: number;
}
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
export type IReplacer = ((key: string, value: any) => any) | (number | string)[] | null;