Skip to content

Commit f0a0a82

Browse files
committed
bumped deps
1 parent 048e056 commit f0a0a82

9 files changed

+427
-1323
lines changed

Diff for: lib/SpellCheckerBase.d.ts

-108
Original file line numberDiff line numberDiff line change
@@ -1,108 +0,0 @@
1-
import { SuggestedItem } from "./SuggestedItem";
2-
export interface WasmSymSpell extends WebAssembly.Exports {
3-
memory: WebAssembly.Memory;
4-
symspell: (dictionaryEditDistance: number, countThreshold: number) => void;
5-
lookup: (ptr: number, length: number, verbosity: Verbosity, maxEditDistance: number, includeUnknowns: boolean, includeSelf: boolean) => void;
6-
lookup_compound: (ptr: number, length: number, maxEditDistance: number) => void;
7-
write_to_dictionary: (prt: number, length: number, isBigram: boolean) => void;
8-
}
9-
export declare enum Verbosity {
10-
Top = 0,
11-
Closest = 1,
12-
All = 2
13-
}
14-
export interface SymSpellOptions {
15-
/**
16-
* The maximum Levenshtein distance to consider
17-
* when matching the input against the dictionary.
18-
* default=2 (0: no correction, word segmentation only)
19-
*/
20-
dictionaryEditDistance: number;
21-
/**
22-
* The minimum frequency count for dictionary words
23-
* to be considered correct spellings.
24-
*/
25-
countThreshold: number;
26-
}
27-
export interface CheckSpellingOptions {
28-
verbosity: Verbosity;
29-
maxEditDistance: number;
30-
includeUnknown: boolean;
31-
includeSelf: boolean;
32-
}
33-
export declare type ResultsHandler = (suggestedItems: SuggestedItem[]) => void;
34-
export declare const defaultOptions: SymSpellOptions;
35-
export declare const defaultCheckSpellingOptions: CheckSpellingOptions;
36-
/**
37-
* This class provides the wrapper for the spellcheck-wasm.wasm functionality.
38-
*/
39-
export declare abstract class SpellcheckerBase {
40-
protected wasmSymSpell: WasmSymSpell;
41-
protected writeBuffer: Uint8Array;
42-
/**
43-
* The handler set by the consumer to receive
44-
* suggested items from the wasm.
45-
*/
46-
resultHandler: ResultsHandler;
47-
protected constructor(resultHandler?: ResultsHandler);
48-
protected abstract encodeString(str: string): Uint8Array;
49-
/**
50-
* Writes a chunk of bytes to the dictionary. This operation is
51-
* useful when implementing a custom dictionary where additional
52-
* entries are required beyond the supplied corpus.
53-
*
54-
* Caution should be used since writing multiple megabytes at once
55-
* often results in a memory out of bounds error. Streaming at 32-64kb
56-
* chunks is recommended.
57-
*
58-
* @param chunk Uint8Array The chunk containing the bytes to write
59-
* @param isBigram boolean Indicates whether this chunk should be written to the bigram dictionary instead.
60-
*/
61-
writeToDictionary(chunk: Uint8Array, isBigram?: boolean): void;
62-
/**
63-
* Prepares the spellcheck wasm for use.
64-
*
65-
* @param wasmLocation
66-
* @param dictionaryLocation
67-
* @param bigramLocation
68-
* @param options
69-
*/
70-
abstract prepareSpellchecker(wasmLocation: string, dictionaryLocation: string, bigramLocation: string, options: SymSpellOptions): Promise<void>;
71-
abstract prepareSpellchecker(wasFetchResponse: Response, dictionaryFetchResponse: Response, bigramFetchResponse: Response, options: SymSpellOptions): Promise<void>;
72-
/**
73-
* Performs a single spelling check based on the supplied word and options.
74-
* The suggestions list will be provided to the resultHandler().
75-
*
76-
* @param word string The word to perform spell checking on.
77-
* @param options CheckSpellingOptions The options to use for this spell check lookup
78-
*/
79-
checkSpelling(word: Uint8Array | string, options?: CheckSpellingOptions): void;
80-
/**
81-
* Performs a spelling check based on the supplied sentence and options.
82-
* The suggestions list will be provided to the resultHandler().
83-
*
84-
* @param sentence string The sentence to perform spell checking on.
85-
* @param options CheckSpellingOptions The options to use for this spell check lookup
86-
*/
87-
checkSpellingCompound(sentence: Uint8Array | string, options?: Pick<CheckSpellingOptions, 'maxEditDistance'>): void;
88-
/**
89-
* @internal
90-
*
91-
* Traps responses form the wasm and converts them into
92-
* their respective SuggestedItem instances.
93-
*
94-
* @param ptr number The pointer in memory where this result set is located
95-
* @param length number The number of total bytes in the set
96-
*/
97-
protected resultTrap: (ptr: number, length: number) => void;
98-
/**
99-
* Allocations within the WASM process
100-
* detach reference to the memory buffer.
101-
* We check for this and create a new Uint8Array
102-
* with the new memory buffer reference if needed.
103-
*
104-
* @param chunk
105-
* @param memory
106-
*/
107-
protected writeToBuffer(chunk: Uint8Array, memory: WebAssembly.Memory): void;
108-
}

