node-sword-interface 1.0.26 → 1.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/API.md CHANGED
@@ -65,6 +65,7 @@ This is the main class of node-sword-interface and it provides a set of static f
65
65
  * [.getBibleText(moduleCode)](#NodeSwordInterface+getBibleText) ⇒ [<code>Array.&lt;VerseObject&gt;</code>](#VerseObject)
66
66
  * [.getBookIntroduction(moduleCode, bookCode)](#NodeSwordInterface+getBookIntroduction) ⇒ <code>String</code>
67
67
  * [.moduleHasBook(moduleCode, bookCode)](#NodeSwordInterface+moduleHasBook) ⇒ <code>Boolean</code>
68
+ * [.getDictModuleKeys(moduleCode)](#NodeSwordInterface+getDictModuleKeys) ⇒ <code>Array.&lt;String&gt;</code>
68
69
  * [.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, searchScope, isCaseSensitive, useExtendedVerseBoundaries)](#NodeSwordInterface+getModuleSearchResults) ⇒ <code>Promise</code>
69
70
  * [.terminateModuleSearch()](#NodeSwordInterface+terminateModuleSearch)
70
71
  * [.hebrewStrongsAvailable()](#NodeSwordInterface+hebrewStrongsAvailable) ⇒ <code>Boolean</code>
@@ -494,7 +495,7 @@ Returns the introduction of the given book.
494
495
  <a name="NodeSwordInterface+moduleHasBook"></a>
495
496
 
496
497
  ### nodeSwordInterface.moduleHasBook(moduleCode, bookCode) ⇒ <code>Boolean</code>
497
- Checks whether a module has a certain book
498
+ Checks whether a module has a certain book.
498
499
 
499
500
  **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
500
501
 
@@ -503,6 +504,17 @@ Checks whether a module has a certain book
503
504
  | moduleCode | <code>String</code> |
504
505
  | bookCode | <code>String</code> |
505
506
 
507
+ <a name="NodeSwordInterface+getDictModuleKeys"></a>
508
+
509
+ ### nodeSwordInterface.getDictModuleKeys(moduleCode) ⇒ <code>Array.&lt;String&gt;</code>
510
+ Returns the keys of a dictionary module.
511
+
512
+ **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
513
+
514
+ | Param | Type |
515
+ | --- | --- |
516
+ | moduleCode | <code>String</code> |
517
+
506
518
  <a name="NodeSwordInterface+getModuleSearchResults"></a>
507
519
 
508
520
  ### nodeSwordInterface.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, searchScope, isCaseSensitive, useExtendedVerseBoundaries) ⇒ <code>Promise</code>
package/CMakeLists.txt CHANGED
@@ -38,6 +38,7 @@ ${CMAKE_SOURCE_DIR}/src/sword_backend/module_store.cpp
38
38
  ${CMAKE_SOURCE_DIR}/src/sword_backend/repository_interface.cpp
39
39
  ${CMAKE_SOURCE_DIR}/src/sword_backend/sword_status_reporter.cpp
40
40
  ${CMAKE_SOURCE_DIR}/src/sword_backend/module_helper.cpp
41
+ ${CMAKE_SOURCE_DIR}/src/sword_backend/dict_helper.cpp
41
42
  ${CMAKE_SOURCE_DIR}/src/sword_backend/string_helper.cpp
42
43
  ${CMAKE_SOURCE_DIR}/src/sword_backend/file_system_helper.cpp
43
44
  ${CMAKE_SOURCE_DIR}/src/sword_backend/module_installer.cpp
package/binding.gyp CHANGED
@@ -58,6 +58,7 @@
58
58
  "src/sword_backend/mutex.cpp",
59
59
  "src/sword_backend/file_system_helper.cpp",
60
60
  "src/sword_backend/module_helper.cpp",
61
+ "src/sword_backend/dict_helper.cpp",
61
62
  "src/sword_backend/module_store.cpp",
62
63
  "src/sword_backend/string_helper.cpp",
63
64
  "src/sword_backend/strongs_entry.cpp",
package/index.js CHANGED
@@ -547,16 +547,26 @@ class NodeSwordInterface {
547
547
  }
548
548
 
549
549
  /**
550
- * Checks whether a module has a certain book
550
+ * Checks whether a module has a certain book.
551
551
  *
552
552
  * @param {String} moduleCode
553
553
  * @param {String} bookCode
554
- * @returns {Boolean}
554
+ * @return {Boolean}
555
555
  */
556
556
  moduleHasBook(moduleCode, bookCode) {
557
557
  return this.nativeInterface.moduleHasBook(moduleCode, bookCode);
558
558
  }
559
559
 
560
+ /**
561
+ * Returns the keys of a dictionary module.
562
+ *
563
+ * @param {String} moduleCode
564
+ * @return {String[]}
565
+ */
566
+ getDictModuleKeys(moduleCode) {
567
+ return this.nativeInterface.getDictModuleKeys(moduleCode);
568
+ }
569
+
560
570
  /**
561
571
  * Returns the results of a module search.
562
572
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "repository": {
30
30
  "type": "git",
31
- "url": "https://github.com/ezra-bible-app/node-sword-interface.git"
31
+ "url": "git+https://github.com/ezra-bible-app/node-sword-interface.git"
32
32
  },
33
33
  "devDependencies": {
34
34
  "jsdoc-to-markdown": "^8.0.3",
@@ -34,6 +34,7 @@
34
34
  #include "module_store.hpp"
35
35
  #include "module_installer.hpp"
36
36
  #include "module_helper.hpp"
37
+ #include "dict_helper.hpp"
37
38
  #include "text_processor.hpp"
38
39
  #include "module_search.hpp"
39
40
  #include "mutex.hpp"
@@ -101,6 +102,7 @@ Napi::Object NodeSwordInterface::Init(Napi::Env env, Napi::Object exports)
101
102
  InstanceMethod("getChapterVerseCount", &NodeSwordInterface::getChapterVerseCount),
102
103
  InstanceMethod("getBookIntroduction", &NodeSwordInterface::getBookIntroduction),
103
104
  InstanceMethod("moduleHasBook", &NodeSwordInterface::moduleHasBook),
105
+ InstanceMethod("getDictModuleKeys", &NodeSwordInterface::getDictModuleKeys),
104
106
  InstanceMethod("getModuleSearchResults", &NodeSwordInterface::getModuleSearchResults),
105
107
  InstanceMethod("terminateModuleSearch", &NodeSwordInterface::terminateModuleSearch),
106
108
  InstanceMethod("getStrongsEntry", &NodeSwordInterface::getStrongsEntry),
@@ -174,6 +176,7 @@ NodeSwordInterface::NodeSwordInterface(const Napi::CallbackInfo& info) : Napi::O
174
176
  if (!homeDirError && !localeDirError) { // We only proceed if there has not been any issue with the homeDir or localeDir
175
177
  this->_moduleStore = new ModuleStore(this->customHomeDir);
176
178
  this->_moduleHelper = new ModuleHelper(*(this->_moduleStore));
179
+ this->_dictHelper = new DictHelper(*(this->_moduleStore));
177
180
  this->_repoInterface = new RepositoryInterface(this->_swordStatusReporter, *(this->_moduleHelper), *(this->_moduleStore), this->customHomeDir);
178
181
  this->_moduleInstaller = new ModuleInstaller(*(this->_repoInterface), *(this->_moduleStore), this->customHomeDir);
179
182
  this->_napiSwordHelper = new NapiSwordHelper(*(this->_moduleHelper), *(this->_moduleStore));
@@ -710,6 +713,21 @@ Napi::Value NodeSwordInterface::moduleHasBook(const Napi::CallbackInfo& info)
710
713
  return hasBook;
711
714
  }
712
715
 
716
+ Napi::Value NodeSwordInterface::getDictModuleKeys(const Napi::CallbackInfo& info)
717
+ {
718
+ lockApi();
719
+ Napi::Env env = info.Env();
720
+ INIT_SCOPE_AND_VALIDATE(ParamType::string);
721
+ Napi::String moduleName = info[0].As<Napi::String>();
722
+ ASSERT_SW_MODULE_EXISTS(moduleName);
723
+
724
+ vector<string> dictModuleKeys = this->_dictHelper->getKeyList(moduleName);
725
+ Napi::Array dictModuleKeyArray = this->_napiSwordHelper->getNapiArrayFromStringVector(env, dictModuleKeys);
726
+
727
+ unlockApi();
728
+ return dictModuleKeyArray;
729
+ }
730
+
713
731
  Napi::Value NodeSwordInterface::getModuleSearchResults(const Napi::CallbackInfo& info)
714
732
  {
715
733
  lockApi();
@@ -29,6 +29,7 @@ class ModuleInstaller;
29
29
  class TextProcessor;
30
30
  class NapiSwordHelper;
31
31
  class ModuleHelper;
32
+ class DictHelper;
32
33
  class ModuleSearch;
33
34
  class ModuleSearchWorker;
34
35
  enum class ModuleType;
@@ -82,6 +83,7 @@ private:
82
83
  Napi::Value getChapterVerseCount(const Napi::CallbackInfo& info);
83
84
  Napi::Value getBookIntroduction(const Napi::CallbackInfo& info);
84
85
  Napi::Value moduleHasBook(const Napi::CallbackInfo& info);
86
+ Napi::Value getDictModuleKeys(const Napi::CallbackInfo& info);
85
87
 
86
88
  Napi::Value getModuleSearchResults(const Napi::CallbackInfo& info);
87
89
  Napi::Value terminateModuleSearch(const Napi::CallbackInfo& info);
@@ -104,6 +106,7 @@ private:
104
106
  bool dirExists(const Napi::CallbackInfo& info, std::string dirName);
105
107
 
106
108
  ModuleHelper* _moduleHelper;
109
+ DictHelper* _dictHelper;
107
110
  NapiSwordHelper* _napiSwordHelper;
108
111
  RepositoryInterface* _repoInterface;
109
112
  ModuleStore* _moduleStore;
@@ -3,6 +3,7 @@
3
3
  #include "module_store.hpp"
4
4
  #include "text_processor.hpp"
5
5
  #include "module_helper.hpp"
6
+ #include "dict_helper.hpp"
6
7
  #include "module_installer.hpp"
7
8
  #include "strongs_entry.hpp"
8
9
  #include "module_search.hpp"
@@ -126,6 +127,17 @@ void get_book_list(ModuleHelper& module_helper)
126
127
  }
127
128
  }
128
129
 
130
+ void get_dict_key_list(DictHelper& dict_helper)
131
+ {
132
+ vector<string> keyList = dict_helper.getKeyList("Vines");
133
+
134
+ cout << "Got " << keyList.size() << " entries!" << endl;
135
+
136
+ for (int i = 0; i < keyList.size(); i++) {
137
+ cout << keyList[i] << endl;
138
+ }
139
+ }
140
+
129
141
  void test_unlock_key(ModuleInstaller& module_installer, ModuleStore& module_store, TextProcessor& text_processor)
130
142
  {
131
143
  module_installer.uninstallModule("NA28");
@@ -167,6 +179,7 @@ int main(int argc, char** argv)
167
179
  {
168
180
  ModuleStore moduleStore;
169
181
  ModuleHelper moduleHelper(moduleStore);
182
+ DictHelper dictHelper(moduleStore);
170
183
  SwordStatusReporter statusReporter;
171
184
  RepositoryInterface repoInterface(statusReporter, moduleHelper, moduleStore);
172
185
  ModuleInstaller moduleInstaller(repoInterface, moduleStore);
@@ -209,7 +222,7 @@ int main(int argc, char** argv)
209
222
  /*sword_facade.installModule("StrongsHebrew");
210
223
  sword_facade.installModule("StrongsGreek");*/
211
224
 
212
- get_strongs_entry(textProcessor);
225
+ //get_strongs_entry(textProcessor);
213
226
 
214
227
  //get_module_text(textProcessor);
215
228
 
@@ -217,6 +230,8 @@ int main(int argc, char** argv)
217
230
 
218
231
  //get_book_list(moduleHelper);
219
232
 
233
+ get_dict_key_list(dictHelper);
234
+
220
235
  //string translation = sword_facade.getSwordTranslation(string("/usr/share/sword/locales.d"), string("de"), string("locales"));
221
236
  //cout << translation << endl;
222
237
 
@@ -0,0 +1,69 @@
1
+ /* This file is part of node-sword-interface.
2
+
3
+ Copyright (C) 2019 - 2024 Tobias Klein <contact@tklein.info>
4
+
5
+ node-sword-interface is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ node-sword-interface is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with node-sword-interface. See the file COPYING.
17
+ If not, see <http://www.gnu.org/licenses/>. */
18
+
19
+ // Sword includes
20
+ #include <swmodule.h>
21
+ #include <swld.h>
22
+
23
+ #include "dict_helper.hpp"
24
+
25
+ using namespace std;
26
+ using namespace sword;
27
+
28
+ std::vector<std::string> DictHelper::getKeyList(std::string moduleName)
29
+ {
30
+ vector<string> keyList;
31
+
32
+ if (moduleName.size() == 0) {
33
+ cerr << "getKeyList: Cannot work with empty moduleName!" << endl;
34
+ return keyList;
35
+ }
36
+
37
+ SWModule* module = this->_moduleStore.getLocalModule(moduleName);
38
+
39
+ if (module == 0) {
40
+ cerr << "getLocalModule returned zero pointer for " << moduleName << endl;
41
+
42
+ } else {
43
+ const char* moduleType = module->getType();
44
+
45
+ if (strcmp(moduleType, "Lexicons / Dictionaries") != 0) {
46
+
47
+ cerr << "Given module is not a lexicon/dictionary!" << endl;
48
+
49
+ } else {
50
+ sword::SWLD* swldModule = static_cast<sword::SWLD*>(module);
51
+
52
+ if (swldModule == NULL) {
53
+
54
+ cerr << "Could not initialize module " << moduleName << " as SWLD module." << endl;
55
+
56
+ } else {
57
+ long entryCount = swldModule->getEntryCount();
58
+
59
+ for (long i = 0; i < entryCount; i++) {
60
+ const char* key = swldModule->getKeyForEntry(i);
61
+ string stringKey = string(key);
62
+ keyList.push_back(stringKey);
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ return keyList;
69
+ }
@@ -0,0 +1,39 @@
1
+ /* This file is part of node-sword-interface.
2
+
3
+ Copyright (C) 2019 - 2024 Tobias Klein <contact@tklein.info>
4
+
5
+ node-sword-interface is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ node-sword-interface is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with node-sword-interface. See the file COPYING.
17
+ If not, see <http://www.gnu.org/licenses/>. */
18
+
19
+ #ifndef _DICT_HELPER
20
+ #define _DICT_HELPER
21
+
22
+ #include <string>
23
+ #include <vector>
24
+
25
+ #include "module_store.hpp"
26
+
27
+ class DictHelper {
28
+ public:
29
+ DictHelper(ModuleStore& moduleStore) : _moduleStore(moduleStore) {}
30
+
31
+ std::vector<std::string> getKeyList(std::string moduleName);
32
+
33
+ virtual ~DictHelper(){}
34
+
35
+ private:
36
+ ModuleStore& _moduleStore;
37
+ };
38
+
39
+ #endif // _DICT_HELPER
@@ -83,9 +83,12 @@ bool ModuleHelper::moduleHasBook(sword::SWModule* module, std::string bookCode)
83
83
  For apocryphal books we may get "Rev 1:1" as actual module key and this will mismatch with the set key
84
84
  and then indicate that the book is not existing. */
85
85
 
86
- if (moduleKeyText != key.str()) {
86
+ // We compare the first three letters of the two keys to see whether the key retrieved matches the key we are looking for
87
+ if (moduleKeyText.size() >= 3 && key.str().size() >= 3 && moduleKeyText.substr(0,3) != key.str().substr(0,3)) {
87
88
  hasBook = false;
88
89
  } else {
90
+ // The first three letters of the key seem ok.
91
+ // Now let's check next whether the module has the corresponding entry.
89
92
  hasBook = module->hasEntry(module->getKey());
90
93
  }
91
94