harper.js 0.15.0 → 0.17.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.
@@ -0,0 +1,20 @@
1
+ {
2
+ "mainEntryPointFilePath": "./dist/harper.d.ts",
3
+ "apiReport": {
4
+ "enabled": false
5
+ },
6
+ "docModel": {
7
+ "enabled": true
8
+ },
9
+ "dtsRollup": {
10
+ "enabled": false
11
+ },
12
+ "bundledPackages": ["wasm"],
13
+ "messages": {
14
+ "extractorMessageReporting": {
15
+ "ae-missing-release-tag": {
16
+ "logLevel": "none"
17
+ }
18
+ }
19
+ }
20
+ }
package/dist/harper.d.ts CHANGED
@@ -1,9 +1,41 @@
1
- import { Lint } from 'wasm';
2
- import { Span } from 'wasm';
3
- import { Suggestion } from 'wasm';
4
-
5
- export { Lint }
1
+ /**
2
+ * An error found in provided text.
3
+ *
4
+ * May include zero or more suggestions that may fix the problematic text.
5
+ */
6
+ export declare class Lint {
7
+ private constructor();
8
+ free(): void;
9
+ to_json(): string;
10
+ static from_json(json: string): Lint;
11
+ /**
12
+ * Get the content of the source material pointed to by [`Self::span`]
13
+ */
14
+ get_problem_text(): string;
15
+ /**
16
+ * Get a string representing the general category of the lint.
17
+ */
18
+ lint_kind(): string;
19
+ /**
20
+ * Equivalent to calling `.length` on the result of `suggestions()`.
21
+ */
22
+ suggestion_count(): number;
23
+ /**
24
+ * Get an array of any suggestions that may resolve the issue.
25
+ */
26
+ suggestions(): (Suggestion)[];
27
+ /**
28
+ * Get the location of the problematic text.
29
+ */
30
+ span(): Span;
31
+ /**
32
+ * Get a description of the error.
33
+ */
34
+ message(): string;
35
+ }
6
36
 
37
+ /** A linting rule configuration dependent on upstream Harper's available rules.
38
+ * This is a record, since you shouldn't hard-code the existence of any particular rules and should generalize based on this struct. */
7
39
  export declare type LintConfig = Record<string, boolean | undefined>;
8
40
 
9
41
  /** An interface for an object that can perform linting actions. */
