harper.js 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/harper.d.ts +141 -5
- package/dist/harper.js +1325 -1776
- package/dist/harper_wasm_bg.wasm +0 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/package.json +13 -5
- package/api-extractor.json +0 -20
- package/docs.sh +0 -24
- package/examples/commonjs-simple/README.md +0 -11
- package/examples/commonjs-simple/index.js +0 -27
- package/examples/commonjs-simple/package.json +0 -11
- package/examples/commonjs-simple/yarn.lock +0 -8
- package/examples/raw-web/README.md +0 -4
- package/examples/raw-web/index.html +0 -55
- package/src/Linter.bench.ts +0 -31
- package/src/Linter.test.ts +0 -208
- package/src/Linter.ts +0 -73
- package/src/LocalLinter.ts +0 -139
- package/src/WorkerLinter/communication.test.ts +0 -63
- package/src/WorkerLinter/communication.ts +0 -111
- package/src/WorkerLinter/index.ts +0 -170
- package/src/WorkerLinter/worker.js +0 -24
- package/src/loadWasm.ts +0 -26
- package/src/main.ts +0 -18
- package/tsconfig.json +0 -25
- package/vite.config.js +0 -63
package/dist/harper.d.ts
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
+
export declare const binary: BinaryModule;
|
|
2
|
+
|
|
3
|
+
export declare const binaryInlined: BinaryModule;
|
|
4
|
+
|
|
5
|
+
/** This class aims to define the communication protocol between the main thread and the worker.
|
|
6
|
+
* Note that much of the complication here comes from the fact that we can't serialize function calls or referenced WebAssembly memory.*/
|
|
7
|
+
export declare class BinaryModule {
|
|
8
|
+
url: string | URL;
|
|
9
|
+
private inner;
|
|
10
|
+
constructor(url: string | URL);
|
|
11
|
+
applySuggestion(text: string, suggestion: Suggestion, span: Span): Promise<string>;
|
|
12
|
+
getDefaultLintConfigAsJSON(): Promise<string>;
|
|
13
|
+
getDefaultLintConfig(): Promise<LintConfig>;
|
|
14
|
+
toTitleCase(text: string): Promise<string>;
|
|
15
|
+
setup(): Promise<void>;
|
|
16
|
+
createLinter(dialect?: Dialect): Promise<Linter_2>;
|
|
17
|
+
serializeArg(arg: any): Promise<RequestArg>;
|
|
18
|
+
serialize(req: DeserializedRequest): Promise<SerializedRequest>;
|
|
19
|
+
deserializeArg(requestArg: RequestArg): Promise<any>;
|
|
20
|
+
deserialize(request: SerializedRequest): Promise<DeserializedRequest>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** An object that is received by the web worker to request work to be done. */
|
|
24
|
+
export declare interface DeserializedRequest {
|
|
25
|
+
/** The procedure to be executed. */
|
|
26
|
+
procName: string;
|
|
27
|
+
/** The arguments to the procedure */
|
|
28
|
+
args: any[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare enum Dialect {
|
|
32
|
+
American = 0,
|
|
33
|
+
British = 1,
|
|
34
|
+
Australian = 2,
|
|
35
|
+
Canadian = 3,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export declare function isSerializedRequest(v: unknown): v is SerializedRequest;
|
|
39
|
+
|
|
40
|
+
declare enum Language {
|
|
41
|
+
Plain = 0,
|
|
42
|
+
Markdown = 1,
|
|
43
|
+
}
|
|
44
|
+
|
|
1
45
|
/**
|
|
2
46
|
* An error found in provided text.
|
|
3
47
|
*
|
|
@@ -92,19 +136,89 @@ export declare interface Linter {
|
|
|
92
136
|
/** Export all added words from the dictionary. Note that this will NOT export anything from the curated dictionary,
|
|
93
137
|
* only words from previous calls to `this.importWords`. */
|
|
94
138
|
exportWords(): Promise<string[]>;
|
|
139
|
+
/** Get the dialect of English this linter was constructed for. */
|
|
140
|
+
getDialect(): Promise<Dialect>;
|
|
141
|
+
/** Get the dialect of English this linter was constructed for. */
|
|
142
|
+
setDialect(dialect: Dialect): Promise<void>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
declare class Linter_2 {
|
|
146
|
+
private constructor();
|
|
147
|
+
free(): void;
|
|
148
|
+
/**
|
|
149
|
+
* Construct a new `Linter`.
|
|
150
|
+
* Note that this can mean constructing the curated dictionary, which is the most expensive operation
|
|
151
|
+
* in Harper.
|
|
152
|
+
*/
|
|
153
|
+
static new(dialect: Dialect): Linter_2;
|
|
154
|
+
/**
|
|
155
|
+
* Helper method to quickly check if a plain string is likely intended to be English
|
|
156
|
+
*/
|
|
157
|
+
is_likely_english(text: string): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Helper method to remove non-English text from a plain English document.
|
|
160
|
+
*/
|
|
161
|
+
isolate_english(text: string): string;
|
|
162
|
+
/**
|
|
163
|
+
* Get a JSON map containing the descriptions of all the linting rules.
|
|
164
|
+
*/
|
|
165
|
+
get_lint_descriptions_as_json(): string;
|
|
166
|
+
get_lint_config_as_json(): string;
|
|
167
|
+
set_lint_config_from_json(json: string): void;
|
|
168
|
+
/**
|
|
169
|
+
* Get a Record containing the descriptions of all the linting rules.
|
|
170
|
+
*/
|
|
171
|
+
get_lint_descriptions_as_object(): any;
|
|
172
|
+
get_lint_config_as_object(): any;
|
|
173
|
+
set_lint_config_from_object(object: any): void;
|
|
174
|
+
ignore_lint(lint: Lint): void;
|
|
175
|
+
/**
|
|
176
|
+
* Perform the configured linting on the provided text.
|
|
177
|
+
*/
|
|
178
|
+
lint(text: string, language: Language): Lint[];
|
|
179
|
+
/**
|
|
180
|
+
* Export the linter's ignored lints as a privacy-respecting JSON list of hashes.
|
|
181
|
+
*/
|
|
182
|
+
export_ignored_lints(): string;
|
|
183
|
+
/**
|
|
184
|
+
* Import into the linter's ignored lints from a privacy-respecting JSON list of hashes.
|
|
185
|
+
*/
|
|
186
|
+
import_ignored_lints(json: string): void;
|
|
187
|
+
clear_ignored_lints(): void;
|
|
188
|
+
/**
|
|
189
|
+
* Import words into the dictionary.
|
|
190
|
+
*/
|
|
191
|
+
import_words(additional_words: string[]): void;
|
|
192
|
+
/**
|
|
193
|
+
* Export words from the dictionary.
|
|
194
|
+
* Note: this will only return words previously added by [`Self::import_words`].
|
|
195
|
+
*/
|
|
196
|
+
export_words(): string[];
|
|
197
|
+
/**
|
|
198
|
+
* Get the dialect this struct was constructed for.
|
|
199
|
+
*/
|
|
200
|
+
get_dialect(): Dialect;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export declare interface LinterInit {
|
|
204
|
+
/** The module or path to the WebAssembly binary. */
|
|
205
|
+
binary: BinaryModule;
|
|
206
|
+
/** The dialect of English Harper should use. If omitted, Harper will default to American English. */
|
|
207
|
+
dialect?: Dialect;
|
|
95
208
|
}
|
|
96
209
|
|
|
97
210
|
/** The option used to configure the parser for an individual linting operation. */
|
|
98
|
-
export declare
|
|
211
|
+
export declare interface LintOptions {
|
|
99
212
|
/** The markup language that is being passed. Defaults to `markdown`. */
|
|
100
213
|
language?: 'plaintext' | 'markdown';
|
|
101
|
-
}
|
|
214
|
+
}
|
|
102
215
|
|
|
103
216
|
/** A Linter that runs in the current JavaScript context (meaning it is allowed to block the event loop). */
|
|
104
217
|
export declare class LocalLinter implements Linter {
|
|
218
|
+
binary: BinaryModule;
|
|
105
219
|
private inner;
|
|
106
|
-
|
|
107
|
-
private
|
|
220
|
+
constructor(init: LinterInit);
|
|
221
|
+
private createInner;
|
|
108
222
|
setup(): Promise<void>;
|
|
109
223
|
lint(text: string, options?: LintOptions): Promise<Lint[]>;
|
|
110
224
|
applySuggestion(text: string, suggestion: Suggestion, span: Span): Promise<string>;
|
|
@@ -125,6 +239,24 @@ export declare class LocalLinter implements Linter {
|
|
|
125
239
|
clearIgnoredLints(): Promise<void>;
|
|
126
240
|
importWords(words: string[]): Promise<void>;
|
|
127
241
|
exportWords(): Promise<string[]>;
|
|
242
|
+
getDialect(): Promise<Dialect>;
|
|
243
|
+
setDialect(dialect: Dialect): Promise<void>;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Serializable argument to a procedure to be run on the web worker. */
|
|
247
|
+
export declare interface RequestArg {
|
|
248
|
+
json: string;
|
|
249
|
+
type: SerializableTypes;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export declare type SerializableTypes = 'string' | 'number' | 'boolean' | 'Suggestion' | 'Lint' | 'Span' | 'Array' | 'undefined';
|
|
253
|
+
|
|
254
|
+
/** An object that is sent to the web worker to request work to be done. */
|
|
255
|
+
export declare interface SerializedRequest {
|
|
256
|
+
/** The procedure to be executed. */
|
|
257
|
+
procName: string;
|
|
258
|
+
/** The arguments to the procedure */
|
|
259
|
+
args: RequestArg[];
|
|
128
260
|
}
|
|
129
261
|
|
|
130
262
|
/**
|
|
@@ -182,10 +314,12 @@ export declare enum SuggestionKind {
|
|
|
182
314
|
*
|
|
183
315
|
* NOTE: This class will not work properly in Node. In that case, just use `LocalLinter`. */
|
|
184
316
|
export declare class WorkerLinter implements Linter {
|
|
317
|
+
private binary;
|
|
318
|
+
private dialect?;
|
|
185
319
|
private worker;
|
|
186
320
|
private requestQueue;
|
|
187
321
|
private working;
|
|
188
|
-
constructor();
|
|
322
|
+
constructor(init: LinterInit);
|
|
189
323
|
private setupMainEventListeners;
|
|
190
324
|
setup(): Promise<void>;
|
|
191
325
|
lint(text: string, options?: LintOptions): Promise<Lint[]>;
|
|
@@ -207,6 +341,8 @@ export declare class WorkerLinter implements Linter {
|
|
|
207
341
|
clearIgnoredLints(): Promise<void>;
|
|
208
342
|
importWords(words: string[]): Promise<void>;
|
|
209
343
|
exportWords(): Promise<string[]>;
|
|
344
|
+
getDialect(): Promise<Dialect>;
|
|
345
|
+
setDialect(dialect: Dialect): Promise<void>;
|
|
210
346
|
/** Run a procedure on the remote worker. */
|
|
211
347
|
private rpc;
|
|
212
348
|
private submitRemainingRequests;
|