Skip to content

Commit

Permalink
* add a temporary declaration for the spellchecker module
Browse files Browse the repository at this point in the history
  • Loading branch information
ConorMurphy21 committed Dec 25, 2023
1 parent 4cf7ec8 commit 0a7dd2d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 19 deletions.
8 changes: 4 additions & 4 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"@types/node": "^20.10.5",
"@types/parameterize": "^1.0.3",
"@types/pluralize": "^0.0.33",
"@types/spellchecker": "^3.5.2",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"chai": "^4.3.4",
Expand Down
2 changes: 1 addition & 1 deletion server/src/models/gameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class GameState {
_getTimeLeft(timeout: NodeJS.Timeout) {
// todo: do this in a safer way
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// ts-expect-error
// @ts-expect-error
return Math.ceil((timeout._idleStart + timeout._idleTimeout) / 1000 - process.uptime());
}

Expand Down
70 changes: 70 additions & 0 deletions server/src/models/spellchecker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* ---------------------------------------------------------------------------
Custom Types / Interfaces
--------------------------------------------------------------------------- */
// this is a temporary type declaration, hopefully there will be a more complete @types/spellchecker soon
declare module 'spellchecker' {
/**
* MisspelledLocation - shape of an object returned by checkSpelling to
* identify locations of misspelled words in a corpus.
* @description a misspelled word can be found by corpus.slice(start, end)
* start - start index of a misspelled word in a corpus
* end - end index of a misspelled word in a corpus
*/
export interface MisspelledLocation {
start: number;
end: number;
}

/* ---------------------------------------------------------------------------
Methods
--------------------------------------------------------------------------- */
/**
* Spellchecker.isMisspelled - Check if a word is misspelled.
* @param word - String word to check.
* @returns boolean - true if the word is misspelled, false otherwise.
*/
export function isMisspelled(word: string): boolean;

/**
* Spellchecker.getCorrectionsForMisspelling - Get the corrections for a misspelled word.
* @param word - String word to get corrections for.
* @returns array - Returns a non-null but possibly empty array of string corrections.
*/
export function getCorrectionsForMisspelling(word: string): string[];

/**
* Spellchecker.checkSpelling - Identify misspelled words in a corpus of text.
* @param corpus - String corpus of text to spellcheck.
* @returns array - Returns an Array containing {start, end} objects that describe an
* index range within the original String that contains a misspelled word.
*/
export function checkSpelling(corpus: string): MisspelledLocation[];

/**
* Spellchecker.checkSpellingAsync - Asynchronously identify misspelled words.
* @param corpus - String corpus of text to spellcheck.
* @returns array - Returns a Promise that resolves with the Array described by checkSpelling().
*/
export function checkSpellingAsync(corpus: string): Promise<MisspelledLocation[]>;

/**
* Spellchecker.add - Adds a word to the dictionary.
* When using Hunspell, this will not modify the .dic file;
* new words must be added each time the spellchecker is created. Use a custom dictionary file.
* @param word - String word to add.
* @returns void
*/
export function add(word: string): void;

export const ALWAYS_USE_HUNSPELL: string;

export class Spellchecker {
setSpellcheckerType(type: string): void;

setDictionary(lang: string, file: string): void;

isMisspelled(word: string): boolean;

getCorrectionsForMisspelling(word: string): string[];
}
}

0 comments on commit 0a7dd2d

Please sign in to comment.