Diff for: lib/SpellCheckerBase.js

-118
Original file line numberDiff line numberDiff line change
@@ -1,118 +0,0 @@
1-
"use strict";
2-
Object.defineProperty(exports, "__esModule", { value: true });
3-
const SuggestedItem_1 = require("./SuggestedItem");
4-
var Verbosity;
5-
(function (Verbosity) {
6-
// Top suggestion with the highest term frequency of the suggestions of smallest edit distance found.
7-
Verbosity[Verbosity["Top"] = 0] = "Top";
8-
// All suggestions of smallest edit distance found, suggestions ordered by term frequency.
9-
Verbosity[Verbosity["Closest"] = 1] = "Closest";
10-
//All suggestions within maxEditDistance, suggestions ordered by edit distance
11-
// , then by term frequency (slower, no early termination).</summary>
12-
Verbosity[Verbosity["All"] = 2] = "All";
13-
})(Verbosity = exports.Verbosity || (exports.Verbosity = {}));
14-
exports.defaultOptions = {
15-
dictionaryEditDistance: 2,
16-
countThreshold: 1
17-
};
18-
exports.defaultCheckSpellingOptions = {
19-
includeUnknown: false,
20-
includeSelf: false,
21-
maxEditDistance: 2,
22-
verbosity: Verbosity.Closest
23-
};
24-
/**
25-
* This class provides the wrapper for the spellcheck-wasm.wasm functionality.
26-
*/
27-
class SpellcheckerBase {
28-
constructor(resultHandler) {
29-
/**
30-
* @internal
31-
*
32-
* Traps responses form the wasm and converts them into
33-
* their respective SuggestedItem instances.
34-
*
35-
* @param ptr number The pointer in memory where this result set is located
36-
* @param length number The number of total bytes in the set
37-
*/
38-
this.resultTrap = (ptr, length) => {
39-
const { memory } = this.wasmSymSpell;
40-
this.resultHandler(SuggestedItem_1.deserializeSuggestedItems(memory.buffer, ptr, length));
41-
};
42-
this.resultHandler = resultHandler;
43-
}
44-
/**
45-
* Writes a chunk of bytes to the dictionary. This operation is
46-
* useful when implementing a custom dictionary where additional
47-
* entries are required beyond the supplied corpus.
48-
*
49-
* Caution should be used since writing multiple megabytes at once
50-
* often results in a memory out of bounds error. Streaming at 32-64kb
51-
* chunks is recommended.
52-
*
53-
* @param chunk Uint8Array The chunk containing the bytes to write
54-
* @param isBigram boolean Indicates whether this chunk should be written to the bigram dictionary instead.
55-
*/
56-
writeToDictionary(chunk, isBigram = false) {
57-
this.writeToBuffer(chunk, this.wasmSymSpell.memory);
58-
this.wasmSymSpell.write_to_dictionary(0, chunk.byteLength, isBigram);
59-
}
60-
/**
61-
* Performs a single spelling check based on the supplied word and options.
62-
* The suggestions list will be provided to the resultHandler().
63-
*
64-
* @param word string The word to perform spell checking on.
65-
* @param options CheckSpellingOptions The options to use for this spell check lookup
66-
*/
67-
checkSpelling(word, options = exports.defaultCheckSpellingOptions) {
68-
const { lookup, memory } = this.wasmSymSpell;
69-
let encodedString;
70-
if (word instanceof Uint8Array) {
71-
encodedString = word;
72-
}
73-
else {
74-
encodedString = this.encodeString(word);
75-
}
76-
this.writeToBuffer(encodedString, memory);
77-
lookup(0, encodedString.byteLength, options.verbosity, options.maxEditDistance, options.includeUnknown, options.includeSelf);
78-
}
79-
/**
80-
* Performs a spelling check based on the supplied sentence and options.
81-
* The suggestions list will be provided to the resultHandler().
82-
*
83-
* @param sentence string The sentence to perform spell checking on.
84-
* @param options CheckSpellingOptions The options to use for this spell check lookup
85-
*/
86-
checkSpellingCompound(sentence, options = exports.defaultCheckSpellingOptions) {
87-
const { lookup_compound, memory } = this.wasmSymSpell;
88-
let encodedString;
89-
if (sentence instanceof Uint8Array) {
90-
encodedString = sentence;
91-
}
92-
else {
93-
encodedString = this.encodeString(sentence);
94-
}
95-
this.writeToBuffer(encodedString, memory);
96-
lookup_compound(0, encodedString.byteLength, options.maxEditDistance);
97-
}
98-
/**
99-
* Allocations within the WASM process
100-
* detach reference to the memory buffer.
101-
* We check for this and create a new Uint8Array
102-
* with the new memory buffer reference if needed.
103-
*
104-
* @param chunk
105-
* @param memory
106-
*/
107-
writeToBuffer(chunk, memory) {
108-
if (!this.writeBuffer || this.writeBuffer.buffer !== memory.buffer || this.writeBuffer.byteLength < chunk.byteLength) {
109-
if (memory.buffer.byteLength < chunk.byteLength) {
110-
const delta = Math.ceil((chunk.byteLength - memory.buffer.byteLength) / 65536); // 64 * 1024;
111-
memory.grow(delta);
112-
}
113-
this.writeBuffer = new Uint8Array(memory.buffer, 0, chunk.byteLength);
114-
}
115-
this.writeBuffer.set(chunk, 0);
116-
}
117-
}
118-
exports.SpellcheckerBase = SpellcheckerBase;

