harper.js 0.72.0 → 1.0.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 CHANGED
@@ -1,32 +1,26 @@
1
+ /** A version of the Harper WebAssembly binary stored inline as a data URL.
2
+ * Can be tree-shaken if unused. */
1
3
  export declare const binary: BinaryModule;
2
4
 
5
+ /** A version of the Harper WebAssembly binary stored inline as a data URL.
6
+ * Can be tree-shaken if unused. */
3
7
  export declare const binaryInlined: BinaryModule;
4
8
 
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.*/
9
+ /** A wrapper around the underlying WebAssembly module that contains Harper's core code. Used to construct a `Linter`, as well as access some miscellaneous other functions. */
7
10
  export declare class BinaryModule {
8
11
  url: string | URL;
9
12
  private inner;
10
- constructor(url: string | URL);
13
+ /** Load a binary from a specified URL. This is the only recommended way to construct this type. */
14
+ static create(url: string | URL): BinaryModule;
11
15
  getDefaultLintConfigAsJSON(): Promise<string>;
12
16
  getDefaultLintConfig(): Promise<LintConfig>;
13
17
  toTitleCase(text: string): Promise<string>;
14
18
  setup(): Promise<void>;
15
- createLinter(dialect?: Dialect): Promise<Linter_2>;
16
- serializeArg(arg: any): Promise<RequestArg>;
17
- serialize(req: DeserializedRequest): Promise<SerializedRequest>;
18
- deserializeArg(requestArg: RequestArg): Promise<any>;
19
- deserialize(request: SerializedRequest): Promise<DeserializedRequest>;
20
- }
21
-
22
- /** An object that is received by the web worker to request work to be done. */
23
- export declare interface DeserializedRequest {
24
- /** The procedure to be executed. */
25
- procName: string;
26
- /** The arguments to the procedure */
27
- args: any[];
28
19
  }
29
20
 
21
+ /**
22
+ * Specifies an English Dialect, often used for linting.
23
+ */
30
24
  export declare enum Dialect {
31
25
  American = 0,
32
26
  British = 1,
@@ -34,8 +28,6 @@ export declare enum Dialect {
34
28
  Canadian = 3,
35
29
  }
36
30
 
37
- export declare function isSerializedRequest(v: unknown): v is SerializedRequest;
38
-
39
31
  declare enum Language {
40
32
  Plain = 0,
41
33
  Markdown = 1,
@@ -125,11 +117,14 @@ export declare interface Linter {
125
117
  getLintDescriptionsAsJSON(): Promise<string>;
126
118
  /** Get the linting rule descriptions as an object, formatted in Markdown. */
127
119
  getLintDescriptions(): Promise<Record<string, string>>;
128
- /** Get the linting rule descriptions as a JSON map, formatted in HTML. */
120
+ /** Get the linting rule descriptions as a JSON map, formatted in HTML.
121
+ * Wraps the function on the BinaryModule by the same name. */
129
122
  getLintDescriptionsHTMLAsJSON(): Promise<string>;
130
- /** Get the linting rule descriptions as an object, formatted in HTML */
123
+ /** Get the linting rule descriptions as an object, formatted in HTML.
124
+ * Wraps the function on the BinaryModule by the same name. */
131
125
  getLintDescriptionsHTML(): Promise<Record<string, string>>;
132
- /** Convert a string to Chicago-style title case. */
126
+ /** Convert a string to Chicago-style title case.
127
+ Wraps the function on the BinaryModule by the same name. */
133
128
  toTitleCase(text: string): Promise<string>;
134
129
  /** Ignore future instances of a lint from a previous linting run in future invocations. */
135
130
  ignoreLint(source: string, lint: Lint): Promise<void>;
@@ -253,6 +248,7 @@ declare class Linter_2 {
253
248
  lint(text: string, language: Language): Lint[];
254
249
  }
255
250
 
251
+ /** The properties and information needed to construct a Linter. */
256
252
  export declare interface LinterInit {
257
253
  /** The module or path to the WebAssembly binary. */
258
254
  binary: BinaryModule;
@@ -260,15 +256,16 @@ export declare interface LinterInit {
260
256
  dialect?: Dialect;
261
257
  }
262
258
 
263
- /** The option used to configure the parser for an individual linting operation. */
259
+ /** Options available to configure Harper's parser for an individual linting operation. */
264
260
  export declare interface LintOptions {
265
261
  /** The markup language that is being passed. Defaults to `markdown`. */
266
262
  language?: 'plaintext' | 'markdown';
267
263
  }
268
264
 
269
- /** A Linter that runs in the current JavaScript context (meaning it is allowed to block the event loop). */
265
+ /** A Linter that runs in the current JavaScript context (meaning it is allowed to block the event loop).
266
+ * See the interface definition for more details. */
270
267
  export declare class LocalLinter implements Linter {
271
- binary: BinaryModule;
268
+ binary: SuperBinaryModule;
272
269
  private inner;
273
270
  constructor(init: LinterInit);
274
271
  private createInner;
@@ -315,22 +312,6 @@ declare class OrganizedGroup {
315
312
  lints: Lint[];
316
313
  }
317
314
 
318
- /** Serializable argument to a procedure to be run on the web worker. */
319
- export declare interface RequestArg {
320
- json: string;
321
- type: SerializableTypes;
322
- }
323
-
324
- export declare type SerializableTypes = 'string' | 'number' | 'boolean' | 'object' | 'Suggestion' | 'Lint' | 'Span' | 'Array' | 'undefined' | 'bigint';
325
-
326
- /** An object that is sent to the web worker to request work to be done. */
327
- export declare interface SerializedRequest {
328
- /** The procedure to be executed. */
329
- procName: string;
330
- /** The arguments to the procedure */
331
- args: RequestArg[];
332
- }
333
-
334
315
  /**
335
316
  * A struct that represents two character indices in a string: a start and an end.
336
317
  */
@@ -382,7 +363,8 @@ export declare enum SuggestionKind {
382
363
  }
383
364
 
384
365
  /**
385
- * Represents the summary of linting results.
366
+ * Represents the summary of linting results and history.
367
+ * Useful to show linting statistics or insights to the user.
386
368
  */
387
369
  export declare interface Summary {
388
370
  /**
@@ -401,12 +383,18 @@ export declare interface Summary {
401
383
  misspelled: Record<string, number>;
402
384
  }
403
385
 
386
+ declare class SuperBinaryModule extends BinaryModule {
387
+ createLinter(dialect?: Dialect): Promise<Linter_2>;
388
+ getBinaryModule(): Promise<any>;
389
+ }
390
+
404
391
  /** A Linter that spins up a dedicated web worker to do processing on a separate thread.
405
392
  * Main benefit: this Linter will not block the event loop for large documents.
406
393
  *
407
394
  * NOTE: This class will not work properly in Node. In that case, just use `LocalLinter`. */
408
395
  export declare class WorkerLinter implements Linter {
409
396
  private binary;
397
+ private serializer;
410
398
  private dialect?;
411
399
  private worker;
412
400
  private requestQueue;