@@ -13,7 +45,7 @@ export declare interface Linter {
13
45
  * 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
46
  setup(): Promise<void>;
15
47
  /** Lint the provided text. */
16
- lint(text: string): Promise<Lint[]>;
48
+ lint(text: string, options?: LintOptions): Promise<Lint[]>;
17
49
  /** Apply a suggestion to the given text, returning the transformed result. */
18
50
  applySuggestion(text: string, suggestion: Suggestion, span: Span): Promise<string>;
19
51
  /** Determine if the provided text is likely to be intended to be English.
@@ -24,6 +56,12 @@ export declare interface Linter {
24
56
  isolateEnglish(text: string): Promise<string>;
25
57
  /** Get the linter's current configuration. */
26
58
  getLintConfig(): Promise<LintConfig>;
59
+ /** Get the default (unset) linter configuration as JSON.
60
+ * This method does not effect the caller's lint configuration, nor does it return the current one. */
61
+ getDefaultLintConfigAsJSON(): Promise<string>;
62
+ /** Get the default (unset) linter configuration.
63
+ * This method does not effect the caller's lint configuration, nor does it return the current one. */
64
+ getDefaultLintConfig(): Promise<LintConfig>;
27
65
  /** Set the linter's current configuration. */
28
66
  setLintConfig(config: LintConfig): Promise<void>;
29
67
  /** Get the linter's current configuration as JSON. */
@@ -38,17 +76,25 @@ export declare interface Linter {
38
76
  toTitleCase(text: string): Promise<string>;
39
77
  }
40
78
 
41
- /** A Linter that runs in the current JavaScript context (meaning it is allowed to block the event loop). */
79
+ /** The option used to configure the parser for an individual linting operation. */
80
+ export declare type LintOptions = {
81
+ /** The markup language that is being passed. Defaults to `markdown`. */
82
+ language?: 'plaintext' | 'markdown';
83
+ };
84
+
85
+ /** A Linter that runs in the current JavaScript context (meaning it is allowed to block the event loop). */
42
86
  export declare class LocalLinter implements Linter {
43
87
  private inner;
44
88
  /** Initialize the WebAssembly and construct the inner Linter. */
45
89
  private initialize;
46
90
  setup(): Promise<void>;
47
- lint(text: string): Promise<Lint[]>;
91
+ lint(text: string, options?: LintOptions): Promise<Lint[]>;
48
92
  applySuggestion(text: string, suggestion: Suggestion, span: Span): Promise<string>;
49
93
  isLikelyEnglish(text: string): Promise<boolean>;
50
94
  isolateEnglish(text: string): Promise<string>;
51
95
  getLintConfig(): Promise<LintConfig>;
96
+ getDefaultLintConfigAsJSON(): Promise<string>;
97
+ getDefaultLintConfig(): Promise<LintConfig>;
52
98
  setLintConfig(config: LintConfig): Promise<void>;
53
99
  getLintConfigAsJSON(): Promise<string>;
54
100
  setLintConfigWithJSON(config: string): Promise<void>;
@@ -57,20 +103,60 @@ export declare class LocalLinter implements Linter {
57
103
  getLintDescriptionsAsJSON(): Promise<string>;
58
104
  }
59
105
 
60
- export { Span }
106
+ /**
107
+ * A struct that represents two character indices in a string: a start and an end.
108
+ */
109
+ export declare class Span {
110
+ private constructor();
111
+ free(): void;
112
+ to_json(): string;
113
+ static from_json(json: string): Span;
114
+ static new(start: number, end: number): Span;
115
+ is_empty(): boolean;
116
+ len(): number;
117
+ start: number;
118
+ end: number;
119
+ }
61
120
 
62
- export { Suggestion }
121
+ /**
122
+ * A suggestion to fix a Lint.
123
+ */
124
+ export declare class Suggestion {
125
+ private constructor();
126
+ free(): void;
127
+ to_json(): string;
128
+ static from_json(json: string): Suggestion;
129
+ /**
130
+ * Get the text that is going to replace the problematic section.
131
+ * If [`Self::kind`] is `SuggestionKind::Remove`, this will return an empty
132
+ * string.
133
+ */
134
+ get_replacement_text(): string;
135
+ kind(): SuggestionKind;
136
+ }
63
137
 
138
+ /**
139
+ * Tags the variant of suggestion.
140
+ */
64
141
  export declare enum SuggestionKind {
142
+ /**
143
+ * Replace the problematic text.
144
+ */
65
145
  Replace = 0,
66
- Remove = 1
146
+ /**
147
+ * Remove the problematic text.
148
+ */
149
+ Remove = 1,
150
+ /**
151
+ * Insert additional text after the error.
152
+ */
153
+ InsertAfter = 2,
67
154
  }
68
155
 
69
156
  /** A Linter that spins up a dedicated web worker to do processing on a separate thread.
70
157
  * Main benefit: this Linter will not block the event loop for large documents.
71
158
  *
72
- * NOTE: This class will not work properly in Node. In that case, just use `LocalLinter`.
73
- * Also requires top-level await to work. */
159
+ * NOTE: This class will not work properly in Node. In that case, just use `LocalLinter`. */
74
160
  export declare class WorkerLinter implements Linter {
75
161
  private worker;
76
162
  private requestQueue;
@@ -78,7 +164,7 @@ export declare class WorkerLinter implements Linter {
78
164
  constructor();
79
165
  private setupMainEventListeners;
80
166
  setup(): Promise<void>;
81
- lint(text: string): Promise<Lint[]>;
167
+ lint(text: string, options?: LintOptions): Promise<Lint[]>;
82
168
  applySuggestion(text: string, suggestion: Suggestion, span: Span): Promise<string>;
83
169
  isLikelyEnglish(text: string): Promise<boolean>;
84
170
  isolateEnglish(text: string): Promise<string>;
@@ -89,6 +175,8 @@ export declare class WorkerLinter implements Linter {
89
175
  toTitleCase(text: string): Promise<string>;
90
176
  getLintDescriptionsAsJSON(): Promise<string>;
91
177
  getLintDescriptions(): Promise<Record<string, string>>;
178
+ getDefaultLintConfigAsJSON(): Promise<string>;
179
+ getDefaultLintConfig(): Promise<LintConfig>;
92
180
  /** Run a procedure on the remote worker. */
93
181
  private rpc;
94
182
  private submitRemainingRequests;