UNPKG

node-darts

Version:

Node.js Native Addon for Darts (Double-ARray Trie System)

166 lines (165 loc) 6.84 kB
"use strict"; /** * node-darts: Node.js Native Addon for Darts (Double-ARray Trie System) * * This package binds the C++ version of Darts, making .darts dictionary files * available in Node.js/TypeScript environments. * * @packageDocumentation */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.sortAndUniqueStrings = exports.uniqueArray = exports.sortStrings = exports.ensureDirectoryExists = exports.validateFilePath = exports.fileExists = exports.BuildError = exports.InvalidDictionaryError = exports.FileNotFoundError = exports.DartsError = exports.TextDarts = exports.Builder = exports.Dictionary = void 0; exports.createDictionary = createDictionary; exports.createBuilder = createBuilder; exports.loadDictionary = loadDictionary; exports.buildDictionary = buildDictionary; exports.buildAndSaveDictionary = buildAndSaveDictionary; exports.buildAndSaveDictionarySync = buildAndSaveDictionarySync; // Import classes const dictionary_1 = __importDefault(require("./core/dictionary")); const builder_1 = __importDefault(require("./core/builder")); const text_darts_1 = __importDefault(require("./text-darts")); /* // Import error classes import { DartsError, FileNotFoundError, InvalidDictionaryError, BuildError } from './core/errors'; // Import utility functions import { fileExists, validateFilePath, ensureDirectoryExists, sortStrings, uniqueArray, sortAndUniqueStrings, } from './core/utils'; */ // Export classes var dictionary_2 = require("./core/dictionary"); Object.defineProperty(exports, "Dictionary", { enumerable: true, get: function () { return __importDefault(dictionary_2).default; } }); var builder_2 = require("./core/builder"); Object.defineProperty(exports, "Builder", { enumerable: true, get: function () { return __importDefault(builder_2).default; } }); var text_darts_2 = require("./text-darts"); Object.defineProperty(exports, "TextDarts", { enumerable: true, get: function () { return __importDefault(text_darts_2).default; } }); // Export error classes var errors_1 = require("./core/errors"); Object.defineProperty(exports, "DartsError", { enumerable: true, get: function () { return errors_1.DartsError; } }); Object.defineProperty(exports, "FileNotFoundError", { enumerable: true, get: function () { return errors_1.FileNotFoundError; } }); Object.defineProperty(exports, "InvalidDictionaryError", { enumerable: true, get: function () { return errors_1.InvalidDictionaryError; } }); Object.defineProperty(exports, "BuildError", { enumerable: true, get: function () { return errors_1.BuildError; } }); // Export utility functions var utils_1 = require("./core/utils"); Object.defineProperty(exports, "fileExists", { enumerable: true, get: function () { return utils_1.fileExists; } }); Object.defineProperty(exports, "validateFilePath", { enumerable: true, get: function () { return utils_1.validateFilePath; } }); Object.defineProperty(exports, "ensureDirectoryExists", { enumerable: true, get: function () { return utils_1.ensureDirectoryExists; } }); Object.defineProperty(exports, "sortStrings", { enumerable: true, get: function () { return utils_1.sortStrings; } }); Object.defineProperty(exports, "uniqueArray", { enumerable: true, get: function () { return utils_1.uniqueArray; } }); Object.defineProperty(exports, "sortAndUniqueStrings", { enumerable: true, get: function () { return utils_1.sortAndUniqueStrings; } }); /** * Creates a dictionary * @returns a new Dictionary object * @example * ```typescript * import { createDictionary } from 'node-darts'; * * const dict = createDictionary(); * dict.loadSync('/path/to/dictionary.darts'); * const result = dict.exactMatchSearch('hello'); * ``` */ function createDictionary() { return new dictionary_1.default(); } /** * Creates a builder * @returns a new Builder object * @example * ```typescript * import { createBuilder } from 'node-darts'; * * const builder = createBuilder(); * const keys = ['apple', 'banana', 'orange']; * const dict = builder.build(keys); * ``` */ function createBuilder() { return new builder_1.default(); } /** * Loads a dictionary file * @param filePath path to the dictionary file * @returns the loaded Dictionary object * @throws {FileNotFoundError} if the file is not found * @throws {InvalidDictionaryError} if the dictionary file is invalid * @example * ```typescript * import { loadDictionary } from 'node-darts'; * * const dict = loadDictionary('/path/to/dictionary.darts'); * const result = dict.exactMatchSearch('hello'); * ``` */ function loadDictionary(filePath) { const dict = new dictionary_1.default(); dict.loadSync(filePath); return dict; } /** * Builds a dictionary from keys and values * @param keys array of keys * @param values array of values (indices are used if omitted) * @param options build options * @returns the constructed Dictionary object * @example * ```typescript * import { buildDictionary } from 'node-darts'; * * const keys = ['apple', 'banana', 'orange']; * const values = [1, 2, 3]; * const dict = buildDictionary(keys, values); * ``` */ function buildDictionary(keys, values, options) { const builder = new builder_1.default(); return builder.build(keys, values, options); } /** * Builds a dictionary from keys and values and saves it to a file * @param keys array of keys * @param filePath destination file path * @param values array of values (indices are used if omitted) * @param options build options * @returns true if successful, false otherwise * @example * ```typescript * import { buildAndSaveDictionary } from 'node-darts'; * * const keys = ['apple', 'banana', 'orange']; * const values = [1, 2, 3]; * const result = await buildAndSaveDictionary(keys, '/path/to/output.darts', values); * ``` */ async function buildAndSaveDictionary(keys, filePath, values, options) { return text_darts_1.default.buildAndSave(keys, filePath, values, options); } /** * Builds a dictionary from keys and values and saves it to a file synchronously * @param keys array of keys * @param filePath destination file path * @param values array of values (indices are used if omitted) * @param options build options * @returns true if successful, false otherwise * @example * ```typescript * import { buildAndSaveDictionarySync } from 'node-darts'; * * const keys = ['apple', 'banana', 'orange']; * const values = [1, 2, 3]; * const result = buildAndSaveDictionarySync(keys, '/path/to/output.darts', values); * ``` */ function buildAndSaveDictionarySync(keys, filePath, values, options) { return text_darts_1.default.buildAndSaveSync(keys, filePath, values, options); } //# sourceMappingURL=index.js.map