Skip to content

Commit

Permalink
Add new api method getDictModuleKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-klein committed Oct 27, 2024
1 parent 07b69a6 commit b36400f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
14 changes: 13 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ This is the main class of node-sword-interface and it provides a set of static f
* [.getBibleText(moduleCode)](#NodeSwordInterface+getBibleText)[<code>Array.&lt;VerseObject&gt;</code>](#VerseObject)
* [.getBookIntroduction(moduleCode, bookCode)](#NodeSwordInterface+getBookIntroduction) ⇒ <code>String</code>
* [.moduleHasBook(moduleCode, bookCode)](#NodeSwordInterface+moduleHasBook) ⇒ <code>Boolean</code>
* [.getDictModuleKeys(moduleCode)](#NodeSwordInterface+getDictModuleKeys) ⇒ <code>Array.&lt;String&gt;</code>
* [.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, searchScope, isCaseSensitive, useExtendedVerseBoundaries)](#NodeSwordInterface+getModuleSearchResults) ⇒ <code>Promise</code>
* [.terminateModuleSearch()](#NodeSwordInterface+terminateModuleSearch)
* [.hebrewStrongsAvailable()](#NodeSwordInterface+hebrewStrongsAvailable) ⇒ <code>Boolean</code>
Expand Down Expand Up @@ -494,7 +495,7 @@ Returns the introduction of the given book.
<a name="NodeSwordInterface+moduleHasBook"></a>

### nodeSwordInterface.moduleHasBook(moduleCode, bookCode) ⇒ <code>Boolean</code>
Checks whether a module has a certain book
Checks whether a module has a certain book.

**Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)

Expand All @@ -503,6 +504,17 @@ Checks whether a module has a certain book
| moduleCode | <code>String</code> |
| bookCode | <code>String</code> |

<a name="NodeSwordInterface+getDictModuleKeys"></a>

### nodeSwordInterface.getDictModuleKeys(moduleCode) ⇒ <code>Array.&lt;String&gt;</code>
Returns the keys of a dictionary module.

**Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)

| Param | Type |
| --- | --- |
| moduleCode | <code>String</code> |

<a name="NodeSwordInterface+getModuleSearchResults"></a>

### nodeSwordInterface.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, searchScope, isCaseSensitive, useExtendedVerseBoundaries) ⇒ <code>Promise</code>
Expand Down
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,16 +547,26 @@ class NodeSwordInterface {
}

/**
* Checks whether a module has a certain book
* Checks whether a module has a certain book.
*
* @param {String} moduleCode
* @param {String} bookCode
* @returns {Boolean}
* @return {Boolean}
*/
moduleHasBook(moduleCode, bookCode) {
return this.nativeInterface.moduleHasBook(moduleCode, bookCode);
}

/**
* Returns the keys of a dictionary module.
*
* @param {String} moduleCode
* @return {String[]}
*/
getDictModuleKeys(moduleCode) {
return this.nativeInterface.getDictModuleKeys(moduleCode);
}

/**
* Returns the results of a module search.
*
Expand Down
18 changes: 18 additions & 0 deletions src/napi_module/node_sword_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "module_store.hpp"
#include "module_installer.hpp"
#include "module_helper.hpp"
#include "dict_helper.hpp"
#include "text_processor.hpp"
#include "module_search.hpp"
#include "mutex.hpp"
Expand Down Expand Up @@ -101,6 +102,7 @@ Napi::Object NodeSwordInterface::Init(Napi::Env env, Napi::Object exports)
InstanceMethod("getChapterVerseCount", &NodeSwordInterface::getChapterVerseCount),
InstanceMethod("getBookIntroduction", &NodeSwordInterface::getBookIntroduction),
InstanceMethod("moduleHasBook", &NodeSwordInterface::moduleHasBook),
InstanceMethod("getDictModuleKeys", &NodeSwordInterface::getDictModuleKeys),
InstanceMethod("getModuleSearchResults", &NodeSwordInterface::getModuleSearchResults),
InstanceMethod("terminateModuleSearch", &NodeSwordInterface::terminateModuleSearch),
InstanceMethod("getStrongsEntry", &NodeSwordInterface::getStrongsEntry),
Expand Down Expand Up @@ -174,6 +176,7 @@ NodeSwordInterface::NodeSwordInterface(const Napi::CallbackInfo& info) : Napi::O
if (!homeDirError && !localeDirError) { // We only proceed if there has not been any issue with the homeDir or localeDir
this->_moduleStore = new ModuleStore(this->customHomeDir);
this->_moduleHelper = new ModuleHelper(*(this->_moduleStore));
this->_dictHelper = new DictHelper(*(this->_moduleStore));
this->_repoInterface = new RepositoryInterface(this->_swordStatusReporter, *(this->_moduleHelper), *(this->_moduleStore), this->customHomeDir);
this->_moduleInstaller = new ModuleInstaller(*(this->_repoInterface), *(this->_moduleStore), this->customHomeDir);
this->_napiSwordHelper = new NapiSwordHelper(*(this->_moduleHelper), *(this->_moduleStore));
Expand Down Expand Up @@ -710,6 +713,21 @@ Napi::Value NodeSwordInterface::moduleHasBook(const Napi::CallbackInfo& info)
return hasBook;
}

Napi::Value NodeSwordInterface::getDictModuleKeys(const Napi::CallbackInfo& info)
{
lockApi();
Napi::Env env = info.Env();
INIT_SCOPE_AND_VALIDATE(ParamType::string);
Napi::String moduleName = info[0].As<Napi::String>();
ASSERT_SW_MODULE_EXISTS(moduleName);

vector<string> dictModuleKeys = this->_dictHelper->getKeyList(moduleName);
Napi::Array dictModuleKeyArray = this->_napiSwordHelper->getNapiArrayFromStringVector(env, dictModuleKeys);

unlockApi();
return dictModuleKeyArray;
}

Napi::Value NodeSwordInterface::getModuleSearchResults(const Napi::CallbackInfo& info)
{
lockApi();
Expand Down
3 changes: 3 additions & 0 deletions src/napi_module/node_sword_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ModuleInstaller;
class TextProcessor;
class NapiSwordHelper;
class ModuleHelper;
class DictHelper;
class ModuleSearch;
class ModuleSearchWorker;
enum class ModuleType;
Expand Down Expand Up @@ -82,6 +83,7 @@ class NodeSwordInterface : public Napi::ObjectWrap<NodeSwordInterface> {
Napi::Value getChapterVerseCount(const Napi::CallbackInfo& info);
Napi::Value getBookIntroduction(const Napi::CallbackInfo& info);
Napi::Value moduleHasBook(const Napi::CallbackInfo& info);
Napi::Value getDictModuleKeys(const Napi::CallbackInfo& info);

Napi::Value getModuleSearchResults(const Napi::CallbackInfo& info);
Napi::Value terminateModuleSearch(const Napi::CallbackInfo& info);
Expand All @@ -104,6 +106,7 @@ class NodeSwordInterface : public Napi::ObjectWrap<NodeSwordInterface> {
bool dirExists(const Napi::CallbackInfo& info, std::string dirName);

ModuleHelper* _moduleHelper;
DictHelper* _dictHelper;
NapiSwordHelper* _napiSwordHelper;
RepositoryInterface* _repoInterface;
ModuleStore* _moduleStore;
Expand Down

0 comments on commit b36400f

Please sign in to comment.