lunr-elastic-search
Version:
Uses Lunr.js to index and search the knowledge base.
1,755 lines (1,483 loc) • 203 kB
JavaScript
var LunrSearch =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 12);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var bind = __webpack_require__(4);
var isBuffer = __webpack_require__(17);
/*global toString:true*/
// utils is a library of generic helper functions non-specific to axios
var toString = Object.prototype.toString;
/**
* Determine if a value is an Array
*
* @param {Object} val The value to test
* @returns {boolean} True if value is an Array, otherwise false
*/
function isArray(val) {
return toString.call(val) === '[object Array]';
}
/**
* Determine if a value is an ArrayBuffer
*
* @param {Object} val The value to test
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
*/
function isArrayBuffer(val) {
return toString.call(val) === '[object ArrayBuffer]';
}
/**
* Determine if a value is a FormData
*
* @param {Object} val The value to test
* @returns {boolean} True if value is an FormData, otherwise false
*/
function isFormData(val) {
return (typeof FormData !== 'undefined') && (val instanceof FormData);
}
/**
* Determine if a value is a view on an ArrayBuffer
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
*/
function isArrayBufferView(val) {
var result;
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
result = ArrayBuffer.isView(val);
} else {
result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
}
return result;
}
/**
* Determine if a value is a String
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a String, otherwise false
*/
function isString(val) {
return typeof val === 'string';
}
/**
* Determine if a value is a Number
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Number, otherwise false
*/
function isNumber(val) {
return typeof val === 'number';
}
/**
* Determine if a value is undefined
*
* @param {Object} val The value to test
* @returns {boolean} True if the value is undefined, otherwise false
*/
function isUndefined(val) {
return typeof val === 'undefined';
}
/**
* Determine if a value is an Object
*
* @param {Object} val The value to test
* @returns {boolean} True if value is an Object, otherwise false
*/
function isObject(val) {
return val !== null && typeof val === 'object';
}
/**
* Determine if a value is a Date
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Date, otherwise false
*/
function isDate(val) {
return toString.call(val) === '[object Date]';
}
/**
* Determine if a value is a File
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a File, otherwise false
*/
function isFile(val) {
return toString.call(val) === '[object File]';
}
/**
* Determine if a value is a Blob
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Blob, otherwise false
*/
function isBlob(val) {
return toString.call(val) === '[object Blob]';
}
/**
* Determine if a value is a Function
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Function, otherwise false
*/
function isFunction(val) {
return toString.call(val) === '[object Function]';
}
/**
* Determine if a value is a Stream
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a Stream, otherwise false
*/
function isStream(val) {
return isObject(val) && isFunction(val.pipe);
}
/**
* Determine if a value is a URLSearchParams object
*
* @param {Object} val The value to test
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
*/
function isURLSearchParams(val) {
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
}
/**
* Trim excess whitespace off the beginning and end of a string
*
* @param {String} str The String to trim
* @returns {String} The String freed of excess whitespace
*/
function trim(str) {
return str.replace(/^\s*/, '').replace(/\s*$/, '');
}
/**
* Determine if we're running in a standard browser environment
*
* This allows axios to run in a web worker, and react-native.
* Both environments support XMLHttpRequest, but not fully standard globals.
*
* web workers:
* typeof window -> undefined
* typeof document -> undefined
*
* react-native:
* navigator.product -> 'ReactNative'
*/
function isStandardBrowserEnv() {
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
return false;
}
return (
typeof window !== 'undefined' &&
typeof document !== 'undefined'
);
}
/**
* Iterate over an Array or an Object invoking a function for each item.
*
* If `obj` is an Array callback will be called passing
* the value, index, and complete array for each item.
*
* If 'obj' is an Object callback will be called passing
* the value, key, and complete object for each property.
*
* @param {Object|Array} obj The object to iterate
* @param {Function} fn The callback to invoke for each item
*/
function forEach(obj, fn) {
// Don't bother if no value provided
if (obj === null || typeof obj === 'undefined') {
return;
}
// Force an array if not already something iterable
if (typeof obj !== 'object' && !isArray(obj)) {
/*eslint no-param-reassign:0*/
obj = [obj];
}
if (isArray(obj)) {
// Iterate over array values
for (var i = 0, l = obj.length; i < l; i++) {
fn.call(null, obj[i], i, obj);
}
} else {
// Iterate over object keys
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
fn.call(null, obj[key], key, obj);
}
}
}
}
/**
* Accepts varargs expecting each argument to be an object, then
* immutably merges the properties of each object and returns result.
*
* When multiple objects contain the same key the later object in
* the arguments list will take precedence.
*
* Example:
*
* ```js
* var result = merge({foo: 123}, {foo: 456});
* console.log(result.foo); // outputs 456
* ```
*
* @param {Object} obj1 Object to merge
* @returns {Object} Result of all merge properties
*/
function merge(/* obj1, obj2, obj3, ... */) {
var result = {};
function assignValue(val, key) {
if (typeof result[key] === 'object' && typeof val === 'object') {
result[key] = merge(result[key], val);
} else {
result[key] = val;
}
}
for (var i = 0, l = arguments.length; i < l; i++) {
forEach(arguments[i], assignValue);
}
return result;
}
/**
* Extends object a by mutably adding to it the properties of object b.
*
* @param {Object} a The object to be extended
* @param {Object} b The object to copy properties from
* @param {Object} thisArg The object to bind function to
* @return {Object} The resulting value of object a
*/
function extend(a, b, thisArg) {
forEach(b, function assignValue(val, key) {
if (thisArg && typeof val === 'function') {
a[key] = bind(val, thisArg);
} else {
a[key] = val;
}
});
return a;
}
module.exports = {
isArray: isArray,
isArrayBuffer: isArrayBuffer,
isBuffer: isBuffer,
isFormData: isFormData,
isArrayBufferView: isArrayBufferView,
isString: isString,
isNumber: isNumber,
isObject: isObject,
isUndefined: isUndefined,
isDate: isDate,
isFile: isFile,
isBlob: isBlob,
isFunction: isFunction,
isStream: isStream,
isURLSearchParams: isURLSearchParams,
isStandardBrowserEnv: isStandardBrowserEnv,
forEach: forEach,
merge: merge,
extend: extend,
trim: trim
};
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(process) {
var utils = __webpack_require__(0);
var normalizeHeaderName = __webpack_require__(19);
var DEFAULT_CONTENT_TYPE = {
'Content-Type': 'application/x-www-form-urlencoded'
};
function setContentTypeIfUnset(headers, value) {
if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
headers['Content-Type'] = value;
}
}
function getDefaultAdapter() {
var adapter;
if (typeof XMLHttpRequest !== 'undefined') {
// For browsers use XHR adapter
adapter = __webpack_require__(6);
} else if (typeof process !== 'undefined') {
// For node use HTTP adapter
adapter = __webpack_require__(6);
}
return adapter;
}
var defaults = {
adapter: getDefaultAdapter(),
transformRequest: [function transformRequest(data, headers) {
normalizeHeaderName(headers, 'Content-Type');
if (utils.isFormData(data) ||
utils.isArrayBuffer(data) ||
utils.isBuffer(data) ||
utils.isStream(data) ||
utils.isFile(data) ||
utils.isBlob(data)
) {
return data;
}
if (utils.isArrayBufferView(data)) {
return data.buffer;
}
if (utils.isURLSearchParams(data)) {
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
return data.toString();
}
if (utils.isObject(data)) {
setContentTypeIfUnset(headers, 'application/json;charset=utf-8');
return JSON.stringify(data);
}
return data;
}],
transformResponse: [function transformResponse(data) {
/*eslint no-param-reassign:0*/
if (typeof data === 'string') {
try {
data = JSON.parse(data);
} catch (e) { /* Ignore */ }
}
return data;
}],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: function validateStatus(status) {
return status >= 200 && status < 300;
}
};
defaults.headers = {
common: {
'Accept': 'application/json, text/plain, */*'
}
};
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
defaults.headers[method] = {};
});
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
});
module.exports = defaults;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(14);
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(16);
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
module.exports = function bind(fn, thisArg) {
return function wrap() {
var args = new Array(arguments.length);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i];
}
return fn.apply(thisArg, args);
};
};
/***/ }),
/* 5 */
/***/ (function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(process) {
var utils = __webpack_require__(0);
var settle = __webpack_require__(20);
var buildURL = __webpack_require__(22);
var parseHeaders = __webpack_require__(23);
var isURLSameOrigin = __webpack_require__(24);
var createError = __webpack_require__(7);
var btoa = (typeof window !== 'undefined' && window.btoa && window.btoa.bind(window)) || __webpack_require__(25);
module.exports = function xhrAdapter(config) {
return new Promise(function dispatchXhrRequest(resolve, reject) {
var requestData = config.data;
var requestHeaders = config.headers;
if (utils.isFormData(requestData)) {
delete requestHeaders['Content-Type']; // Let the browser set it
}
var request = new XMLHttpRequest();
var loadEvent = 'onreadystatechange';
var xDomain = false;
// For IE 8/9 CORS support
// Only supports POST and GET calls and doesn't returns the response headers.
// DON'T do this for testing b/c XMLHttpRequest is mocked, not XDomainRequest.
if (process.env.NODE_ENV !== 'test' &&
typeof window !== 'undefined' &&
window.XDomainRequest && !('withCredentials' in request) &&
!isURLSameOrigin(config.url)) {
request = new window.XDomainRequest();
loadEvent = 'onload';
xDomain = true;
request.onprogress = function handleProgress() {};
request.ontimeout = function handleTimeout() {};
}
// HTTP basic authentication
if (config.auth) {
var username = config.auth.username || '';
var password = config.auth.password || '';
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
}
request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true);
// Set the request timeout in MS
request.timeout = config.timeout;
// Listen for ready state
request[loadEvent] = function handleLoad() {
if (!request || (request.readyState !== 4 && !xDomain)) {
return;
}
// The request errored out and we didn't get a response, this will be
// handled by onerror instead
// With one exception: request that using file: protocol, most browsers
// will return status as 0 even though it's a successful request
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
return;
}
// Prepare the response
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
var response = {
data: responseData,
// IE sends 1223 instead of 204 (https://github.com/mzabriskie/axios/issues/201)
status: request.status === 1223 ? 204 : request.status,
statusText: request.status === 1223 ? 'No Content' : request.statusText,
headers: responseHeaders,
config: config,
request: request
};
settle(resolve, reject, response);
// Clean up request
request = null;
};
// Handle low level network errors
request.onerror = function handleError() {
// Real errors are hidden from us by the browser
// onerror should only fire if it's a network error
reject(createError('Network Error', config, null, request));
// Clean up request
request = null;
};
// Handle timeout
request.ontimeout = function handleTimeout() {
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED',
request));
// Clean up request
request = null;
};
// Add xsrf header
// This is only done if running in a standard browser environment.
// Specifically not if we're in a web worker, or react-native.
if (utils.isStandardBrowserEnv()) {
var cookies = __webpack_require__(26);
// Add xsrf header
var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
cookies.read(config.xsrfCookieName) :
undefined;
if (xsrfValue) {
requestHeaders[config.xsrfHeaderName] = xsrfValue;
}
}
// Add headers to the request
if ('setRequestHeader' in request) {
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
// Remove Content-Type if data is undefined
delete requestHeaders[key];
} else {
// Otherwise add header to the request
request.setRequestHeader(key, val);
}
});
}
// Add withCredentials to request if needed
if (config.withCredentials) {
request.withCredentials = true;
}
// Add responseType to request if needed
if (config.responseType) {
try {
request.responseType = config.responseType;
} catch (e) {
// Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
// But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
if (config.responseType !== 'json') {
throw e;
}
}
}
// Handle progress if needed
if (typeof config.onDownloadProgress === 'function') {
request.addEventListener('progress', config.onDownloadProgress);
}
// Not all browsers support upload events
if (typeof config.onUploadProgress === 'function' && request.upload) {
request.upload.addEventListener('progress', config.onUploadProgress);
}
if (config.cancelToken) {
// Handle cancellation
config.cancelToken.promise.then(function onCanceled(cancel) {
if (!request) {
return;
}
request.abort();
reject(cancel);
// Clean up request
request = null;
});
}
if (requestData === undefined) {
requestData = null;
}
// Send the request
request.send(requestData);
});
};
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var enhanceError = __webpack_require__(21);
/**
* Create an Error with the specified message, config, error code, request and response.
*
* @param {string} message The error message.
* @param {Object} config The config.
* @param {string} [code] The error code (for example, 'ECONNABORTED').
* @param {Object} [request] The request.
* @param {Object} [response] The response.
* @returns {Error} The created error.
*/
module.exports = function createError(message, config, code, request, response) {
var error = new Error(message);
return enhanceError(error, config, code, request, response);
};
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
module.exports = function isCancel(value) {
return !!(value && value.__CANCEL__);
};
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* A `Cancel` is an object that is thrown when an operation is canceled.
*
* @class
* @param {string=} message The message.
*/
function Cancel(message) {
this.message = message;
}
Cancel.prototype.toString = function toString() {
return 'Cancel' + (this.message ? ': ' + this.message : '');
};
Cancel.prototype.__CANCEL__ = true;
module.exports = Cancel;
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.buildResults = exports.definedFunction = undefined;
var _definedFunction = __webpack_require__(37);
var _definedFunction2 = _interopRequireDefault(_definedFunction);
var _buildResults = __webpack_require__(38);
var _buildResults2 = _interopRequireDefault(_buildResults);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @namespace util
*/
exports.definedFunction = _definedFunction2.default;
exports.buildResults = _buildResults2.default;
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Expose `arrayFlatten`.
*/
module.exports = flatten
module.exports.from = flattenFrom
module.exports.depth = flattenDepth
module.exports.fromDepth = flattenFromDepth
/**
* Flatten an array.
*
* @param {Array} array
* @return {Array}
*/
function flatten (array) {
if (!Array.isArray(array)) {
throw new TypeError('Expected value to be an array')
}
return flattenFrom(array)
}
/**
* Flatten an array-like structure.
*
* @param {Array} array
* @return {Array}
*/
function flattenFrom (array) {
return flattenDown(array, [])
}
/**
* Flatten an array-like structure with depth.
*
* @param {Array} array
* @param {number} depth
* @return {Array}
*/
function flattenDepth (array, depth) {
if (!Array.isArray(array)) {
throw new TypeError('Expected value to be an array')
}
return flattenFromDepth(array, depth)
}
/**
* Flatten an array-like structure with depth.
*
* @param {Array} array
* @param {number} depth
* @return {Array}
*/
function flattenFromDepth (array, depth) {
if (typeof depth !== 'number') {
throw new TypeError('Expected the depth to be a number')
}
return flattenDownDepth(array, [], depth)
}
/**
* Flatten an array indefinitely.
*
* @param {Array} array
* @param {Array} result
* @return {Array}
*/
function flattenDown (array, result) {
for (var i = 0; i < array.length; i++) {
var value = array[i]
if (Array.isArray(value)) {
flattenDown(value, result)
} else {
result.push(value)
}
}
return result
}
/**
* Flatten an array with depth.
*
* @param {Array} array
* @param {Array} result
* @param {number} depth
* @return {Array}
*/
function flattenDownDepth (array, result, depth) {
depth--
for (var i = 0; i < array.length; i++) {
var value = array[i]
if (depth > -1 && Array.isArray(value)) {
flattenDownDepth(value, result, depth)
} else {
result.push(value)
}
}
return result
}
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lunr = __webpack_require__(13);
var _lunr2 = _interopRequireDefault(_lunr);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = _lunr2.default;
module.exports = exports['default'];
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _regenerator = __webpack_require__(2);
var _regenerator2 = _interopRequireDefault(_regenerator);
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _axios = __webpack_require__(3);
var _axios2 = _interopRequireDefault(_axios);
var _lunr = __webpack_require__(34);
var _lunr2 = _interopRequireDefault(_lunr);
var _plugin = __webpack_require__(35);
var _util = __webpack_require__(10);
var util = _interopRequireWildcard(_util);
var _package = __webpack_require__(39);
var _arrayFlatten = __webpack_require__(11);
var _arrayFlatten2 = _interopRequireDefault(_arrayFlatten);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var documentStorage = {};
/**
* @typedef Plugin
* @memberOf LunrSearch
* @property {Function} plugin a lunr builder plugin
* @property {Function} fetch a function to fetch documents
* @property {Function} isSupported checks whether the plugin is supported in the current environment
*/
/**
* @typedef Result
* @memberOf LunrSearch
* @property {Object} document the document that was matched
* @property {Object} source describes the source of the document
* @property {string} source.type the type of the document source, examples are 'forum' or 'solution'
* @property {string} source.url the URL that the document was fetched from
* @property {lunr.Index~Result} result the lunr search result
*/
/**
* A class to handle building, importing, exporting, and searching a lunr index.
* It contains static and instance methods of each function so you can choose how to use it.
*
* @example <caption>Instance usage</caption>
* const builder = new lunr.Builder() // if you need to,
* builder.metadataWhitelist = ['tags'] // you can customize the builder that will be used internally
*
* const lunrSearch = new LunrSearch('myfreshdeskdomain', 'freshdeskusername', 'freshdeskpassword', {
* builder, // pass the custom builder if needed
* plugins: [myCustomBuilderPlugin],
* editDistance: 2 // in case your users can't type very well :)
* })
*
* lunrSearch.buildIndex().then(() => mySearchBar.addEventListener('input', () => lunrSeach.search(mySearchBar.value))
*
* @example <caption>Static usage</caption>
* const opts = {domain: 'freshdeskdomain', user: 'username', pass: 'password'}
* const builder = new lunr.Builder() // custom builder, etc.
* const indexPromise = LunrSearch.buildIndex({builder, ...opts}) // you can pass a custom builder into the static methods too
*
* indexPromise.then(() => mySearchBar.addEventListener('input', () => lunrSeach.search(mySearchBar.value))
*
* @param {string} domain the domain to use for all fetch requests
* @param {string} user the username to use for all fetch requests
* @param {string} pass the password to use for all fetch requests
* @param {object} [options={}]
* @param {lunr.Builder} [options.builder] a custom builder to use instead of creating a new instance
* @param {Plugin[]} [options.plugins] a list of plugins to use
* @param {number} [options.editDistance=1] a default edit distance to use in search queries
* @class LunrSearch
*/
var LunrSearch = function () {
function LunrSearch(domain, user, pass) {
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
_ref$builder = _ref.builder,
builder = _ref$builder === undefined ? new _lunr2.default.Builder() : _ref$builder,
_ref$plugins = _ref.plugins,
plugins = _ref$plugins === undefined ? [_plugin.freshdesk] : _ref$plugins,
_ref$editDistance = _ref.editDistance,
editDistance = _ref$editDistance === undefined ? 1 : _ref$editDistance;
_classCallCheck(this, LunrSearch);
/**
* The package version.
* @memberOf LunrSearch
* @member {string} VERSION
* @static
*/
this.constructor.VERSION = _package.version;
/**
* the fetched documents
* the keys are the document ID and the value is the document.
* useful for getting info about a search result.
*
* @memberOf LunrSearch
* @member {Object} docs
* @instance
*/
this.docs = {};
/**
* the domain to use for all fetch requests
*
* @member {string} domain
* @memberOf LunrSearch
* @instance
*/
this.domain = domain;
/**
* the username to use for all fetch requests
*
* @member {string} user
* @memberOf LunrSearch
* @instance
*/
this.user = user;
/**
* the password to use for all fetch requests
*
* @member {string} pass
* @memberOf LunrSearch
* @instance
*/
this.pass = pass;
/**
* a custom builder to use
*
* @member {lunr.Builder} builder
* @memberOf LunrSearch
* @instance
*/
this.builder = builder;
/**
* a list of plugins to use
*
* @member {Plugin[]} plugins
* @memberOf LunrSearch
* @instance
*/
this.plugins = plugins;
/**
* a default edit distance to use in search queries
*
* @member {number} editDistance
* @memberOf LunrSearch
* @default 0
* @instance
*/
this.editDistance = editDistance;
/**
* The built lunr index.
*
* @member {lunr.Index} index
* @memberOf LunrSearch
* @instance
*/
this.index = null;
}
/**
* Searches the index with the given query.
*
* @param {string} query the query to search with
* @param {Object} [options={}]
* @param {number} [options.editDistance] the edit distance to use for the search
* @return {Result[]} an array of search results
* @memberOf LunrSearch
* @instance
*/
_createClass(LunrSearch, [{
key: 'search',
value: function search(query) {
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
editDistance = _ref2.editDistance;
return query ? util.buildResults(this.index.search(query + '~' + (editDistance || this.editDistance)), this.docs) : [];
}
/**
* Gets and imports an index fram a URL.
*
* @async
* @param {string} url the URL of the endpoint
* @param {Object} [auth={}] authentication details for the API
* @param {string} [auth.user] the username for the API
* @param {string} [auth.pass] the password for the API
* @return {lunr.Index}
* @memberOf LunrSearch
* @instance
*/
}, {
key: 'getIndex',
value: function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(url) {
var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
user = _ref4.user,
pass = _ref4.pass;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return this.constructor.getIndex(url, { user: user, pass: pass });
case 2:
this.index = _context.sent;
return _context.abrupt('return', this.index);
case 4:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
function getIndex(_x4) {
return _ref3.apply(this, arguments);
}
return getIndex;
}()
/**
* Imports an exported lunr index and stores it.
*
* @param {string} json the index to import as a json string
* @return {void}
* @memberOf LunrSearch
* @instance
*/
}, {
key: 'importIndex',
value: function importIndex(json) {
this.index = this.constructor.importIndex(json);
}
/**
* Posts index to a URL.
* If the index exists locally, it will not be built. Call {@link LunrSearch#buildIndex} to build a fresh index.
* If the index does not already exist, it will be built asynchronously.
*
* @async
* @param {string} url the URL of the endpoint
* @param {Object} [auth={}] authentication details for the API
* @param {string} [auth.user] the username for the API
* @param {string} [auth.pass] the password for the API
* @return {axios.Response}
* @memberOf LunrSearch
* @instance
*/
}, {
key: 'postIndex',
value: function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2(url) {
var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
user = _ref6.user,
pass = _ref6.pass;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.t0 = this.constructor;
_context2.next = 3;
return this.exportIndex();
case 3:
_context2.t1 = _context2.sent;
_context2.t2 = url;
_context2.t3 = { user: user, pass: pass };
return _context2.abrupt('return', _context2.t0.postIndex.call(_context2.t0, _context2.t1, _context2.t2, _context2.t3));
case 7:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
function postIndex(_x6) {
return _ref5.apply(this, arguments);
}
return postIndex;
}()
/**
* Serializes and exports a lunr index.
* If the index exists locally, it will not be built. Call #buildIndex to build a fresh index.
* If the index does not already exist, it will be built asynchronously.
*
* @async
* @return {Promise<string>} the serialized index
* @memberOf LunrSearch
* @instance
*/
}, {
key: 'exportIndex',
value: function () {
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.t0 = JSON;
_context3.t1 = this.index;
if (_context3.t1) {
_context3.next = 6;
break;
}
_context3.next = 5;
return this.buildIndex();
case 5:
_context3.t1 = _context3.sent;
case 6:
_context3.t2 = _context3.t1;
return _context3.abrupt('return', _context3.t0.stringify.call(_context3.t0, _context3.t2));
case 8:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
function exportIndex() {
return _ref7.apply(this, arguments);
}
return exportIndex;
}()
/**
* Builds an index and stores it.
*
* @async
* @return {lunr.Index} the built index
* @memberOf LunrSearch
* @instance
*/
}, {
key: 'buildIndex',
value: function () {
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee4() {
var docs;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
docs = Object.values(this.docs);
_context4.t0 = this.constructor;
if (!(docs.length > 0)) {
_context4.next = 6;
break;
}
_context4.t1 = docs;
_context4.next = 9;
break;
case 6:
_context4.next = 8;
return this.fetch();
case 8:
_context4.t1 = _context4.sent;
case 9:
_context4.t2 = _context4.t1;
_context4.t3 = this.builder;
_context4.t4 = this.plugins;
_context4.t5 = {
docs: _context4.t2,
builder: _context4.t3,
plugins: _context4.t4
};
_context4.next = 15;
return _context4.t0.buildIndex.call(_context4.t0, _context4.t5);
case 15:
this.index = _context4.sent;
return _context4.abrupt('return', this.index);
case 17:
case 'end':
return _context4.stop();
}
}
}, _callee4, this);
}));
function buildIndex() {
return _ref8.apply(this, arguments);
}
return buildIndex;
}()
/**
* Fetches some documents that are ready to be indexed.
*
* @async
* @return {Object[]} the array of Objects to be indexed
* @memberOf LunrSearch
* @instance
*/
}, {
key: 'fetch',
value: function () {
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee5() {
var docs;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return this.constructor.fetch({
domain: this.domain,
user: this.user,
pass: this.pass,
plugins: this.plugins
});
case 2:
docs = _context5.sent;
this.docs = documentStorage;
return _context5.abrupt('return', docs);
case 5:
case 'end':
return _context5.stop();
}
}
}, _callee5, this);
}));
function fetch() {
return _ref9.apply(this, arguments);
}
return fetch;
}()
/**
* Searches the given index with the given query.
* If query is falsey no search is performed.
*
* @param {string} query the query to search with
* @param {lunr.Index} index an index to use for the search
* @param {Object} [options={}]
* @param {number} [options.editDistance=1] the edit distance to use for the search
* @return {Result[]} an array of search results
* @memberOf LunrSearch
* @static
*/
}], [{
key: 'search',
value: function search(query, index, _ref10) {
var _ref10$editDistance = _ref10.editDistance,
editDistance = _ref10$editDistance === undefined ? 1 : _ref10$editDistance;
return query ? util.buildResults(index.search(query + '~' + editDistance), documentStorage) : [];
}
/**
* Gets and imports an index fram a URL.
*
* @async
* @param {string} url the URL of the endpoint
* @param {Object} [auth={}] authentication details for the API
* @param {string} [auth.user] the username for the API
* @param {string} [auth.pass] the password for the API
* @return {lunr.Index}
* @memberOf LunrSearch
* @static
*/
}, {
key: 'getIndex',
value: function () {
var _ref11 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee6(url) {
var _this = this;
var _ref12 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
user = _ref12.user,
pass = _ref12.pass;
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
return _context6.abrupt('return', _axios2.default.get(url, { auth: { username: user, password: pass } }).then(function (_ref13) {
var data = _ref13.data;
return _this.importIndex(data);
}));
case 1:
case 'end':
return _context6.stop();
}
}
}, _callee6, this);
}));
function getIndex(_x8) {
return _ref11.apply(this, arguments);
}
return getIndex;
}()
/**
* Imports an exported lunr index and returns it.
*
* @param {string} json the stringified index to import
* @return {lunr.Index}
* @memberOf LunrSearch
* @static
*/
}, {
key: 'importIndex',
value: function importIndex(json) {
return _lunr2.default.Index.load(JSON.parse(json));
}
/**
* Posts an exported index to a URL.
*
* @async
* @param {lunr.Index} index the index to be posted
* @param {string} url the URL of the endpoint
* @param {Object} [auth={}] authentication details for the API
* @param {string} [auth.user] the username for the API
* @param {string} [auth.pass] the password for the API
* @return {axios.Response}
* @memberOf LunrSearch
* @static
*/
}, {
key: 'postIndex',
value: function () {
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee7(index, url) {
var _ref15 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
user = _ref15.user,
pass = _ref15.pass;
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
return _context7.abrupt('return', _axios2.default.post(url, index, { auth: { username: user, password: pass } }));
case 1:
case 'end':
return _context7.stop();
}
}
}, _callee7, this);
}));
function postIndex(_x10, _x11) {
return _ref14.apply(this, arguments);
}
return postIndex;
}()
/**
* Builds then serializes and exports a lunr index.
*
* @async
* @param {Object} [options={}]
* @param {string} [options.domain] the domain of the API to make the request to
* @param {string} [options.user] the username for the API
* @param {string} [options.pass] the password for the API
* @param {lunr.Builder} [options.builder] the builder to use for building the index
* @param {Function[]} [options.plugins] a list of plugins for the builder to use
* @return {string} the serialized index
* @memberOf LunrSearch
* @static
*/
}, {
key: 'exportIndex',
value: function () {
var _ref17 = _asyncToGe