Diff for: lib/SuggestedItem.js

-65
Original file line numberDiff line numberDiff line change
@@ -1,65 +0,0 @@
1-
"use strict";
2-
Object.defineProperty(exports, "__esModule", { value: true });
3-
class SuggestedItem {
4-
constructor(data, ptr) {
5-
this.cache = {};
6-
this.data = data;
7-
this.ptr = ptr;
8-
}
9-
get count() {
10-
return this.cache.count || (this.cache.count = readU32(this.data, this.ptr));
11-
}
12-
get distance() {
13-
return this.cache.distance || (this.cache.distance = readU32(this.data, this.ptr + 4));
14-
}
15-
get term() {
16-
if (this.cache.term) {
17-
return this.cache.term;
18-
}
19-
const start = this.ptr + 12;
20-
const end = start + readU32(this.data, this.ptr + 8);
21-
return (this.cache.term = SuggestedItem.decodeString(this.data.slice(start, end)));
22-
}
23-
toJSON() {
24-
const { count, distance, term } = this;
25-
return { count, distance, term };
26-
}
27-
}
28-
exports.SuggestedItem = SuggestedItem;
29-
function readU32(buffer, ptr) {
30-
return (buffer[ptr + 3] << 24) | (buffer[ptr + 2] << 16) | (buffer[ptr + 1] << 8) | buffer[ptr];
31-
}
32-
exports.readU32 = readU32;
33-
/**
34-
* Suggested items are encoded by the wasm to be as compact as possible and
35-
* reside in the wasm ArrayBuffer. This function slices that ArrayBuffer into
36-
* the data representing each SuggestedItem and supplies it as the data source
37-
* for all properties within the respective SuggestedItem.
38-
*
39-
* This is not JSON encoded data since JSON tokens often exceed the data they
40-
* encapsulate making them far less efficient.
41-
*
42-
*
43-
* @param buffer ArrayBufferLike The ArrayBuffer from the wasm memory export.
44-
* @param ptr number The beginning byte for the SuggestedItems
45-
* @param length number The total number of byes comprising all suggested items in memory.
46-
*/
47-
function deserializeSuggestedItems(buffer, ptr, length) {
48-
const rawSlice = new Uint8Array(buffer.slice(ptr, ptr + length));
49-
ptr = 0; // pointer resets to zero when we slice
50-
// Find each position of the encoded suggest item
51-
// within the buffer
52-
const numItems = readU32(rawSlice, 0); // bytes 0-3 represent the u32 of total items encoded in LE
53-
ptr += 4;
54-
const suggestedItems = [];
55-
for (let i = 0; i < numItems; i++) {
56-
const itemLen = readU32(rawSlice, ptr); //bytes ptr + 3 represent the number of bytes in each item encoded in LE
57-
ptr += 4;
58-
// All suggested items share the same slice but the pointer
59-
// is updated to indicate where the property values start.
60-
suggestedItems[i] = new SuggestedItem(rawSlice, ptr);
61-
ptr += itemLen;
62-
}
63-
return suggestedItems;
64-
}
65-
exports.deserializeSuggestedItems = deserializeSuggestedItems;

Diff for: lib/frequency_bigramdictionary_en_243_342.txt.gz

-1.86 MB
Binary file not shown.

Diff for: lib/frequency_dictionary_en_82_765.txt.gz

-613 KB
Binary file not shown.
-695 KB
Binary file not shown.

Diff for: lib/spellchecker-wasm.js

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
export * from "./spellchecker-wasm.wasm_bg.js";

Diff for: lib/spellchecker-wasm.wasm

1.07 KB
Binary file not shown.

0 commit comments

Comments
 (0)