@gmod/trix 0.2.0 → 2.0.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/CHANGELOG.md +19 -0
- package/README.md +35 -36
- package/dist/index.d.ts +13 -63
- package/dist/index.js +280 -8
- package/dist/index.js.map +1 -0
- package/esm/index.d.ts +12 -0
- package/esm/index.js +120 -0
- package/esm/index.js.map +1 -0
- package/package.json +25 -40
- package/dist/trix.cjs.development.js +0 -1471
- package/dist/trix.cjs.development.js.map +0 -1
- package/dist/trix.cjs.production.min.js +0 -2
- package/dist/trix.cjs.production.min.js.map +0 -1
- package/dist/trix.esm.js +0 -1467
- package/dist/trix.esm.js.map +0 -1
- package/src/index.ts +0 -341
package/dist/trix.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trix.esm.js","sources":["../node_modules/regenerator-runtime/runtime.js","../src/index.ts"],"sourcesContent":["/**\n * Copyright (c) 2014-present, Facebook, Inc.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvar runtime = (function (exports) {\n \"use strict\";\n\n var Op = Object.prototype;\n var hasOwn = Op.hasOwnProperty;\n var undefined; // More compressible than void 0.\n var $Symbol = typeof Symbol === \"function\" ? Symbol : {};\n var iteratorSymbol = $Symbol.iterator || \"@@iterator\";\n var asyncIteratorSymbol = $Symbol.asyncIterator || \"@@asyncIterator\";\n var toStringTagSymbol = $Symbol.toStringTag || \"@@toStringTag\";\n\n function define(obj, key, value) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n return obj[key];\n }\n try {\n // IE 8 has a broken Object.defineProperty that only works on DOM objects.\n define({}, \"\");\n } catch (err) {\n define = function(obj, key, value) {\n return obj[key] = value;\n };\n }\n\n function wrap(innerFn, outerFn, self, tryLocsList) {\n // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.\n var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;\n var generator = Object.create(protoGenerator.prototype);\n var context = new Context(tryLocsList || []);\n\n // The ._invoke method unifies the implementations of the .next,\n // .throw, and .return methods.\n generator._invoke = makeInvokeMethod(innerFn, self, context);\n\n return generator;\n }\n exports.wrap = wrap;\n\n // Try/catch helper to minimize deoptimizations. Returns a completion\n // record like context.tryEntries[i].completion. This interface could\n // have been (and was previously) designed to take a closure to be\n // invoked without arguments, but in all the cases we care about we\n // already have an existing method we want to call, so there's no need\n // to create a new function object. We can even get away with assuming\n // the method takes exactly one argument, since that happens to be true\n // in every case, so we don't have to touch the arguments object. The\n // only additional allocation required is the completion record, which\n // has a stable shape and so hopefully should be cheap to allocate.\n function tryCatch(fn, obj, arg) {\n try {\n return { type: \"normal\", arg: fn.call(obj, arg) };\n } catch (err) {\n return { type: \"throw\", arg: err };\n }\n }\n\n var GenStateSuspendedStart = \"suspendedStart\";\n var GenStateSuspendedYield = \"suspendedYield\";\n var GenStateExecuting = \"executing\";\n var GenStateCompleted = \"completed\";\n\n // Returning this object from the innerFn has the same effect as\n // breaking out of the dispatch switch statement.\n var ContinueSentinel = {};\n\n // Dummy constructor functions that we use as the .constructor and\n // .constructor.prototype properties for functions that return Generator\n // objects. For full spec compliance, you may wish to configure your\n // minifier not to mangle the names of these two functions.\n function Generator() {}\n function GeneratorFunction() {}\n function GeneratorFunctionPrototype() {}\n\n // This is a polyfill for %IteratorPrototype% for environments that\n // don't natively support it.\n var IteratorPrototype = {};\n IteratorPrototype[iteratorSymbol] = function () {\n return this;\n };\n\n var getProto = Object.getPrototypeOf;\n var NativeIteratorPrototype = getProto && getProto(getProto(values([])));\n if (NativeIteratorPrototype &&\n NativeIteratorPrototype !== Op &&\n hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {\n // This environment has a native %IteratorPrototype%; use it instead\n // of the polyfill.\n IteratorPrototype = NativeIteratorPrototype;\n }\n\n var Gp = GeneratorFunctionPrototype.prototype =\n Generator.prototype = Object.create(IteratorPrototype);\n GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;\n GeneratorFunctionPrototype.constructor = GeneratorFunction;\n GeneratorFunction.displayName = define(\n GeneratorFunctionPrototype,\n toStringTagSymbol,\n \"GeneratorFunction\"\n );\n\n // Helper for defining the .next, .throw, and .return methods of the\n // Iterator interface in terms of a single ._invoke method.\n function defineIteratorMethods(prototype) {\n [\"next\", \"throw\", \"return\"].forEach(function(method) {\n define(prototype, method, function(arg) {\n return this._invoke(method, arg);\n });\n });\n }\n\n exports.isGeneratorFunction = function(genFun) {\n var ctor = typeof genFun === \"function\" && genFun.constructor;\n return ctor\n ? ctor === GeneratorFunction ||\n // For the native GeneratorFunction constructor, the best we can\n // do is to check its .name property.\n (ctor.displayName || ctor.name) === \"GeneratorFunction\"\n : false;\n };\n\n exports.mark = function(genFun) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);\n } else {\n genFun.__proto__ = GeneratorFunctionPrototype;\n define(genFun, toStringTagSymbol, \"GeneratorFunction\");\n }\n genFun.prototype = Object.create(Gp);\n return genFun;\n };\n\n // Within the body of any async function, `await x` is transformed to\n // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test\n // `hasOwn.call(value, \"__await\")` to determine if the yielded value is\n // meant to be awaited.\n exports.awrap = function(arg) {\n return { __await: arg };\n };\n\n function AsyncIterator(generator, PromiseImpl) {\n function invoke(method, arg, resolve, reject) {\n var record = tryCatch(generator[method], generator, arg);\n if (record.type === \"throw\") {\n reject(record.arg);\n } else {\n var result = record.arg;\n var value = result.value;\n if (value &&\n typeof value === \"object\" &&\n hasOwn.call(value, \"__await\")) {\n return PromiseImpl.resolve(value.__await).then(function(value) {\n invoke(\"next\", value, resolve, reject);\n }, function(err) {\n invoke(\"throw\", err, resolve, reject);\n });\n }\n\n return PromiseImpl.resolve(value).then(function(unwrapped) {\n // When a yielded Promise is resolved, its final value becomes\n // the .value of the Promise<{value,done}> result for the\n // current iteration.\n result.value = unwrapped;\n resolve(result);\n }, function(error) {\n // If a rejected Promise was yielded, throw the rejection back\n // into the async generator function so it can be handled there.\n return invoke(\"throw\", error, resolve, reject);\n });\n }\n }\n\n var previousPromise;\n\n function enqueue(method, arg) {\n function callInvokeWithMethodAndArg() {\n return new PromiseImpl(function(resolve, reject) {\n invoke(method, arg, resolve, reject);\n });\n }\n\n return previousPromise =\n // If enqueue has been called before, then we want to wait until\n // all previous Promises have been resolved before calling invoke,\n // so that results are always delivered in the correct order. If\n // enqueue has not been called before, then it is important to\n // call invoke immediately, without waiting on a callback to fire,\n // so that the async generator function has the opportunity to do\n // any necessary setup in a predictable way. This predictability\n // is why the Promise constructor synchronously invokes its\n // executor callback, and why async functions synchronously\n // execute code before the first await. Since we implement simple\n // async functions in terms of async generators, it is especially\n // important to get this right, even though it requires care.\n previousPromise ? previousPromise.then(\n callInvokeWithMethodAndArg,\n // Avoid propagating failures to Promises returned by later\n // invocations of the iterator.\n callInvokeWithMethodAndArg\n ) : callInvokeWithMethodAndArg();\n }\n\n // Define the unified helper method that is used to implement .next,\n // .throw, and .return (see defineIteratorMethods).\n this._invoke = enqueue;\n }\n\n defineIteratorMethods(AsyncIterator.prototype);\n AsyncIterator.prototype[asyncIteratorSymbol] = function () {\n return this;\n };\n exports.AsyncIterator = AsyncIterator;\n\n // Note that simple async functions are implemented on top of\n // AsyncIterator objects; they just return a Promise for the value of\n // the final result produced by the iterator.\n exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {\n if (PromiseImpl === void 0) PromiseImpl = Promise;\n\n var iter = new AsyncIterator(\n wrap(innerFn, outerFn, self, tryLocsList),\n PromiseImpl\n );\n\n return exports.isGeneratorFunction(outerFn)\n ? iter // If outerFn is a generator, return the full iterator.\n : iter.next().then(function(result) {\n return result.done ? result.value : iter.next();\n });\n };\n\n function makeInvokeMethod(innerFn, self, context) {\n var state = GenStateSuspendedStart;\n\n return function invoke(method, arg) {\n if (state === GenStateExecuting) {\n throw new Error(\"Generator is already running\");\n }\n\n if (state === GenStateCompleted) {\n if (method === \"throw\") {\n throw arg;\n }\n\n // Be forgiving, per 25.3.3.3.3 of the spec:\n // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume\n return doneResult();\n }\n\n context.method = method;\n context.arg = arg;\n\n while (true) {\n var delegate = context.delegate;\n if (delegate) {\n var delegateResult = maybeInvokeDelegate(delegate, context);\n if (delegateResult) {\n if (delegateResult === ContinueSentinel) continue;\n return delegateResult;\n }\n }\n\n if (context.method === \"next\") {\n // Setting context._sent for legacy support of Babel's\n // function.sent implementation.\n context.sent = context._sent = context.arg;\n\n } else if (context.method === \"throw\") {\n if (state === GenStateSuspendedStart) {\n state = GenStateCompleted;\n throw context.arg;\n }\n\n context.dispatchException(context.arg);\n\n } else if (context.method === \"return\") {\n context.abrupt(\"return\", context.arg);\n }\n\n state = GenStateExecuting;\n\n var record = tryCatch(innerFn, self, context);\n if (record.type === \"normal\") {\n // If an exception is thrown from innerFn, we leave state ===\n // GenStateExecuting and loop back for another invocation.\n state = context.done\n ? GenStateCompleted\n : GenStateSuspendedYield;\n\n if (record.arg === ContinueSentinel) {\n continue;\n }\n\n return {\n value: record.arg,\n done: context.done\n };\n\n } else if (record.type === \"throw\") {\n state = GenStateCompleted;\n // Dispatch the exception by looping back around to the\n // context.dispatchException(context.arg) call above.\n context.method = \"throw\";\n context.arg = record.arg;\n }\n }\n };\n }\n\n // Call delegate.iterator[context.method](context.arg) and handle the\n // result, either by returning a { value, done } result from the\n // delegate iterator, or by modifying context.method and context.arg,\n // setting context.delegate to null, and returning the ContinueSentinel.\n function maybeInvokeDelegate(delegate, context) {\n var method = delegate.iterator[context.method];\n if (method === undefined) {\n // A .throw or .return when the delegate iterator has no .throw\n // method always terminates the yield* loop.\n context.delegate = null;\n\n if (context.method === \"throw\") {\n // Note: [\"return\"] must be used for ES3 parsing compatibility.\n if (delegate.iterator[\"return\"]) {\n // If the delegate iterator has a return method, give it a\n // chance to clean up.\n context.method = \"return\";\n context.arg = undefined;\n maybeInvokeDelegate(delegate, context);\n\n if (context.method === \"throw\") {\n // If maybeInvokeDelegate(context) changed context.method from\n // \"return\" to \"throw\", let that override the TypeError below.\n return ContinueSentinel;\n }\n }\n\n context.method = \"throw\";\n context.arg = new TypeError(\n \"The iterator does not provide a 'throw' method\");\n }\n\n return ContinueSentinel;\n }\n\n var record = tryCatch(method, delegate.iterator, context.arg);\n\n if (record.type === \"throw\") {\n context.method = \"throw\";\n context.arg = record.arg;\n context.delegate = null;\n return ContinueSentinel;\n }\n\n var info = record.arg;\n\n if (! info) {\n context.method = \"throw\";\n context.arg = new TypeError(\"iterator result is not an object\");\n context.delegate = null;\n return ContinueSentinel;\n }\n\n if (info.done) {\n // Assign the result of the finished delegate to the temporary\n // variable specified by delegate.resultName (see delegateYield).\n context[delegate.resultName] = info.value;\n\n // Resume execution at the desired location (see delegateYield).\n context.next = delegate.nextLoc;\n\n // If context.method was \"throw\" but the delegate handled the\n // exception, let the outer generator proceed normally. If\n // context.method was \"next\", forget context.arg since it has been\n // \"consumed\" by the delegate iterator. If context.method was\n // \"return\", allow the original .return call to continue in the\n // outer generator.\n if (context.method !== \"return\") {\n context.method = \"next\";\n context.arg = undefined;\n }\n\n } else {\n // Re-yield the result returned by the delegate method.\n return info;\n }\n\n // The delegate iterator is finished, so forget it and continue with\n // the outer generator.\n context.delegate = null;\n return ContinueSentinel;\n }\n\n // Define Generator.prototype.{next,throw,return} in terms of the\n // unified ._invoke helper method.\n defineIteratorMethods(Gp);\n\n define(Gp, toStringTagSymbol, \"Generator\");\n\n // A Generator should always return itself as the iterator object when the\n // @@iterator function is called on it. Some browsers' implementations of the\n // iterator prototype chain incorrectly implement this, causing the Generator\n // object to not be returned from this call. This ensures that doesn't happen.\n // See https://github.com/facebook/regenerator/issues/274 for more details.\n Gp[iteratorSymbol] = function() {\n return this;\n };\n\n Gp.toString = function() {\n return \"[object Generator]\";\n };\n\n function pushTryEntry(locs) {\n var entry = { tryLoc: locs[0] };\n\n if (1 in locs) {\n entry.catchLoc = locs[1];\n }\n\n if (2 in locs) {\n entry.finallyLoc = locs[2];\n entry.afterLoc = locs[3];\n }\n\n this.tryEntries.push(entry);\n }\n\n function resetTryEntry(entry) {\n var record = entry.completion || {};\n record.type = \"normal\";\n delete record.arg;\n entry.completion = record;\n }\n\n function Context(tryLocsList) {\n // The root entry object (effectively a try statement without a catch\n // or a finally block) gives us a place to store values thrown from\n // locations where there is no enclosing try statement.\n this.tryEntries = [{ tryLoc: \"root\" }];\n tryLocsList.forEach(pushTryEntry, this);\n this.reset(true);\n }\n\n exports.keys = function(object) {\n var keys = [];\n for (var key in object) {\n keys.push(key);\n }\n keys.reverse();\n\n // Rather than returning an object with a next method, we keep\n // things simple and return the next function itself.\n return function next() {\n while (keys.length) {\n var key = keys.pop();\n if (key in object) {\n next.value = key;\n next.done = false;\n return next;\n }\n }\n\n // To avoid creating an additional object, we just hang the .value\n // and .done properties off the next function object itself. This\n // also ensures that the minifier will not anonymize the function.\n next.done = true;\n return next;\n };\n };\n\n function values(iterable) {\n if (iterable) {\n var iteratorMethod = iterable[iteratorSymbol];\n if (iteratorMethod) {\n return iteratorMethod.call(iterable);\n }\n\n if (typeof iterable.next === \"function\") {\n return iterable;\n }\n\n if (!isNaN(iterable.length)) {\n var i = -1, next = function next() {\n while (++i < iterable.length) {\n if (hasOwn.call(iterable, i)) {\n next.value = iterable[i];\n next.done = false;\n return next;\n }\n }\n\n next.value = undefined;\n next.done = true;\n\n return next;\n };\n\n return next.next = next;\n }\n }\n\n // Return an iterator with no values.\n return { next: doneResult };\n }\n exports.values = values;\n\n function doneResult() {\n return { value: undefined, done: true };\n }\n\n Context.prototype = {\n constructor: Context,\n\n reset: function(skipTempReset) {\n this.prev = 0;\n this.next = 0;\n // Resetting context._sent for legacy support of Babel's\n // function.sent implementation.\n this.sent = this._sent = undefined;\n this.done = false;\n this.delegate = null;\n\n this.method = \"next\";\n this.arg = undefined;\n\n this.tryEntries.forEach(resetTryEntry);\n\n if (!skipTempReset) {\n for (var name in this) {\n // Not sure about the optimal order of these conditions:\n if (name.charAt(0) === \"t\" &&\n hasOwn.call(this, name) &&\n !isNaN(+name.slice(1))) {\n this[name] = undefined;\n }\n }\n }\n },\n\n stop: function() {\n this.done = true;\n\n var rootEntry = this.tryEntries[0];\n var rootRecord = rootEntry.completion;\n if (rootRecord.type === \"throw\") {\n throw rootRecord.arg;\n }\n\n return this.rval;\n },\n\n dispatchException: function(exception) {\n if (this.done) {\n throw exception;\n }\n\n var context = this;\n function handle(loc, caught) {\n record.type = \"throw\";\n record.arg = exception;\n context.next = loc;\n\n if (caught) {\n // If the dispatched exception was caught by a catch block,\n // then let that catch block handle the exception normally.\n context.method = \"next\";\n context.arg = undefined;\n }\n\n return !! caught;\n }\n\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n var record = entry.completion;\n\n if (entry.tryLoc === \"root\") {\n // Exception thrown outside of any try block that could handle\n // it, so set the completion value of the entire function to\n // throw the exception.\n return handle(\"end\");\n }\n\n if (entry.tryLoc <= this.prev) {\n var hasCatch = hasOwn.call(entry, \"catchLoc\");\n var hasFinally = hasOwn.call(entry, \"finallyLoc\");\n\n if (hasCatch && hasFinally) {\n if (this.prev < entry.catchLoc) {\n return handle(entry.catchLoc, true);\n } else if (this.prev < entry.finallyLoc) {\n return handle(entry.finallyLoc);\n }\n\n } else if (hasCatch) {\n if (this.prev < entry.catchLoc) {\n return handle(entry.catchLoc, true);\n }\n\n } else if (hasFinally) {\n if (this.prev < entry.finallyLoc) {\n return handle(entry.finallyLoc);\n }\n\n } else {\n throw new Error(\"try statement without catch or finally\");\n }\n }\n }\n },\n\n abrupt: function(type, arg) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.tryLoc <= this.prev &&\n hasOwn.call(entry, \"finallyLoc\") &&\n this.prev < entry.finallyLoc) {\n var finallyEntry = entry;\n break;\n }\n }\n\n if (finallyEntry &&\n (type === \"break\" ||\n type === \"continue\") &&\n finallyEntry.tryLoc <= arg &&\n arg <= finallyEntry.finallyLoc) {\n // Ignore the finally entry if control is not jumping to a\n // location outside the try/catch block.\n finallyEntry = null;\n }\n\n var record = finallyEntry ? finallyEntry.completion : {};\n record.type = type;\n record.arg = arg;\n\n if (finallyEntry) {\n this.method = \"next\";\n this.next = finallyEntry.finallyLoc;\n return ContinueSentinel;\n }\n\n return this.complete(record);\n },\n\n complete: function(record, afterLoc) {\n if (record.type === \"throw\") {\n throw record.arg;\n }\n\n if (record.type === \"break\" ||\n record.type === \"continue\") {\n this.next = record.arg;\n } else if (record.type === \"return\") {\n this.rval = this.arg = record.arg;\n this.method = \"return\";\n this.next = \"end\";\n } else if (record.type === \"normal\" && afterLoc) {\n this.next = afterLoc;\n }\n\n return ContinueSentinel;\n },\n\n finish: function(finallyLoc) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.finallyLoc === finallyLoc) {\n this.complete(entry.completion, entry.afterLoc);\n resetTryEntry(entry);\n return ContinueSentinel;\n }\n }\n },\n\n \"catch\": function(tryLoc) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.tryLoc === tryLoc) {\n var record = entry.completion;\n if (record.type === \"throw\") {\n var thrown = record.arg;\n resetTryEntry(entry);\n }\n return thrown;\n }\n }\n\n // The context.catch method must only be called with a location\n // argument that corresponds to a known catch block.\n throw new Error(\"illegal catch attempt\");\n },\n\n delegateYield: function(iterable, resultName, nextLoc) {\n this.delegate = {\n iterator: values(iterable),\n resultName: resultName,\n nextLoc: nextLoc\n };\n\n if (this.method === \"next\") {\n // Deliberately forget the last sent value so that we don't\n // accidentally pass it on to the delegate.\n this.arg = undefined;\n }\n\n return ContinueSentinel;\n }\n };\n\n // Regardless of whether this script is executing as a CommonJS module\n // or not, return the runtime object so that we can declare the variable\n // regeneratorRuntime in the outer scope, which allows this module to be\n // injected easily by `bin/regenerator --include-runtime script.js`.\n return exports;\n\n}(\n // If this script is executing as a CommonJS module, use module.exports\n // as the regeneratorRuntime namespace. Otherwise create a new empty\n // object. Either way, the resulting object will be used to initialize\n // the regeneratorRuntime variable at the top of this file.\n typeof module === \"object\" ? module.exports : {}\n));\n\ntry {\n regeneratorRuntime = runtime;\n} catch (accidentalStrictMode) {\n // This module should not be running in strict mode, so the above\n // assignment should always work unless something is misconfigured. Just\n // in case runtime.js accidentally runs in strict mode, we can escape\n // strict mode using a global Function call. This could conceivably fail\n // if a Content Security Policy forbids using Function, but in that case\n // the proper solution is to fix the accidental strict mode problem. If\n // you've misconfigured your bundler to force strict mode and applied a\n // CSP to forbid Function, and you're not willing to fix either of those\n // problems, please detail your unique predicament in a GitHub issue.\n Function(\"r\", \"regeneratorRuntime = r\")(runtime);\n}\n","import type { FileHandle } from 'fs/promises';\nimport type { LocalFile, RemoteFile, BlobFile } from 'generic-filehandle';\n\ntype AnyFile = LocalFile | RemoteFile | BlobFile | FileHandle\ntype ParsedIxx = Map<string, number>;\n\nconst trixPrefixSize = 5;\n\n\n// Define this object with .ixx and .ix files.\n// Then use the trixSearch() function to search for a word.\nexport default class Trix {\n private index: Promise<ParsedIxx>;\n private ixFile: AnyFile;\n maxResults: number;\n\n /**\n * @param ixxFile [anyFile] the second-level trix index file produced by ixIxx.\n * @param ixFile [anyFile] the first-level trix index file produced by ixIxx.\n * @param maxResults [number] the maximum number of results to return. Default is set to 20.\n */\n constructor(ixxFile: AnyFile, ixFile: AnyFile, maxResults: number = 20) {\n this.index = this._parseIxx(ixxFile);\n this.ixFile = ixFile;\n this.maxResults = maxResults;\n }\n\n \n /**\n * Search trix for the given searchWord(s). Return up to {this.maxResults} results.\n * This method matches each index prefix against each searchWord. It does not do fuzzy matching.\n *\n * @param searchString [string] term(s) separated by spaces to search for id(s).\n * @returns results [Array<string>] where each string is a corresponding itemId.\n */\n async search(searchString: string) {\n\n // If there is one search word, store results in resultArr.\n let resultArr: Array<string> = [];\n\n // If there are multiple words, store results in initialSet.\n // firstWord indicates we are iterating the first time.\n let firstWord: boolean = true;\n let initialSet = new Set<string>();\n\n let searchWords = searchString.split(' ');\n\n // Loop for each word in searchWords.\n // If there are more than one searchWords, use resultSet and only take the matching terms\n // that are also in initialSet. \n // Otherwise, just iterate once and add words to resultArr.\n for (let w = 0; w < searchWords.length; w++) {\n let searchWord = searchWords[w];\n searchWord = searchWord.toLowerCase();\n\n // 1. Seek ahead to byte `this.index` of `ixFile`. Load this section of .ix data into the buffer.\n let bufData = await this._getBuffer(searchWord);\n let buf: Buffer = bufData.buf;\n let bufPos = bufData.bufEndPos;\n let resultSet = new Set<string>();\n let linePtr = 0;\n let numValues = 0;\n\n // 2. Iterate through the entire buffer\n while (linePtr < buf.byteLength) {\n let startsWith = true;\n let done = false;\n let i = linePtr;\n\n // 3. Check if the first word in the current line has the same prefix as searchWord.\n\n // Iterate through each char of the line in the buffer.\n // break out of loop when we hit a \\n (unicode char 10) or the searchWord does not match the line.\n while (buf[i] != 10) {\n\n if (i >= buf.byteLength) {\n \n // In this case, we ran out of our current buffer, but could still find more matches.\n // Load another chunk in to buf and repeat.\n let tempBufData = await this._getNextChunk(bufPos);\n if (tempBufData) {\n buf = tempBufData.buf;\n bufPos = tempBufData.bufEndPos; \n i = 0;\n linePtr = 0;\n }\n else {\n // If tempBufData is null, we reached the end of the file, so we are done.\n done = true;\n break;\n }\n }\n\n \n if (startsWith) {\n let cur = String.fromCharCode(buf[i]);\n\n if (i < linePtr + searchWord.length && searchWord[i - linePtr] > cur) {\n // searchWord[i] > cur, so keep looping.\n startsWith = false;\n } \n else if (i < linePtr + searchWord.length && searchWord[i - linePtr] < cur) {\n // searchWord[i] < cur, so we lexicographically will not find any more results.\n startsWith = false;\n done = true;\n break;\n } \n else {\n \n // This condition indicates we found a match.\n if (buf[i] === 44) {\n // We found a ',' so increment numValues by one.\n numValues++;\n\n // If we're searching for one word and we have enough results, break out at the next space.\n if (numValues >= this.maxResults && searchWords.length === 1) {\n while (buf[i] != 32) \n i++;\n\n break;\n }\n }\n }\n }\n\n i++;\n }\n\n if (done) break;\n\n // If the line starts with the searchWord, we have a hit!\n if (startsWith) {\n\n\n // Parse the line and add results to arr.\n const line: string = buf.slice(linePtr, i).toString();\n let arr = this._parseHitString(line);\n\n if (searchWords.length === 1) {\n // Only a single search word so add results to array.\n resultArr = resultArr.concat(arr);\n // Once we have enough results, stop searching.\n if (resultArr.length >= this.maxResults) break;\n \n }\n else {\n // Handle multiple words using sets.\n for (let hit of arr) {\n hit = hit.toLowerCase();\n\n if (firstWord) {\n resultSet.add(hit);\n }\n else {\n if (initialSet.has(hit)) {\n resultSet.add(hit);\n \n // If it is on the last iteration of words, break after we reach maxResults\n if (w === searchWords.length - 1 && resultSet.size >= this.maxResults)\n break;\n }\n }\n } \n }\n }\n\n linePtr = i + 1;\n }\n\n initialSet = resultSet;\n firstWord = false;\n\n // If there aren't any results, stop looping, because an intersection with an empty set is an empty set.\n if (resultArr.length === 0 && initialSet.size === 0)\n return [];\n\n }\n \n // 4. Return the hitList [list of string]\n if (searchWords.length === 1) {\n return resultArr;\n }\n\n // Else we need to return our set converted to an array\n resultArr = Array.from(initialSet);\n if (resultArr.length > this.maxResults)\n return resultArr.slice(0, this.maxResults)\n\n return resultArr;\n }\n\n\n // Private Methods:\n\n /**\n * Seek ahead to the correct position in the .ix file, \n * then load that chunk of .ix into a buffer.\n *\n * @param searchWord [string]\n * @returns a Buffer holding the sections we want to search.\n */\n private async _getBuffer(searchWord: string) {\n\n // Get position to seek to in .ix file from indexes.\n let seekPosStart = 0;\n let seekPosEnd = -1;\n const indexes = await this.index;\n for (let [key, value] of indexes) {\n let trimmedKey = key.slice(0, searchWord.length);\n if (seekPosEnd === -1) {\n if (trimmedKey >= searchWord) {\n // We reached the end pos in the file.\n seekPosEnd = value - 1;\n break;\n } \n else {\n seekPosStart = value;\n }\n }\n }\n \n // Return the buffer and its end position in the file.\n return this._createBuffer(seekPosStart, seekPosEnd);\n }\n\n\n /**\n * Given the end position of the last buffer, \n * load the next chunk of .ix data into a buffer and return it.\n *\n * @param seekPosStart [number] where to start loading data into the new buffer.\n * @returns a Buffer holding the chunk we want to search.\n */\n private async _getNextChunk(seekPosStart: number) {\n\n if (seekPosStart == -1)\n return null;\n\n let seekPosEnd = -1;\n // Get the next position of the end of buffer.\n const indexes = await this.index;\n for (let [key, value] of indexes) {\n if (value <= seekPosStart + 1)\n continue\n\n seekPosEnd = value;\n break;\n }\n\n seekPosStart--;\n\n // Return the buffer and its end position in the file.\n return this._createBuffer(seekPosStart, seekPosEnd);\n }\n\n\n /**\n * Create and return a buffer given the start and end position \n * of what to load from the .ix file.\n *\n * @param seekPosStart [number] byte the buffer should start reading from file.\n * @param seekPosEnd [number] byte the buffer should stop reading from file.\n * @returns a Buffer holding the chunk of data.\n */\n private async _createBuffer(seekPosStart: number, seekPosEnd: number) { \n // Set bufLength to seekPosEnd or the end of the file.\n let bufLength: number;\n if (seekPosEnd < 0) {\n const stat = await this.ixFile.stat();\n bufLength = stat.size - seekPosStart;\n } \n else {\n bufLength = seekPosEnd - seekPosStart;\n }\n \n let buf = Buffer.alloc(bufLength);\n await this.ixFile.read(buf, 0, bufLength, seekPosStart);\n \n // Return the buffer and its end position in the file.\n return { \"buf\": buf, \"bufEndPos\": seekPosEnd };\n }\n\n\n\n\n /**\n * Takes in a hit string and returns an array of result terms.\n *\n * @param line [string] The line of .ix that is a hit.\n * @returns results [Array<hit>]. Each hit contains the itemId [string], and wordPos [number].\n */\n private _parseHitString(line: string) {\n let arr: Array<string> = [];\n const parts = line.split(' ');\n // Each result is of format: \"{itemId},{wordPos}\"\n // Parse the entire line of these and return\n for (const part of parts) {\n const pair = part.split(',');\n if (pair.length === 2) {\n const itemId: string = pair[0];\n const wordPos: number = Number.parseInt(pair[1]);\n if (typeof wordPos !== 'number' || isNaN(wordPos))\n throw `Error in ix index format at term ${itemId} for word ${parts[0]}`;\n\n arr.push(itemId);\n } else if (pair.length > 1) {\n throw `Error in ix index format at word ${parts[0]}`;\n }\n }\n return arr;\n }\n\n /**\n * Parses ixx file and constructs a map of {word: ixFileLocation}\n *\n * @param ixxFile [anyFile] second level index that is produced by ixIxx.\n * @returns a ParsedIxx map.\n */\n private async _parseIxx(ixxFile: AnyFile): Promise<ParsedIxx> {\n const ixx = new Map();\n\n // Load the ixxFile into ixxData object\n const buf = await ixxFile.readFile();\n const lines = buf.toString('utf8').split('\\n');\n for (const line of lines) {\n if (line.length > 0) {\n // Parse the ixx line\n // Format: 5 characters prefix, 10 characters hex\n const prefix = line.substr(0, trixPrefixSize);\n const posStr = line.substr(trixPrefixSize);\n const pos = Number.parseInt(posStr, 16);\n if (typeof pos !== 'number' || isNaN(pos))\n throw `Error in ixx index format at word ${prefix}`;\n\n ixx.set(prefix, pos);\n }\n }\n\n return ixx;\n }\n}\n"],"names":["undefined","trixPrefixSize","Trix","ixxFile","ixFile","maxResults","index","_parseIxx","search","searchString","resultArr","firstWord","initialSet","Set","searchWords","split","w","length","searchWord","toLowerCase","_getBuffer","bufData","buf","bufPos","bufEndPos","resultSet","linePtr","numValues","byteLength","startsWith","done","i","_getNextChunk","tempBufData","cur","String","fromCharCode","line","slice","toString","arr","_parseHitString","concat","hit","add","has","size","Array","from","seekPosStart","seekPosEnd","indexes","key","value","trimmedKey","_createBuffer","stat","bufLength","Buffer","alloc","read","parts","part","pair","itemId","wordPos","Number","parseInt","isNaN","push","ixx","Map","readFile","lines","prefix","substr","posStr","pos","set"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,IAAI,UAAU,OAAO,EAAE;AAElC;AACA,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;AAC5B,EAAE,IAAI,MAAM,GAAG,EAAE,CAAC,cAA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AhB,EAAwB,EAAxB,CAZV;;AAAA,oBAaE,OAAOC,GAAP,KAAe,QAAf,IAA2BT,KAAK,CAACS,GAAD,CAblC;AAAA;AAAA;AAAA;;AAAA,2DAc2CH,MAd3C;;AAAA;AAgBFJ,cAAAA,GAAG,CAACQ,GAAJ,CAAQJ,MAAR,EAAgBG,GAAhB;;AAhBE;AAAA;AAAA;;AAAA;AAAA,gDAoBCP,GApBD;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;;;;;;;;;"}
|
package/src/index.ts
DELETED
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
import type { FileHandle } from 'fs/promises';
|
|
2
|
-
import type { LocalFile, RemoteFile, BlobFile } from 'generic-filehandle';
|
|
3
|
-
|
|
4
|
-
type AnyFile = LocalFile | RemoteFile | BlobFile | FileHandle
|
|
5
|
-
type ParsedIxx = Map<string, number>;
|
|
6
|
-
|
|
7
|
-
const trixPrefixSize = 5;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// Define this object with .ixx and .ix files.
|
|
11
|
-
// Then use the trixSearch() function to search for a word.
|
|
12
|
-
export default class Trix {
|
|
13
|
-
private index: Promise<ParsedIxx>;
|
|
14
|
-
private ixFile: AnyFile;
|
|
15
|
-
maxResults: number;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param ixxFile [anyFile] the second-level trix index file produced by ixIxx.
|
|
19
|
-
* @param ixFile [anyFile] the first-level trix index file produced by ixIxx.
|
|
20
|
-
* @param maxResults [number] the maximum number of results to return. Default is set to 20.
|
|
21
|
-
*/
|
|
22
|
-
constructor(ixxFile: AnyFile, ixFile: AnyFile, maxResults: number = 20) {
|
|
23
|
-
this.index = this._parseIxx(ixxFile);
|
|
24
|
-
this.ixFile = ixFile;
|
|
25
|
-
this.maxResults = maxResults;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Search trix for the given searchWord(s). Return up to {this.maxResults} results.
|
|
31
|
-
* This method matches each index prefix against each searchWord. It does not do fuzzy matching.
|
|
32
|
-
*
|
|
33
|
-
* @param searchString [string] term(s) separated by spaces to search for id(s).
|
|
34
|
-
* @returns results [Array<string>] where each string is a corresponding itemId.
|
|
35
|
-
*/
|
|
36
|
-
async search(searchString: string) {
|
|
37
|
-
|
|
38
|
-
// If there is one search word, store results in resultArr.
|
|
39
|
-
let resultArr: Array<string> = [];
|
|
40
|
-
|
|
41
|
-
// If there are multiple words, store results in initialSet.
|
|
42
|
-
// firstWord indicates we are iterating the first time.
|
|
43
|
-
let firstWord: boolean = true;
|
|
44
|
-
let initialSet = new Set<string>();
|
|
45
|
-
|
|
46
|
-
let searchWords = searchString.split(' ');
|
|
47
|
-
|
|
48
|
-
// Loop for each word in searchWords.
|
|
49
|
-
// If there are more than one searchWords, use resultSet and only take the matching terms
|
|
50
|
-
// that are also in initialSet.
|
|
51
|
-
// Otherwise, just iterate once and add words to resultArr.
|
|
52
|
-
for (let w = 0; w < searchWords.length; w++) {
|
|
53
|
-
let searchWord = searchWords[w];
|
|
54
|
-
searchWord = searchWord.toLowerCase();
|
|
55
|
-
|
|
56
|
-
// 1. Seek ahead to byte `this.index` of `ixFile`. Load this section of .ix data into the buffer.
|
|
57
|
-
let bufData = await this._getBuffer(searchWord);
|
|
58
|
-
let buf: Buffer = bufData.buf;
|
|
59
|
-
let bufPos = bufData.bufEndPos;
|
|
60
|
-
let resultSet = new Set<string>();
|
|
61
|
-
let linePtr = 0;
|
|
62
|
-
let numValues = 0;
|
|
63
|
-
|
|
64
|
-
// 2. Iterate through the entire buffer
|
|
65
|
-
while (linePtr < buf.byteLength) {
|
|
66
|
-
let startsWith = true;
|
|
67
|
-
let done = false;
|
|
68
|
-
let i = linePtr;
|
|
69
|
-
|
|
70
|
-
// 3. Check if the first word in the current line has the same prefix as searchWord.
|
|
71
|
-
|
|
72
|
-
// Iterate through each char of the line in the buffer.
|
|
73
|
-
// break out of loop when we hit a \n (unicode char 10) or the searchWord does not match the line.
|
|
74
|
-
while (buf[i] != 10) {
|
|
75
|
-
|
|
76
|
-
if (i >= buf.byteLength) {
|
|
77
|
-
|
|
78
|
-
// In this case, we ran out of our current buffer, but could still find more matches.
|
|
79
|
-
// Load another chunk in to buf and repeat.
|
|
80
|
-
let tempBufData = await this._getNextChunk(bufPos);
|
|
81
|
-
if (tempBufData) {
|
|
82
|
-
buf = tempBufData.buf;
|
|
83
|
-
bufPos = tempBufData.bufEndPos;
|
|
84
|
-
i = 0;
|
|
85
|
-
linePtr = 0;
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
// If tempBufData is null, we reached the end of the file, so we are done.
|
|
89
|
-
done = true;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (startsWith) {
|
|
96
|
-
let cur = String.fromCharCode(buf[i]);
|
|
97
|
-
|
|
98
|
-
if (i < linePtr + searchWord.length && searchWord[i - linePtr] > cur) {
|
|
99
|
-
// searchWord[i] > cur, so keep looping.
|
|
100
|
-
startsWith = false;
|
|
101
|
-
}
|
|
102
|
-
else if (i < linePtr + searchWord.length && searchWord[i - linePtr] < cur) {
|
|
103
|
-
// searchWord[i] < cur, so we lexicographically will not find any more results.
|
|
104
|
-
startsWith = false;
|
|
105
|
-
done = true;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
|
|
110
|
-
// This condition indicates we found a match.
|
|
111
|
-
if (buf[i] === 44) {
|
|
112
|
-
// We found a ',' so increment numValues by one.
|
|
113
|
-
numValues++;
|
|
114
|
-
|
|
115
|
-
// If we're searching for one word and we have enough results, break out at the next space.
|
|
116
|
-
if (numValues >= this.maxResults && searchWords.length === 1) {
|
|
117
|
-
while (buf[i] != 32)
|
|
118
|
-
i++;
|
|
119
|
-
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
i++;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (done) break;
|
|
130
|
-
|
|
131
|
-
// If the line starts with the searchWord, we have a hit!
|
|
132
|
-
if (startsWith) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// Parse the line and add results to arr.
|
|
136
|
-
const line: string = buf.slice(linePtr, i).toString();
|
|
137
|
-
let arr = this._parseHitString(line);
|
|
138
|
-
|
|
139
|
-
if (searchWords.length === 1) {
|
|
140
|
-
// Only a single search word so add results to array.
|
|
141
|
-
resultArr = resultArr.concat(arr);
|
|
142
|
-
// Once we have enough results, stop searching.
|
|
143
|
-
if (resultArr.length >= this.maxResults) break;
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
// Handle multiple words using sets.
|
|
148
|
-
for (let hit of arr) {
|
|
149
|
-
hit = hit.toLowerCase();
|
|
150
|
-
|
|
151
|
-
if (firstWord) {
|
|
152
|
-
resultSet.add(hit);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
if (initialSet.has(hit)) {
|
|
156
|
-
resultSet.add(hit);
|
|
157
|
-
|
|
158
|
-
// If it is on the last iteration of words, break after we reach maxResults
|
|
159
|
-
if (w === searchWords.length - 1 && resultSet.size >= this.maxResults)
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
linePtr = i + 1;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
initialSet = resultSet;
|
|
171
|
-
firstWord = false;
|
|
172
|
-
|
|
173
|
-
// If there aren't any results, stop looping, because an intersection with an empty set is an empty set.
|
|
174
|
-
if (resultArr.length === 0 && initialSet.size === 0)
|
|
175
|
-
return [];
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// 4. Return the hitList [list of string]
|
|
180
|
-
if (searchWords.length === 1) {
|
|
181
|
-
return resultArr;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Else we need to return our set converted to an array
|
|
185
|
-
resultArr = Array.from(initialSet);
|
|
186
|
-
if (resultArr.length > this.maxResults)
|
|
187
|
-
return resultArr.slice(0, this.maxResults)
|
|
188
|
-
|
|
189
|
-
return resultArr;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
// Private Methods:
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Seek ahead to the correct position in the .ix file,
|
|
197
|
-
* then load that chunk of .ix into a buffer.
|
|
198
|
-
*
|
|
199
|
-
* @param searchWord [string]
|
|
200
|
-
* @returns a Buffer holding the sections we want to search.
|
|
201
|
-
*/
|
|
202
|
-
private async _getBuffer(searchWord: string) {
|
|
203
|
-
|
|
204
|
-
// Get position to seek to in .ix file from indexes.
|
|
205
|
-
let seekPosStart = 0;
|
|
206
|
-
let seekPosEnd = -1;
|
|
207
|
-
const indexes = await this.index;
|
|
208
|
-
for (let [key, value] of indexes) {
|
|
209
|
-
let trimmedKey = key.slice(0, searchWord.length);
|
|
210
|
-
if (seekPosEnd === -1) {
|
|
211
|
-
if (trimmedKey >= searchWord) {
|
|
212
|
-
// We reached the end pos in the file.
|
|
213
|
-
seekPosEnd = value - 1;
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
seekPosStart = value;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// Return the buffer and its end position in the file.
|
|
223
|
-
return this._createBuffer(seekPosStart, seekPosEnd);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Given the end position of the last buffer,
|
|
229
|
-
* load the next chunk of .ix data into a buffer and return it.
|
|
230
|
-
*
|
|
231
|
-
* @param seekPosStart [number] where to start loading data into the new buffer.
|
|
232
|
-
* @returns a Buffer holding the chunk we want to search.
|
|
233
|
-
*/
|
|
234
|
-
private async _getNextChunk(seekPosStart: number) {
|
|
235
|
-
|
|
236
|
-
if (seekPosStart == -1)
|
|
237
|
-
return null;
|
|
238
|
-
|
|
239
|
-
let seekPosEnd = -1;
|
|
240
|
-
// Get the next position of the end of buffer.
|
|
241
|
-
const indexes = await this.index;
|
|
242
|
-
for (let [key, value] of indexes) {
|
|
243
|
-
if (value <= seekPosStart + 1)
|
|
244
|
-
continue
|
|
245
|
-
|
|
246
|
-
seekPosEnd = value;
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
seekPosStart--;
|
|
251
|
-
|
|
252
|
-
// Return the buffer and its end position in the file.
|
|
253
|
-
return this._createBuffer(seekPosStart, seekPosEnd);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Create and return a buffer given the start and end position
|
|
259
|
-
* of what to load from the .ix file.
|
|
260
|
-
*
|
|
261
|
-
* @param seekPosStart [number] byte the buffer should start reading from file.
|
|
262
|
-
* @param seekPosEnd [number] byte the buffer should stop reading from file.
|
|
263
|
-
* @returns a Buffer holding the chunk of data.
|
|
264
|
-
*/
|
|
265
|
-
private async _createBuffer(seekPosStart: number, seekPosEnd: number) {
|
|
266
|
-
// Set bufLength to seekPosEnd or the end of the file.
|
|
267
|
-
let bufLength: number;
|
|
268
|
-
if (seekPosEnd < 0) {
|
|
269
|
-
const stat = await this.ixFile.stat();
|
|
270
|
-
bufLength = stat.size - seekPosStart;
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
bufLength = seekPosEnd - seekPosStart;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
let buf = Buffer.alloc(bufLength);
|
|
277
|
-
await this.ixFile.read(buf, 0, bufLength, seekPosStart);
|
|
278
|
-
|
|
279
|
-
// Return the buffer and its end position in the file.
|
|
280
|
-
return { "buf": buf, "bufEndPos": seekPosEnd };
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Takes in a hit string and returns an array of result terms.
|
|
288
|
-
*
|
|
289
|
-
* @param line [string] The line of .ix that is a hit.
|
|
290
|
-
* @returns results [Array<hit>]. Each hit contains the itemId [string], and wordPos [number].
|
|
291
|
-
*/
|
|
292
|
-
private _parseHitString(line: string) {
|
|
293
|
-
let arr: Array<string> = [];
|
|
294
|
-
const parts = line.split(' ');
|
|
295
|
-
// Each result is of format: "{itemId},{wordPos}"
|
|
296
|
-
// Parse the entire line of these and return
|
|
297
|
-
for (const part of parts) {
|
|
298
|
-
const pair = part.split(',');
|
|
299
|
-
if (pair.length === 2) {
|
|
300
|
-
const itemId: string = pair[0];
|
|
301
|
-
const wordPos: number = Number.parseInt(pair[1]);
|
|
302
|
-
if (typeof wordPos !== 'number' || isNaN(wordPos))
|
|
303
|
-
throw `Error in ix index format at term ${itemId} for word ${parts[0]}`;
|
|
304
|
-
|
|
305
|
-
arr.push(itemId);
|
|
306
|
-
} else if (pair.length > 1) {
|
|
307
|
-
throw `Error in ix index format at word ${parts[0]}`;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return arr;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Parses ixx file and constructs a map of {word: ixFileLocation}
|
|
315
|
-
*
|
|
316
|
-
* @param ixxFile [anyFile] second level index that is produced by ixIxx.
|
|
317
|
-
* @returns a ParsedIxx map.
|
|
318
|
-
*/
|
|
319
|
-
private async _parseIxx(ixxFile: AnyFile): Promise<ParsedIxx> {
|
|
320
|
-
const ixx = new Map();
|
|
321
|
-
|
|
322
|
-
// Load the ixxFile into ixxData object
|
|
323
|
-
const buf = await ixxFile.readFile();
|
|
324
|
-
const lines = buf.toString('utf8').split('\n');
|
|
325
|
-
for (const line of lines) {
|
|
326
|
-
if (line.length > 0) {
|
|
327
|
-
// Parse the ixx line
|
|
328
|
-
// Format: 5 characters prefix, 10 characters hex
|
|
329
|
-
const prefix = line.substr(0, trixPrefixSize);
|
|
330
|
-
const posStr = line.substr(trixPrefixSize);
|
|
331
|
-
const pos = Number.parseInt(posStr, 16);
|
|
332
|
-
if (typeof pos !== 'number' || isNaN(pos))
|
|
333
|
-
throw `Error in ixx index format at word ${prefix}`;
|
|
334
|
-
|
|
335
|
-
ixx.set(prefix, pos);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
return ixx;
|
|
340
|
-
}
|
|
341
|
-
}
|