node-sword-interface 0.238.0 → 0.242.0

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
@@ -61,7 +61,7 @@ This is the main class of node-sword-interface and it provides a set of static f
61
61
  * [.getBibleText(moduleCode)](#NodeSwordInterface+getBibleText) ⇒ [<code>Array.&lt;VerseObject&gt;</code>](#VerseObject)
62
62
  * [.getBookIntroduction(moduleCode, bookCode)](#NodeSwordInterface+getBookIntroduction) ⇒ <code>String</code>
63
63
  * [.moduleHasBook(moduleCode, bookCode)](#NodeSwordInterface+moduleHasBook) ⇒ <code>Boolean</code>
64
- * [.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, isCaseSensitive, useExtendedVerseBoundaries)](#NodeSwordInterface+getModuleSearchResults) ⇒ <code>Promise</code>
64
+ * [.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, searchScope, isCaseSensitive, useExtendedVerseBoundaries)](#NodeSwordInterface+getModuleSearchResults) ⇒ <code>Promise</code>
65
65
  * [.terminateModuleSearch()](#NodeSwordInterface+terminateModuleSearch)
66
66
  * [.hebrewStrongsAvailable()](#NodeSwordInterface+hebrewStrongsAvailable) ⇒ <code>Boolean</code>
67
67
  * [.greekStrongsAvailable()](#NodeSwordInterface+greekStrongsAvailable) ⇒ <code>Boolean</code>
@@ -73,6 +73,7 @@ This is the main class of node-sword-interface and it provides a set of static f
73
73
  * [.getSwordTranslation(originalString, localeCode)](#NodeSwordInterface+getSwordTranslation)
74
74
  * [.getBookAbbreviation(moduleName, bookCode, localeCode)](#NodeSwordInterface+getBookAbbreviation)
75
75
  * [.getSwordVersion()](#NodeSwordInterface+getSwordVersion) ⇒ <code>String</code>
76
+ * [.getSwordPath()](#NodeSwordInterface+getSwordPath) ⇒ <code>String</code>
76
77
 
77
78
  <a name="NodeSwordInterface+repositoryConfigExisting"></a>
78
79
 
@@ -447,7 +448,7 @@ Checks whether a module has a certain book
447
448
 
448
449
  <a name="NodeSwordInterface+getModuleSearchResults"></a>
449
450
 
450
- ### nodeSwordInterface.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, isCaseSensitive, useExtendedVerseBoundaries) ⇒ <code>Promise</code>
451
+ ### nodeSwordInterface.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, searchScope, isCaseSensitive, useExtendedVerseBoundaries) ⇒ <code>Promise</code>
451
452
  Returns the results of a module search.
452
453
 
453
454
  **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
@@ -458,6 +459,7 @@ Returns the results of a module search.
458
459
  | searchTerm | <code>String</code> | | The term to search for. |
459
460
  | progressCB | <code>function</code> | | Optional callback function that is called on progress events. |
460
461
  | searchType | <code>String</code> | <code>phrase</code> | Options: phrase, multiWord, strongsNumber |
462
+ | searchScope | <code>String</code> | <code>BIBLE</code> | Options: BIBLE, OT, NT |
461
463
  | isCaseSensitive | <code>Boolean</code> | <code>false</code> | Whether the search is case sensitive |
462
464
  | useExtendedVerseBoundaries | <code>Boolean</code> | <code>false</code> | Whether the search should use extended verse boundaries (Two verses instead of one) in case of a multi word search. |
463
465
 
@@ -563,6 +565,13 @@ Returns the version of the SWORD library
563
565
 
564
566
  **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
565
567
  **Returns**: <code>String</code> - SWORD library version.
568
+ <a name="NodeSwordInterface+getSwordPath"></a>
569
+
570
+ ### nodeSwordInterface.getSwordPath() ⇒ <code>String</code>
571
+ Returns the platform-specific path where SWORD accesses and stores its modules.
572
+
573
+ **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
574
+ **Returns**: <code>String</code> - Platform-specific SWORD path.
566
575
  <a name="VerseObject"></a>
567
576
 
568
577
  ## VerseObject : <code>Object</code>
package/index.js CHANGED
@@ -459,20 +459,33 @@ class NodeSwordInterface {
459
459
  * @param {String} searchTerm - The term to search for.
460
460
  * @param {Function} progressCB - Optional callback function that is called on progress events.
461
461
  * @param {String} searchType - Options: phrase, multiWord, strongsNumber
462
+ * @param {String} searchScope - Options: BIBLE, OT, NT
462
463
  * @param {Boolean} isCaseSensitive - Whether the search is case sensitive
463
464
  * @param {Boolean} useExtendedVerseBoundaries - Whether the search should use extended verse boundaries (Two verses instead of one) in case of a multi word search.
464
465
  * @return {Promise}
465
466
  */
466
- getModuleSearchResults(moduleCode, searchTerm, progressCB=undefined, searchType="phrase", isCaseSensitive=false, useExtendedVerseBoundaries=false) {
467
+ getModuleSearchResults(moduleCode,
468
+ searchTerm,
469
+ progressCB=undefined,
470
+ searchType="phrase",
471
+ searchScope="BIBLE",
472
+ isCaseSensitive=false,
473
+ useExtendedVerseBoundaries=false) {
474
+
467
475
  if (progressCB === undefined) {
468
476
  progressCB = function(progress) {};
469
477
  }
470
478
 
471
479
  return new Promise((resolve, reject) => {
472
480
  try {
473
- this.nativeInterface.getModuleSearchResults(moduleCode, searchTerm, searchType, isCaseSensitive, useExtendedVerseBoundaries, progressCB, function(searchResults) {
474
- resolve(searchResults);
475
- });
481
+ this.nativeInterface.getModuleSearchResults(moduleCode,
482
+ searchTerm,
483
+ searchType,
484
+ searchScope,
485
+ isCaseSensitive,
486
+ useExtendedVerseBoundaries,
487
+ progressCB,
488
+ function(searchResults) { resolve(searchResults); });
476
489
  } catch (error) {
477
490
  reject(error);
478
491
  }
@@ -584,6 +597,14 @@ class NodeSwordInterface {
584
597
  getSwordVersion() {
585
598
  return this.nativeInterface.getSwordVersion();
586
599
  }
600
+
601
+ /**
602
+ * Returns the platform-specific path where SWORD accesses and stores its modules.
603
+ * @returns {String} Platform-specific SWORD path.
604
+ */
605
+ getSwordPath() {
606
+ return this.nativeInterface.getSwordPath();
607
+ }
587
608
  }
588
609
 
589
610
  module.exports = NodeSwordInterface;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "0.238.0",
3
+ "version": "0.242.0",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -35,6 +35,7 @@ void ModuleSearchWorker::Execute(const ExecutionProgress& progress)
35
35
  this->_stdSearchResults = this->_moduleSearch.getModuleSearchResults(this->_moduleName,
36
36
  this->_searchTerm,
37
37
  this->_searchType,
38
+ this->_searchScope,
38
39
  this->_isCaseSensitive,
39
40
  this->_useExtendedVerseBoundaries);
40
41
 
@@ -36,6 +36,7 @@ public:
36
36
  std::string moduleName,
37
37
  std::string searchTerm,
38
38
  SearchType searchType,
39
+ SearchScope searchScope,
39
40
  bool isCaseSensitive=false,
40
41
  bool useExtendedVerseBoundaries=false)
41
42
 
@@ -45,6 +46,7 @@ public:
45
46
  _moduleName(moduleName),
46
47
  _searchTerm(searchTerm),
47
48
  _searchType(searchType),
49
+ _searchScope(searchScope),
48
50
  _isCaseSensitive(isCaseSensitive),
49
51
  _useExtendedVerseBoundaries(useExtendedVerseBoundaries),
50
52
  _searchTerminated(false) {
@@ -66,6 +68,7 @@ private:
66
68
  std::string _moduleName;
67
69
  std::string _searchTerm;
68
70
  SearchType _searchType;
71
+ SearchScope _searchScope;
69
72
  bool _isCaseSensitive;
70
73
  bool _useExtendedVerseBoundaries;
71
74
  bool _searchTerminated;
@@ -111,7 +111,8 @@ Napi::Object NodeSwordInterface::Init(Napi::Env env, Napi::Object exports)
111
111
  InstanceMethod("isModuleReadable", &NodeSwordInterface::isModuleReadable),
112
112
  InstanceMethod("getSwordTranslation", &NodeSwordInterface::getSwordTranslation),
113
113
  InstanceMethod("getBookAbbreviation", &NodeSwordInterface::getBookAbbreviation),
114
- InstanceMethod("getSwordVersion", &NodeSwordInterface::getSwordVersion)
114
+ InstanceMethod("getSwordVersion", &NodeSwordInterface::getSwordVersion),
115
+ InstanceMethod("getSwordPath", &NodeSwordInterface::getSwordPath)
115
116
  });
116
117
 
117
118
  constructor = Napi::Persistent(func);
@@ -695,6 +696,7 @@ Napi::Value NodeSwordInterface::getModuleSearchResults(const Napi::CallbackInfo&
695
696
  INIT_SCOPE_AND_VALIDATE(ParamType::string, // moduleName
696
697
  ParamType::string, // searchTerm
697
698
  ParamType::string, // searchType
699
+ ParamType::string, // searchScope
698
700
  ParamType::boolean, // isCaseSensitive
699
701
  ParamType::boolean, // useExtendedVerseBoundaries
700
702
  ParamType::function, // progressCallback
@@ -703,10 +705,11 @@ Napi::Value NodeSwordInterface::getModuleSearchResults(const Napi::CallbackInfo&
703
705
  Napi::String moduleName = info[0].As<Napi::String>();
704
706
  Napi::String searchTerm = info[1].As<Napi::String>();
705
707
  string searchTypeString = string(info[2].As<Napi::String>());
706
- Napi::Boolean isCaseSensitive = info[3].As<Napi::Boolean>();
707
- Napi::Boolean useExtendedVerseBoundaries = info[4].As<Napi::Boolean>();
708
- Napi::Function jsProgressCallback = info[5].As<Napi::Function>();
709
- Napi::Function callback = info[6].As<Napi::Function>();
708
+ string searchScopeString = string(info[3].As<Napi::String>());
709
+ Napi::Boolean isCaseSensitive = info[4].As<Napi::Boolean>();
710
+ Napi::Boolean useExtendedVerseBoundaries = info[5].As<Napi::Boolean>();
711
+ Napi::Function jsProgressCallback = info[6].As<Napi::Function>();
712
+ Napi::Function callback = info[7].As<Napi::Function>();
710
713
  SearchType searchType = SearchType::multiWord;
711
714
 
712
715
  if (searchTypeString == "phrase") {
@@ -725,6 +728,18 @@ Napi::Value NodeSwordInterface::getModuleSearchResults(const Napi::CallbackInfo&
725
728
  }
726
729
  }
727
730
 
731
+ SearchScope searchScope = SearchScope::BIBLE;
732
+
733
+ if (searchScopeString == "BIBLE") {
734
+ searchScope = SearchScope::BIBLE;
735
+ } else if (searchScopeString == "OT") {
736
+ searchScope = SearchScope::OT;
737
+ } else if (searchScopeString == "NT") {
738
+ searchScope = SearchScope::NT;
739
+ } else {
740
+ THROW_JS_EXCEPTION("Unknown search scope!");
741
+ }
742
+
728
743
  this->_currentModuleSearchWorker = new ModuleSearchWorker(*(this->_moduleHelper),
729
744
  *(this->_moduleSearch),
730
745
  *(this->_moduleStore),
@@ -735,6 +750,7 @@ Napi::Value NodeSwordInterface::getModuleSearchResults(const Napi::CallbackInfo&
735
750
  moduleName,
736
751
  searchTerm,
737
752
  searchType,
753
+ searchScope,
738
754
  isCaseSensitive,
739
755
  useExtendedVerseBoundaries);
740
756
  this->_currentModuleSearchWorker->Queue();
@@ -928,3 +944,15 @@ Napi::Value NodeSwordInterface::getSwordVersion(const Napi::CallbackInfo& info)
928
944
  unlockApi();
929
945
  return swVersion;
930
946
  }
947
+
948
+ Napi::Value NodeSwordInterface::getSwordPath(const Napi::CallbackInfo& info)
949
+ {
950
+ lockApi();
951
+ Napi::Env env = info.Env();
952
+ Napi::HandleScope scope(env);
953
+
954
+ FileSystemHelper fsHelper;
955
+ Napi::String swordPath = Napi::String::New(env, fsHelper.getUserSwordDir());
956
+ unlockApi();
957
+ return swordPath;
958
+ }
@@ -96,6 +96,7 @@ private:
96
96
  Napi::Value getSwordTranslation(const Napi::CallbackInfo& info);
97
97
  Napi::Value getBookAbbreviation(const Napi::CallbackInfo& info);
98
98
  Napi::Value getSwordVersion(const Napi::CallbackInfo& info);
99
+ Napi::Value getSwordPath(const Napi::CallbackInfo& info);
99
100
 
100
101
  int validateParams(const Napi::CallbackInfo& info, std::vector<ParamType> paramSpec);
101
102
  ModuleType getModuleTypeFromString(std::string moduleTypeString);
@@ -197,7 +197,7 @@ int main(int argc, char** argv)
197
197
 
198
198
  //get_strongs_entry(textProcessor);
199
199
 
200
- get_module_text(textProcessor);
200
+ //get_module_text(textProcessor);
201
201
 
202
202
  //get_book_intro(textProcessor);
203
203
 
@@ -206,11 +206,11 @@ int main(int argc, char** argv)
206
206
  //string translation = sword_facade.getSwordTranslation(string("/usr/share/sword/locales.d"), string("de"), string("locales"));
207
207
  //cout << translation << endl;
208
208
 
209
- /*vector<Verse> searchResults = moduleSearch.getModuleSearchResults("NASB", "Jesus faith", SearchType::multiWord, false, true);
209
+ vector<Verse> searchResults = moduleSearch.getModuleSearchResults("NASB", "faith", SearchType::multiWord, SearchScope::NT, true);
210
210
  cout << "Got " << searchResults.size() << " results!" << endl;
211
211
  for (unsigned int i=0; i < searchResults.size(); i++) {
212
212
  cout << searchResults[i].reference << endl;
213
- }*/
213
+ }
214
214
 
215
215
  return 0;
216
216
  }
@@ -82,6 +82,13 @@ void FileSystemHelper::createBasicDirectories()
82
82
  #endif
83
83
  #endif
84
84
 
85
+ if (!this->fileExists(this->getUserDir())) {
86
+ ret = this->makeDirectory(this->getUserDir());
87
+ if (ret != 0) {
88
+ cerr << "Failed to create user dir at " << this->getUserDir() << endl;
89
+ }
90
+ }
91
+
85
92
  if (!this->fileExists(this->getUserSwordDir())) {
86
93
  ret = this->makeDirectory(this->getUserSwordDir());
87
94
  if (ret != 0) {
@@ -50,17 +50,52 @@
50
50
  using namespace std;
51
51
  using namespace sword;
52
52
 
53
+ ListKey ModuleSearch::getScopeKey(SearchScope scope)
54
+ {
55
+ ListKey key;
56
+
57
+ switch (scope) {
58
+ case SearchScope::OT:
59
+ {
60
+ const char* otBooks = "Genesis;Exodus;Leviticus;Numbers;Joshua;Judges;"
61
+ "Ruth;I Samuel;II Samuel;I Kings;II Kings;I Chronicles;II Chronicles;"
62
+ "Ezra;Nehemiah;Esther;Job;Psalms;Proverbs;Ecclesiastes;Song of Solomon;"
63
+ "Isaiah;Jeremiah;Lamentations;Ezekiel;Daniel;Hosea;Joel;Amos;Obadiah;"
64
+ "Jonah;Micah;Nahum;Habakkuk;Zephaniah;Haggai;Zechariah;Malachi;";
65
+
66
+ key = VerseKey().parseVerseList(otBooks, "", true);
67
+ break;
68
+ }
69
+
70
+ case SearchScope::NT:
71
+ {
72
+ const char* ntBooks = "Matthew;Mark;Luke;John;Acts;Romans;I Corinthians;II Corinthians;"
73
+ "Galatians;Ephesians;Philippians;Colossians;I Thessalonians;II Thessalonians;"
74
+ "I Timothy;II Timothy;Titus;Philemon;Hebrews;James;I Peter;II Peter;"
75
+ "I John;II John;III John;Jude;Revelation of John;";
76
+
77
+ key = VerseKey().parseVerseList(ntBooks, "", true);
78
+ break;
79
+ }
80
+
81
+ default:
82
+ break;
83
+ }
84
+
85
+ return key;
86
+ }
53
87
 
54
88
  vector<Verse> ModuleSearch::getModuleSearchResults(string moduleName,
55
89
  string searchTerm,
56
90
  SearchType searchType,
91
+ SearchScope searchScope,
57
92
  bool isCaseSensitive,
58
93
  bool useExtendedVerseBoundaries)
59
94
  {
60
95
  this->_currentModuleName = moduleName;
61
96
  SWModule* module = this->_moduleStore.getLocalModule(moduleName);
62
97
  ListKey listKey;
63
- ListKey* scope = 0;
98
+ SWKey* scope = 0;
64
99
  int flags = 0;
65
100
  // This holds the text that we will return
66
101
  vector<Verse> searchResults;
@@ -81,6 +116,13 @@ vector<Verse> ModuleSearch::getModuleSearchResults(string moduleName,
81
116
  } else if (searchTerm == "") {
82
117
  cerr << "ModuleSearch::getModuleSearchResults: cannot work with empty search term!" << endl;
83
118
  } else {
119
+ ListKey scopeKey;
120
+
121
+ if (searchScope != SearchScope::BIBLE) {
122
+ scopeKey = this->getScopeKey(searchScope);
123
+ scope = &scopeKey;
124
+ }
125
+
84
126
  bool hasStrongs = this->_moduleHelper.moduleHasGlobalOption(module, "Strongs");
85
127
 
86
128
  if (searchType == SearchType::strongsNumber) {
@@ -29,6 +29,7 @@ void internalModuleSearchProgressCB(char percent, void* userData);
29
29
 
30
30
  namespace sword {
31
31
  class SWModule;
32
+ class ListKey;
32
33
  };
33
34
 
34
35
  enum class SearchType {
@@ -37,6 +38,12 @@ enum class SearchType {
37
38
  strongsNumber = -3
38
39
  };
39
40
 
41
+ enum class SearchScope {
42
+ BIBLE = 0,
43
+ OT = 1,
44
+ NT = 2
45
+ };
46
+
40
47
  class ModuleStore;
41
48
  class ModuleHelper;
42
49
  class TextProcessor;
@@ -51,12 +58,15 @@ public:
51
58
  std::vector<Verse> getModuleSearchResults(std::string moduleName,
52
59
  std::string searchTerm,
53
60
  SearchType searchType=SearchType::multiWord,
61
+ SearchScope searchScope=SearchScope::BIBLE,
54
62
  bool isCaseSensitive=false,
55
63
  bool useExtendedVerseBoundaries=false);
56
64
 
57
65
  void terminate();
58
66
 
59
67
  private:
68
+ sword::ListKey getScopeKey(SearchScope scope);
69
+
60
70
  ModuleStore& _moduleStore;
61
71
  ModuleHelper& _moduleHelper;
62
72
  TextProcessor& _textProcessor;
@@ -67,6 +67,9 @@ void RepositoryInterface::resetMgr()
67
67
 
68
68
  this->_installMgr = new InstallMgr(this->_fileSystemHelper.getInstallMgrDir().c_str(), &this->_statusReporter);
69
69
  this->_installMgr->setUserDisclaimerConfirmed(true);
70
+
71
+ long timeoutMillis = 20000;
72
+ this->_installMgr->setTimeoutMillis(timeoutMillis);
70
73
  }
71
74
 
72
75
  int RepositoryInterface::refreshRepositoryConfig()