harper.js 0.13.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 +89 -0
- package/dist/harper.js +929 -0
- package/package.json +24 -0
- package/src/Linter.test.ts +135 -0
- package/src/Linter.ts +35 -0
- package/src/LocalLinter.ts +77 -0
- package/src/WorkerLinter/communication.test.ts +63 -0
- package/src/WorkerLinter/communication.ts +111 -0
- package/src/WorkerLinter/index.ts +131 -0
- package/src/WorkerLinter/worker.js +24 -0
- package/src/loadWasm.ts +26 -0
- package/src/main.test.ts +8 -0
- package/src/main.ts +14 -0
- package/tsconfig.json +22 -0
- package/vite.config.js +53 -0
package/dist/harper.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Lint } from 'wasm';
|
|
2
|
+
import { Span } from 'wasm';
|
|
3
|
+
import { Suggestion } from 'wasm';
|
|
4
|
+
|
|
5
|
+
export { Lint }
|
|
6
|
+
|
|
7
|
+
export declare type LintConfig = Record<string, boolean | undefined>;
|
|
8
|
+
|
|
9
|
+
/** A interface for an object that can perform linting actions. */
|
|
10
|
+
export declare interface Linter {
|
|
11
|
+
/** Complete any setup that is necessary before linting. This may include downloading and compiling the WebAssembly binary.
|
|
12
|
+
* This setup will complete when needed regardless of whether you call this function.
|
|
13
|
+
* This function exists to allow you to do this work when it is of least impact to the user experiences (i.e. while you're loading something else). */
|
|
14
|
+
setup(): Promise<void>;
|
|
15
|
+
/** Lint the provided text. */
|
|
16
|
+
lint(text: string): Promise<Lint[]>;
|
|
17
|
+
/** Apply a suggestion to the given text, returning the transformed result. */
|
|
18
|
+
applySuggestion(text: string, suggestion: Suggestion, span: Span): Promise<string>;
|
|
19
|
+
/** Determine if the provided text is likely to be intended to be English.
|
|
20
|
+
* The algorithm can be described as "proof of concept" and as such does not work terribly well.*/
|
|
21
|
+
isLikelyEnglish(text: string): Promise<boolean>;
|
|
22
|
+
/** Determine which parts of a given string are intended to be English, returning those bits.
|
|
23
|
+
* The algorithm can be described as "proof of concept" and as such does not work terribly well.*/
|
|
24
|
+
isolateEnglish(text: string): Promise<string>;
|
|
25
|
+
/** Get the linter's current configuration. */
|
|
26
|
+
getLintConfig(): Promise<LintConfig>;
|
|
27
|
+
/** Set the linter's current configuration. */
|
|
28
|
+
setLintConfig(config: LintConfig): Promise<void>;
|
|
29
|
+
/** Get the linter's current configuration as JSON. */
|
|
30
|
+
getLintConfigAsJSON(): Promise<string>;
|
|
31
|
+
/** Set the linter's current configuration from JSON. */
|
|
32
|
+
setLintConfigWithJSON(config: string): Promise<void>;
|
|
33
|
+
/** Convert a string to Chicago-style title case. */
|
|
34
|
+
toTitleCase(text: string): Promise<string>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A Linter that runs in the current JavaScript context (meaning it is allowed to block the event loop). */
|
|
38
|
+
export declare class LocalLinter implements Linter {
|
|
39
|
+
private inner;
|
|
40
|
+
/** Initialize the WebAssembly and construct the inner Linter. */
|
|
41
|
+
private initialize;
|
|
42
|
+
setup(): Promise<void>;
|
|
43
|
+
lint(text: string): Promise<Lint[]>;
|
|
44
|
+
applySuggestion(text: string, suggestion: Suggestion, span: Span): Promise<string>;
|
|
45
|
+
isLikelyEnglish(text: string): Promise<boolean>;
|
|
46
|
+
isolateEnglish(text: string): Promise<string>;
|
|
47
|
+
getLintConfig(): Promise<LintConfig>;
|
|
48
|
+
setLintConfig(config: LintConfig): Promise<void>;
|
|
49
|
+
getLintConfigAsJSON(): Promise<string>;
|
|
50
|
+
setLintConfigWithJSON(config: string): Promise<void>;
|
|
51
|
+
toTitleCase(text: string): Promise<string>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { Span }
|
|
55
|
+
|
|
56
|
+
export { Suggestion }
|
|
57
|
+
|
|
58
|
+
export declare enum SuggestionKind {
|
|
59
|
+
Replace = 0,
|
|
60
|
+
Remove = 1
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A Linter that spins up a dedicated web worker to do processing on a separate thread.
|
|
64
|
+
* Main benefit: this Linter will not block the event loop for large documents.
|
|
65
|
+
*
|
|
66
|
+
* NOTE: This class will not work properly in Node. In that case, just use `LocalLinter`.
|
|
67
|
+
* Also requires top-level await to work. */
|
|
68
|
+
export declare class WorkerLinter implements Linter {
|
|
69
|
+
private worker;
|
|
70
|
+
private requestQueue;
|
|
71
|
+
private working;
|
|
72
|
+
constructor();
|
|
73
|
+
private setupMainEventListeners;
|
|
74
|
+
setup(): Promise<void>;
|
|
75
|
+
lint(text: string): Promise<Lint[]>;
|
|
76
|
+
applySuggestion(text: string, suggestion: Suggestion, span: Span): Promise<string>;
|
|
77
|
+
isLikelyEnglish(text: string): Promise<boolean>;
|
|
78
|
+
isolateEnglish(text: string): Promise<string>;
|
|
79
|
+
getLintConfig(): Promise<LintConfig>;
|
|
80
|
+
setLintConfig(config: LintConfig): Promise<void>;
|
|
81
|
+
getLintConfigAsJSON(): Promise<string>;
|
|
82
|
+
setLintConfigWithJSON(config: string): Promise<void>;
|
|
83
|
+
toTitleCase(text: string): Promise<string>;
|
|
84
|
+
/** Run a procedure on the remote worker. */
|
|
85
|
+
private rpc;
|
|
86
|
+
private submitRemainingRequests;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { }
|