UNPKG

@enonic/js-utils

Version:
183 lines (182 loc) 7.64 kB
"use strict"; function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = function(target, all) { for(var name in all)__defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = function(to, from, except, desc) { if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") { var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; try { var _loop = function() { var key = _step.value; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: function() { return from[key]; }, enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); }; for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop(); } catch (err) { _didIteratorError = true; _iteratorError = err; } finally{ try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally{ if (_didIteratorError) { throw _iteratorError; } } } } return to; }; var __toCommonJS = function(mod) { return __copyProps(__defProp({}, "__esModule", { value: true }), mod); }; // storage/indexing/indexTemplateToConfig.ts var indexTemplateToConfig_exports = {}; __export(indexTemplateToConfig_exports, { indexTemplateToConfig: function() { return indexTemplateToConfig; } }); module.exports = __toCommonJS(indexTemplateToConfig_exports); // value/isFunction.ts function isFunction(value) { return Object.prototype.toString.call(value).slice(8, -1) === "Function"; } // value/isInt.ts function isInt(value) { return typeof value === "number" && isFinite(value) && // TODO Is isFinite() available in Enonic XP? Math.floor(value) === value; } // value/isInteger.ts var isInteger = "isInteger" in Number && isFunction(Number.isInteger) ? Number.isInteger : isInt; // value/isObject.ts var isObject = function(value) { return Object.prototype.toString.call(value).slice(8, -1) === "Object"; }; // storage/indexing/constants.ts var INDEX_CONFIG_ENABLED = "enabled"; var INDEX_CONFIG_DECIDE_BY_TYPE = "decideByType"; var INDEX_CONFIG_FULLTEXT = "fulltext"; var INDEX_CONFIG_INCLUDE_IN_ALL_TEXT = "includeInAllText"; var INDEX_CONFIG_INDEX_VALUE_PROCESSORS = "indexValueProcessors"; var INDEX_CONFIG_LANGUAGES = "languages"; var INDEX_CONFIG_N_GRAM = "nGram"; var INDEX_CONFIG_PATH = "path"; var INDEX_CONFIG_TEMPLATE_NONE = "none"; var INDEX_CONFIG_TEMPLATE_BY_TYPE = "byType"; var INDEX_CONFIG_TEMPLATE_FULLTEXT = "fulltext"; var INDEX_CONFIG_TEMPLATE_PATH = "path"; var INDEX_CONFIG_TEMPLATE_MINIMAL = "minimal"; // storage/indexing/indexTemplateToConfig.ts function indexTemplateToConfig(param) { var template = param.template, indexValueProcessors = param.indexValueProcessors, // = [], languages = param.languages; if (isObject(template)) { var configObject = JSON.parse(JSON.stringify(template)); if (indexValueProcessors) { configObject.indexValueProcessors = indexValueProcessors; } if (languages) { configObject.languages = languages; } return configObject; } if (template === INDEX_CONFIG_TEMPLATE_NONE) { var _obj; var rv = (_obj = {}, _define_property(_obj, INDEX_CONFIG_DECIDE_BY_TYPE, false), _define_property(_obj, INDEX_CONFIG_ENABLED, false), _define_property(_obj, INDEX_CONFIG_FULLTEXT, false), _define_property(_obj, INDEX_CONFIG_INCLUDE_IN_ALL_TEXT, false), _obj); if (indexValueProcessors) { rv[INDEX_CONFIG_INDEX_VALUE_PROCESSORS] = indexValueProcessors; } if (languages) { rv[INDEX_CONFIG_LANGUAGES] = languages; } rv[INDEX_CONFIG_N_GRAM] = false; rv[INDEX_CONFIG_PATH] = false; return rv; } if (template === INDEX_CONFIG_TEMPLATE_BY_TYPE) { var _obj1; var rv1 = (_obj1 = {}, _define_property(_obj1, INDEX_CONFIG_DECIDE_BY_TYPE, true), _define_property(_obj1, INDEX_CONFIG_ENABLED, true), _define_property(_obj1, INDEX_CONFIG_FULLTEXT, false), _define_property(_obj1, INDEX_CONFIG_INCLUDE_IN_ALL_TEXT, false), _obj1); if (indexValueProcessors) { rv1[INDEX_CONFIG_INDEX_VALUE_PROCESSORS] = indexValueProcessors; } if (languages) { rv1[INDEX_CONFIG_LANGUAGES] = languages; } rv1[INDEX_CONFIG_N_GRAM] = false; rv1[INDEX_CONFIG_PATH] = false; return rv1; } if (template === INDEX_CONFIG_TEMPLATE_FULLTEXT) { var _obj2; var rv2 = (_obj2 = {}, _define_property(_obj2, INDEX_CONFIG_DECIDE_BY_TYPE, false), _define_property(_obj2, INDEX_CONFIG_ENABLED, true), _define_property(_obj2, INDEX_CONFIG_FULLTEXT, true), _define_property(_obj2, INDEX_CONFIG_INCLUDE_IN_ALL_TEXT, true), _obj2); if (indexValueProcessors) { rv2[INDEX_CONFIG_INDEX_VALUE_PROCESSORS] = indexValueProcessors; } if (languages) { rv2[INDEX_CONFIG_LANGUAGES] = languages; } rv2[INDEX_CONFIG_N_GRAM] = true; rv2[INDEX_CONFIG_PATH] = false; return rv2; } if (template === INDEX_CONFIG_TEMPLATE_PATH) { var _obj3; var rv3 = (_obj3 = {}, _define_property(_obj3, INDEX_CONFIG_DECIDE_BY_TYPE, false), _define_property(_obj3, INDEX_CONFIG_ENABLED, true), _define_property(_obj3, INDEX_CONFIG_FULLTEXT, false), _define_property(_obj3, INDEX_CONFIG_INCLUDE_IN_ALL_TEXT, false), _obj3); if (indexValueProcessors) { rv3[INDEX_CONFIG_INDEX_VALUE_PROCESSORS] = indexValueProcessors; } if (languages) { rv3[INDEX_CONFIG_LANGUAGES] = languages; } rv3[INDEX_CONFIG_N_GRAM] = false; rv3[INDEX_CONFIG_PATH] = true; return rv3; } if (template === INDEX_CONFIG_TEMPLATE_MINIMAL) { var _obj4; var rv4 = (_obj4 = {}, _define_property(_obj4, INDEX_CONFIG_DECIDE_BY_TYPE, false), _define_property(_obj4, INDEX_CONFIG_ENABLED, true), _define_property(_obj4, INDEX_CONFIG_FULLTEXT, false), _define_property(_obj4, INDEX_CONFIG_INCLUDE_IN_ALL_TEXT, false), _obj4); if (indexValueProcessors) { rv4[INDEX_CONFIG_INDEX_VALUE_PROCESSORS] = indexValueProcessors; } if (languages) { rv4[INDEX_CONFIG_LANGUAGES] = languages; } rv4[INDEX_CONFIG_N_GRAM] = false; rv4[INDEX_CONFIG_PATH] = false; return rv4; } throw new Error("Unknown indexing template:".concat(template, "!")); }