hunspell-dict-downloader
v1.1.0
Published
Hunspell based dictionary downloader for node.js
Downloads
3
Readme
hunspell-dict-downloader
hunspell-dict-downloader
provides interface to manage hunspell-based dictionaries via javascript on node.js. There are about 40 language dictionaries available.
Install
npm install hunspell-dict-downloader
Usage
Initialize location to manage dictionary
createDownloader
interface provides way to initialize location to store dictionaries.
createDownloader(installPath: string): Promise<HunspellDictDownloader>
If given path has previously installed dictionaries, it'll be loaded into installedDictionaries
.
Manage dictionaries
HunspellDictDownloader
provides few interfaces to manage dictionaries.
interface HunspellDictDownloader {
/**
* Returns array of available dictionary can be installed.
*/
availableDictionaries: Readonly<Array<CODE_LANG_REGION>>;
/**
* Returns array of currently installed dictionary.
*/
installedDictionaries: Readonly<Array<CODE_LANG_REGION>>;
/**
* Object maps language to dictionary location for installed dictionary.
*/
dictionaryLocation: Readonly<{ [index in CODE_LANG_REGION]: { dic: string; aff: string } }>;
/**
* Returns mapped LANG_REGION code from LANG code
*/
getLanguageRegionCode(code: CODE_LANG_REGION | CODE_LANG): CODE_LANG_REGION;
/**
* Download new dictionary and install it.
* If dictionary package has been downloaded previously and if it's valid
* it'll be installed without re downloading whole package.
*
* NOTE: It is not thread safety and multple attempt to download same
* language does not gaurantee validaty of installed dictionary.
*
* @param {CODE_LANG_REGION | CODE_LANG} code
* @returns Promise resolves path to installed dictionary.
*/
installDictionary(code: CODE_LANG_REGION | CODE_LANG): Promise<{ dic: string; aff: string }>;
/**
* Delete installed dicationry.
* @param {CODE_LANG_REGION | CODE_LANG} code
*/
uninstallDictionary(code: CODE_LANG_REGION | CODE_LANG): Promise<void>;
/**
* Clear cache of dictionary previously downloaded.
* This'll make next attempt to download dictionary should ask remote endpoint.
*/
clearCache(): Promise<void>;
}
Building / Testing
Few npm scripts are supported for build / test code.
build
: Transpiles code to ES5 commonjs todist
.test
: Run unit tests.manifest:generate
: Update dictionary manifest file.manifest:validate
: Integration tests, actually download dictionary and verify installed correctly.lint
: Run lint over all codebaseslint:staged
: Run lint only for staged changes. This'll be executed automatically with precommit hook.commit
: Commit wizard to write commit message