-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
181 lines (170 loc) · 5.32 KB
/
index.d.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Copyright (C) 2017 jeffy-g <hirotom1107@gmail.com>
Released under the MIT license
https://opensource.org/licenses/mit-license.php
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
/// <reference path="./extras.d.ts"/>
declare global {
/**
* @since 3.0
*/
type TRemoveCStyleCommentsOpt = {
/**
* Whether collect detected regex
* @default undefined
*/
collectRegex?: true;
/**
* Whether to display an error message
*
* By default, a concise message will be logged when an exception occurs,
* but setting this option to true will also log an error message.
* @default undefined
*/
showErrorMessage?: true;
// - - - - - - - - - - - - - - -
// replace mode
// - - - - - - - - - - - - - - -
/**
* Whether preserve whitespace and blank lines
* + this option is ignore on walk through mode
* @default undefined
*/
preserveBlanks?: true;
};
/**
* use with `walk` function
*/
type TWalkThroughOpt = Omit<TRemoveCStyleCommentsOpt, "preserveBlanks">;
interface IRemoveCStyleCommentsMain {
/**
* #### remove c style comments form "source" content.
*
* step 1:
* - remove line comments, multi line comments.
* - and search the regexp literal. if found then concat it to results. (`collectRegex` option).
*
* step 2:
* - remove blank line and trailing whitespaces.
* if preserve it, set `TRemoveCStyleCommentsOpt.preserveBlanks` to `true`
*
* @param source c style commented text source.
* @param options see TRemoveCStyleCommentsOpt.
* @returns if `options.isWalk === true`, returns original string, otherwise returns comment removed string
* @since 3.0
*/
(source: string, options?: TRemoveCStyleCommentsOpt): string;
}
interface IRemoveCStyleCommentsTypeSig extends IRemoveCStyleCommentsMain {
/**
* #### Walk through the `(Java|Type)Script` source content.
*
* @param source c style commented text source.
* @param options see {@link TWalkThroughOpt}
* @see {@link EScannerEvent}
* @since 3.2
*/
walk(source: string, options?: TWalkThroughOpt): void;
}
interface IRemoveCStyleCommentsProperties {
/** package version */
readonly version: string;
/**
* The number of times the process has been canceled due to an error etc.
*/
readonly noops: number;
/**
* number of times successfully processed
*/
readonly processed: number;
/**
* Whether to keep only jsdoc comments
* + this option is ignore on walk through mode
* @default undefined
*/
keepJsDoc?: true;
}
interface IRemoveCStyleComments extends IRemoveCStyleCommentsTypeSig, IRemoveCStyleCommentsProperties {
/**
* reset "noops" and "processed".
*/
reset(): void;
/**
* Can refer to the regex literal detected after processing by setting `TRemoveCStyleCommentsOpt.collectRegex` to `true`
*
* ```ts
* import * as rmc from "rm-cstyle-cmts";
* const ret = rmc(source, { collectRegex: true });
* ```
*/
getDetectedReContext(): TDetectedReContext;
/**
* listen the Scan event
*
* + When single line comment detected {@link EScannerEvent.SingleLineComment}
*
* + When multi line comment detected {@link EScannerEvent.MultiLineComment}
*
* ### how to remove listener
* ```ts
* import * as rmc from "rm-cstyle-cmts";
*
* // this indicate revert to default empty listener
* rmc.setListener();
* ```
*
* @see {@link EScannerEvent}
* @since 3.0
*/
setListener(listener?: IScanEventCallback): void;
}
/**
*
*/
type TDetectedReContext = {
detectedReLiterals: string[];
uniqReLiterals: string[];
};
/**
*
*/
const enum EScannerEvent {
SingleLineComment,
MultiLineComment
}
/**
* @since 3.1
*/
type TScannerEventContext = {
/**
* currently supported `ScannerEvent.SingleLineComment` and `ScannerEvent.MultiLineComment`
*/
event: EScannerEvent;
/**
* Is the detected string from original source
*/
fragment: string;
/**
* fragment start offset from original source
*/
offset: number;
};
/**
* + replace mode - If it returns `true`, it is concatenated to the resulting source, otherwise it is deleted
*
* + walk through mode - If returns `true`, proceed walk through, otherwise stop that
*
* @since 3.1
* @see {@link TScannerEventContext}
*/
interface IScanEventCallback {
(context: TScannerEventContext): boolean;
}
/**
* umd module
*/
const Rmc: IRemoveCStyleComments;
}
export = Rmc;