diff --git a/lib/spellchecker.js b/lib/spellchecker.js index 4d3523f..5623bdb 100644 --- a/lib/spellchecker.js +++ b/lib/spellchecker.js @@ -5,6 +5,7 @@ var bindings = require('../build/Release/spellchecker.node'); var Spellchecker = bindings.Spellchecker; var defaultSpellcheck = null; +var dictionaryBaseURL = "https://redirector.gvt1.com/edgedl/chrome/dict/"; var ensureDefaultSpellCheck = function() { if (defaultSpellcheck) { @@ -74,16 +75,22 @@ var getDictionaryPath = function() { return dict; } +var setBaseUrlForHunspellDictionary = function(url) { + if(url && url.length > 0){ + dictionaryBaseURL = url + } +} + var getURLForHunspellDictionary = function(lang) { // NB: This is derived from https://code.google.com/p/chromium/codesearch#chromium/src/chrome/common/spellcheck_common.cc&sq=package:chromium&type=cs&rcl=1464736770&l=107 var defaultVersion = '-3-0'; var specialVersions = { 'tr-tr': '-4-0', 'tg-tg': '-5-0', - 'en-ca': '-7-1', - 'en-gb': '-7-1', - 'en-us': '-7-1', - 'fa-ir': '-7-0', + 'en-ca': '-8-0', + 'en-gb': '-8-0', + 'en-us': '-8-0', + 'fa-ir': '-8-0', }; var nonFormedLangCode = ['ko', 'sh', 'sq', 'sr']; @@ -98,7 +105,7 @@ var getURLForHunspellDictionary = function(lang) { } } - return "https://redirector.gvt1.com/edgedl/chrome/dict/" + langCode + (specialVersions[langCode] || defaultVersion) + ".bdic"; + return dictionaryBaseURL + langCode + (specialVersions[langCode] || defaultVersion) + ".bdic"; } module.exports = { @@ -110,5 +117,6 @@ module.exports = { getAvailableDictionaries: getAvailableDictionaries, getCorrectionsForMisspelling: getCorrectionsForMisspelling, getURLForHunspellDictionary: getURLForHunspellDictionary, + setBaseUrlForHunspellDictionary: setBaseUrlForHunspellDictionary, Spellchecker: Spellchecker }; diff --git a/package.json b/package.json index 08e747f..ac588f3 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "main": "./lib/spellchecker.js", - "name": "spellchecker", + "name": "node-spellcheckr", "description": "Bindings to native spellchecker", - "version": "4.0.0", + "version": "4.0.3", "licenses": [ { "type": "MIT", @@ -24,6 +24,6 @@ "jasmine-focused": "1.x" }, "dependencies": { - "nan": "^2.0.0" + "nan": "^2.14.0" } } diff --git a/src/main.cc b/src/main.cc index 8509edc..fc7e296 100644 --- a/src/main.cc +++ b/src/main.cc @@ -72,7 +72,7 @@ class Spellchecker : public Nan::ObjectWrap { return Nan::ThrowError("Bad argument"); } - Handle string = Handle::Cast(info[0]); + Local string = Local::Cast(info[0]); if (!string->IsString()) { return Nan::ThrowError("Bad argument"); } @@ -96,9 +96,9 @@ class Spellchecker : public Nan::ObjectWrap { uint32_t start = iter->start, end = iter->end; Local misspelled_range = Nan::New(); - misspelled_range->Set(Nan::New("start").ToLocalChecked(), Nan::New(start)); - misspelled_range->Set(Nan::New("end").ToLocalChecked(), Nan::New(end)); - result->Set(index, misspelled_range); + Nan::Set(misspelled_range, Nan::New("start").ToLocalChecked(), Nan::New(start)); + Nan::Set(misspelled_range, Nan::New("end").ToLocalChecked(), Nan::New(end)); + Nan::Set(result, index, misspelled_range); } } @@ -145,7 +145,7 @@ class Spellchecker : public Nan::ObjectWrap { Local result = Nan::New(dictionaries.size()); for (size_t i = 0; i < dictionaries.size(); ++i) { const std::string& dict = dictionaries[i]; - result->Set(i, Nan::New(dict.data(), dict.size()).ToLocalChecked()); + Nan::Set(result, i, Nan::New(dict.data(), dict.size()).ToLocalChecked()); } info.GetReturnValue().Set(result); @@ -168,7 +168,7 @@ class Spellchecker : public Nan::ObjectWrap { const std::string& word = corrections[i]; Nan::MaybeLocal val = Nan::New(word.data(), word.size()); - result->Set(i, val.ToLocalChecked()); + Nan::Set(result, i, val.ToLocalChecked()); } info.GetReturnValue().Set(result); @@ -184,7 +184,7 @@ class Spellchecker : public Nan::ObjectWrap { } public: - static void Init(Handle exports) { + static void Init(Local exports) { Local tpl = Nan::New(Spellchecker::New); tpl->SetClassName(Nan::New("Spellchecker").ToLocalChecked()); @@ -198,12 +198,12 @@ class Spellchecker : public Nan::ObjectWrap { Nan::SetMethod(tpl->InstanceTemplate(), "add", Spellchecker::Add); Nan::SetMethod(tpl->InstanceTemplate(), "remove", Spellchecker::Remove); - exports->Set(Nan::New("Spellchecker").ToLocalChecked(), tpl->GetFunction()); + Nan::Set(exports, Nan::New("Spellchecker").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked()); } }; -void Init(Handle exports, Handle module) { - Spellchecker::Init(exports); +NAN_MODULE_INIT(Init) { + Spellchecker::Init(target); } } // namespace