From e16cf20cace33d58fe2d18d1461960165e1cac57 Mon Sep 17 00:00:00 2001 From: Ron Wang Date: Tue, 7 May 2019 17:44:28 -0700 Subject: [PATCH 1/4] Implements overwrite dictionary base url function --- lib/spellchecker.js | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/spellchecker.js b/lib/spellchecker.js index 4d3523f..1cde4fe 100644 --- a/lib/spellchecker.js +++ b/lib/spellchecker.js @@ -1,10 +1,26 @@ var path = require('path'); var fs = require('fs'); +var Promise = require('any-promise'); var bindings = require('../build/Release/spellchecker.node'); var Spellchecker = bindings.Spellchecker; +var checkSpellingAsyncCb = Spellchecker.prototype.checkSpellingAsync + +Spellchecker.prototype.checkSpellingAsync = function (corpus) { + return new Promise(function (resolve, reject) { + checkSpellingAsyncCb.call(this, corpus, function (err, result) { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }.bind(this)); +}; + var defaultSpellcheck = null; +var dictionaryBaseURL = "https://redirector.gvt1.com/edgedl/chrome/dict/"; var ensureDefaultSpellCheck = function() { if (defaultSpellcheck) { @@ -45,6 +61,12 @@ var checkSpelling = function() { return defaultSpellcheck.checkSpelling.apply(defaultSpellcheck, arguments); }; +var checkSpellingAsync = function(corpus) { + ensureDefaultSpellCheck(); + + return defaultSpellcheck.checkSpellingAsync.apply(defaultSpellcheck, arguments); +}; + var add = function() { ensureDefaultSpellCheck(); @@ -74,16 +96,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 +126,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 = { @@ -107,8 +135,10 @@ module.exports = { remove: remove, isMisspelled: isMisspelled, checkSpelling: checkSpelling, + checkSpellingAsync: checkSpellingAsync, getAvailableDictionaries: getAvailableDictionaries, getCorrectionsForMisspelling: getCorrectionsForMisspelling, getURLForHunspellDictionary: getURLForHunspellDictionary, + setBaseUrlForHunspellDictionary: setBaseUrlForHunspellDictionary, Spellchecker: Spellchecker }; From 57bbb2f6c2fe3ccaf08af8a3293c97dab21fbe9c Mon Sep 17 00:00:00 2001 From: Ron Wang Date: Thu, 9 May 2019 16:52:28 -0700 Subject: [PATCH 2/4] Removing async spell check --- lib/spellchecker.js | 22 ---------------------- package.json | 4 ++-- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/lib/spellchecker.js b/lib/spellchecker.js index 1cde4fe..5623bdb 100644 --- a/lib/spellchecker.js +++ b/lib/spellchecker.js @@ -1,24 +1,9 @@ var path = require('path'); var fs = require('fs'); -var Promise = require('any-promise'); var bindings = require('../build/Release/spellchecker.node'); var Spellchecker = bindings.Spellchecker; -var checkSpellingAsyncCb = Spellchecker.prototype.checkSpellingAsync - -Spellchecker.prototype.checkSpellingAsync = function (corpus) { - return new Promise(function (resolve, reject) { - checkSpellingAsyncCb.call(this, corpus, function (err, result) { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }.bind(this)); -}; - var defaultSpellcheck = null; var dictionaryBaseURL = "https://redirector.gvt1.com/edgedl/chrome/dict/"; @@ -61,12 +46,6 @@ var checkSpelling = function() { return defaultSpellcheck.checkSpelling.apply(defaultSpellcheck, arguments); }; -var checkSpellingAsync = function(corpus) { - ensureDefaultSpellCheck(); - - return defaultSpellcheck.checkSpellingAsync.apply(defaultSpellcheck, arguments); -}; - var add = function() { ensureDefaultSpellCheck(); @@ -135,7 +114,6 @@ module.exports = { remove: remove, isMisspelled: isMisspelled, checkSpelling: checkSpelling, - checkSpellingAsync: checkSpellingAsync, getAvailableDictionaries: getAvailableDictionaries, getCorrectionsForMisspelling: getCorrectionsForMisspelling, getURLForHunspellDictionary: getURLForHunspellDictionary, diff --git a/package.json b/package.json index 08e747f..5cf28da 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.1", "licenses": [ { "type": "MIT", From e647cb26e3dc43e8b8fd304f2560528d6753b5dc Mon Sep 17 00:00:00 2001 From: Aleksei Kuzmin Date: Mon, 20 Jan 2020 15:51:03 +0100 Subject: [PATCH 3/4] chore: add compatibility with Electron 7 Bump version to 4.0.2. --- package.json | 4 ++-- src/main.cc | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 5cf28da..a07c2ec 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "main": "./lib/spellchecker.js", "name": "node-spellcheckr", "description": "Bindings to native spellchecker", - "version": "4.0.1", + "version": "4.0.2", "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 From c2c1c03c73bbad88085659bc00e665d890e74ffe Mon Sep 17 00:00:00 2001 From: Aleksei Kuzmin Date: Wed, 29 Jan 2020 22:49:24 +0100 Subject: [PATCH 4/4] chore: bump version to 4.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a07c2ec..ac588f3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "main": "./lib/spellchecker.js", "name": "node-spellcheckr", "description": "Bindings to native spellchecker", - "version": "4.0.2", + "version": "4.0.3", "licenses": [ { "type": "MIT",