harper.js 0.15.0 → 0.16.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.
@@ -38,13 +70,19 @@ export declare interface Linter {
38
70
  toTitleCase(text: string): Promise<string>;
39
71
  }
40
72
 
41
- /** A Linter that runs in the current JavaScript context (meaning it is allowed to block the event loop). */
73
+ /** The option used to configure the parser for an individual linting operation. */
74
+ export declare type LintOptions = {
75
+ /** The markup language that is being passed. Defaults to `markdown`. */
76
+ language?: 'plaintext' | 'markdown';
77
+ };
78
+
79
+ /** A Linter that runs in the current JavaScript context (meaning it is allowed to block the event loop). */
42
80
  export declare class LocalLinter implements Linter {
43
81
  private inner;
44
82
  /** Initialize the WebAssembly and construct the inner Linter. */
45
83
  private initialize;
46
84
  setup(): Promise<void>;
47
- lint(text: string): Promise<Lint[]>;
85
+ lint(text: string, options?: LintOptions): Promise<Lint[]>;
48
86
  applySuggestion(text: string, suggestion: Suggestion, span: Span): Promise<string>;
49
87
  isLikelyEnglish(text: string): Promise<boolean>;
50
88
  isolateEnglish(text: string): Promise<string>;
@@ -57,20 +95,60 @@ export declare class LocalLinter implements Linter {
57
95
  getLintDescriptionsAsJSON(): Promise<string>;
58
96
  }
59
97
 
60
- export { Span }
98
+ /**
99
+ * A struct that represents two character indices in a string: a start and an end.
100
+ */
101
+ export declare class Span {
102
+ private constructor();
103
+ free(): void;
104
+ to_json(): string;
105
+ static from_json(json: string): Span;
106
+ static new(start: number, end: number): Span;
107
+ is_empty(): boolean;
108
+ len(): number;
109
+ start: number;
110
+ end: number;
111
+ }
61
112
 
62
- export { Suggestion }
113
+ /**
114
+ * A suggestion to fix a Lint.
115
+ */
116
+ export declare class Suggestion {
117
+ private constructor();
118
+ free(): void;
119
+ to_json(): string;
120
+ static from_json(json: string): Suggestion;
121
+ /**
122
+ * Get the text that is going to replace the problematic section.
123
+ * If [`Self::kind`] is `SuggestionKind::Remove`, this will return an empty
124
+ * string.
125
+ */
126
+ get_replacement_text(): string;
127
+ kind(): SuggestionKind;
128
+ }
63
129
 
130
+ /**
131
+ * Tags the variant of suggestion.
132
+ */
64
133
  export declare enum SuggestionKind {
134
+ /**
135
+ * Replace the problematic text.
136
+ */
65
137
  Replace = 0,
66
- Remove = 1
138
+ /**
139
+ * Remove the problematic text.
140
+ */
141
+ Remove = 1,
142
+ /**
143
+ * Insert additional text after the error.
144
+ */
145
+ InsertAfter = 2,
67
146
  }
68
147
 
69
148
  /** A Linter that spins up a dedicated web worker to do processing on a separate thread.
70
149
  * Main benefit: this Linter will not block the event loop for large documents.
71
150
  *
72
- * NOTE: This class will not work properly in Node. In that case, just use `LocalLinter`.
73
- * Also requires top-level await to work. */
151
+ * NOTE: This class will not work properly in Node. In that case, just use `LocalLinter`. */
74
152
  export declare class WorkerLinter implements Linter {
75
153
  private worker;
76
154
  private requestQueue;
@@ -78,7 +156,7 @@ export declare class WorkerLinter implements Linter {
78
156
  constructor();
79
157
  private setupMainEventListeners;
80
158
  setup(): Promise<void>;
81
- lint(text: string): Promise<Lint[]>;
159
+ lint(text: string, options?: LintOptions): Promise<Lint[]>;
82
160
  applySuggestion(text: string, suggestion: Suggestion, span: Span): Promise<string>;
83
161
  isLikelyEnglish(text: string): Promise<boolean>;
84
162
  isolateEnglish(text: string): Promise<string>;