UNPKG

fly-json-odm

Version:

An Object Document Mapper to handle JSON on the fly for NodeJS or Browser

1 lines 21.4 kB
"use strict";function _defineProperty(t,e,r){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,_toPropertyKey(i.key),i)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function _toPropertyKey(t){t=_toPrimitive(t,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(t,e){if("object"!==_typeof(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!==_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e)}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function _createSuper(r){var i=_isNativeReflectConstruct();return function(){var t,e=_getPrototypeOf(r);return _possibleConstructorReturn(this,i?(t=_getPrototypeOf(this).constructor,Reflect.construct(e,arguments,t)):e.apply(this,arguments))}}function _possibleConstructorReturn(t,e){if(e&&("object"===_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t)}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}!function(t){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).FlyJson=t()}(function(){return function i(n,o,s){function a(e,t){if(!o[e]){if(!n[e]){var r="function"==typeof require&&require;if(!t&&r)return r(e,!0);if(u)return u(e,!0);throw(t=new Error("Cannot find module '"+e+"'")).code="MODULE_NOT_FOUND",t}r=o[e]={exports:{}},n[e][0].call(r.exports,function(t){return a(n[e][1][t]||t)},r,r.exports,i,n,o,s)}return o[e].exports}for(var u="function"==typeof require&&require,t=0;t<s.length;t++)a(s[t]);return a}({1:[function(t,e,r){var i=t("./helper"),f=t("./operator"),t=function(){_inherits(n,i);var e=_createSuper(n);function n(r){var i;if(_classCallCheck(this,n),(i=e.call(this)).data1=[],i.data2=[],i.query=[],i.result=[],i.isObject(r))for(var t in r)!function(e){r[e]&&"function"==typeof r[e]&&(i[e]=function(t){return r[e](t),_assertThisInitialized(i)})}(t);return i}return _createClass(n,[{key:"_sortBy",value:function(e,r,i){var n=i?function(t){return i(t[e])}:function(t){return t[e]};return r=r?-1:1,function(t,e){return t=n(t),e=n(e),r*((e<t)-(t<e))}}},{key:"_findDistinct",value:function(n,e){for(var o=this,s=!1,t=0;t<n.length;t++)!function(r){var t=Object.keys(e).length,i=0;o.foreach(e,function(t,e){n[r][e]===t&&i++}),t===i&&(s=!0)}(t);return s}},{key:"setMode",value:function(t){return this.mode=t.toString().toLowerCase(),this}},{key:"set",value:function(t){if(this.fastCheckArrayObject(t))return"shallow"===this.mode?this.data1=this.shallowClone(t):this.data1=this.deepClone(t),this;throw new Error("Set data must be an array contains object.")}},{key:"list",value:function(){return this.data1}},{key:"insert",value:function(t){if(!this.isObject(t)||this.isEmptyObject(t))throw new Error("New value must be an object and not empty");return this.data1.push(t),this}},{key:"insertMany",value:function(t){if(!this.isArray(t))throw new Error("Data must be an array object");for(var e=t.length,r=0;r<e;r++){if(!this.isObject(t[r])||this.isEmptyObject(t[r]))throw new Error("New value must be an object and not empty");this.data1.push(t[r])}return this}},{key:"update",value:function(t,e,r){if(this.isEmpty(t)||this.isEmpty(e))throw new Error("Key and Value must be defined and value must be unique");if(!this.isObject(r)||this.isEmptyObject(r))throw new Error("New value must be an object and not empty");for(var i=this.data1.length,n=0;n<i;n++)if(this.data1[n][t]===e){this.data1.splice(n,1),this.data1.push(Object.assign(_defineProperty({},t,e),r));break}return this}},{key:"updateMany",value:function(t,e){if(this.isEmpty(t)||!this.isString(t))throw new Error("Key and Value must be defined and value must be unique");if(this.isEmptyArray(e)||!this.fastCheckArrayObject(e))throw new Error("Data to update must be an array object and not empty");for(var r=this.data1.length,i=e.length,n=[],o=0;o<r;o++){for(var s=!1,a=0;a<i;a++)this.data1[o][t]===e[a][t]&&(s=!0,n.push(e[a]));!1===s&&n.push(this.data1[o])}return this.data1=n,this}},{key:"modify",value:function(t,e,r){if(this.isEmpty(t)||this.isEmpty(e))throw new Error("Key and Value must be defined and value must be unique");if(!this.isObject(r)||this.isEmptyObject(r))throw new Error("New value must be an object and not empty");for(var i,n=this.data1.length,o=0;o<n;o++)if(this.data1[o][t]===e){i=this.data1[o],this.data1.splice(o,1),this.data1.push(Object.assign(_defineProperty({},t,e),i,r));break}return this}},{key:"modifyMany",value:function(t,e){if(this.isEmpty(t)||!this.isString(t))throw new Error("Key must be defined");if(this.isEmptyArray(e)||!this.fastCheckArrayObject(e))throw new Error("Data to modify must be an array object and not empty");if("shallow"===this.mode)throw new Error("Shallow mode is not allowed for modifyMany!");for(var r,i=this.data1.length,n=e.length,o=[],s=0;s<i;s++){for(var a=!1,u=0;u<n;u++)this.data1[s][t]===e[u][t]&&(a=!0,r=this.data1[s],o.push(Object.assign(r,e[u])));!1===a&&o.push(this.data1[s])}return this.data1=o,this}},{key:"delete",value:function(t,e){if(this.isEmpty(t)||this.isEmpty(e))throw new Error("Key and Value must be defined also remember that Value must be unique.");for(var r=this.data1.length,i=0;i<r;i++)if(this.data1[i][t]===e){this.data1.splice(i,1);break}return this}},{key:"deleteMany",value:function(t,e){if(this.isEmpty(t)||this.isEmptyArray(e))throw new Error("Key and Data array of key value must be defined.");for(var r=this.data1.length,i=e.length,n=[],o=!1,s=0;s<r;s++){for(var o=!1,a=0;a<i;a++)this.data1[s][t]===e[a]&&(o=!0);!1===o&&n.push(this.data1[s])}return this.data1=n,this}},{key:"select",value:function(t){if(!this.isEmpty(t)&&this.isArray(t)&&!this.isEmptyArray(t)){for(var e=[],r=this.data1.length,i=t.length,n=0;n<r;n++){for(var o={},s=0;s<i;s++)void 0!==this.data1[n][t[s]]&&(o[t[s]]=this.data1[n][t[s]]);e.push(o)}this.data1=e}return this}},{key:"where",value:function(){var t,r,i,n,o,s,a,e,u=[];return!this.isEmpty(arguments.length<=0?void 0:arguments[0])&&this.isString(arguments.length<=0?void 0:arguments[0])&&void 0!==(arguments.length<=1?void 0:arguments[1])&&(r=!0,2<arguments.length?(i=arguments.length<=1?void 0:arguments[1],e=arguments.length<=0?void 0:arguments[0],t=arguments.length<=2?void 0:arguments[2],this.isEmpty(arguments.length<=3?void 0:arguments[3])||(r=arguments.length<=3?void 0:arguments[3])):(i="===",e=arguments.length<=0?void 0:arguments[0],t=arguments.length<=1?void 0:arguments[1],r=!0),i=i.toString().toLowerCase(),n=_defineProperty({},e,t),e=(a=this).data1.filter(function(e){return Object.keys(n).every(function(t){switch(o=e[t],s=n[t],!1===r&&"regex"!==i&&(a.isObject(e[t])||(o=e[t]&&e[t].toString().toLowerCase()),s=n[t].toString().toLowerCase()),i){case"=":return f.unstrict(i,o,s);case"!==":return o!==s;case"==":case"!=":return f.unstrict(i,o,s);case">":return s<o;case">=":return s<=o;case"<":return o<s;case"<=":return o<=s;case"in":return a.isString(o)?-1!==o.indexOf(s):(u=[],o&&a.foreach(o,function(t){r?t===s&&u.push(t):(t=a.isString(t)?t.toLowerCase():t)===s&&u.push(t)}),0<u.length);case"in like":return a.isString(o)?-1!==o.indexOf(s):(u=[],o&&a.foreach(o,function(t){r?a.isString(t)&&-1!==t.toString().indexOf(s)&&u.push(t):a.isString(t)&&-1!==(t=t.toLowerCase()).indexOf(s)&&u.push(t)}),0<u.length);case"not in":return a.isString(o)?-1===o.indexOf(s):(u=[],o&&o.length?(a.foreach(o,function(t){t!==s&&u.push(t)}),u.length===o.length):!!a.isObject(o)&&(a.foreach(o,function(t){r?t!==s&&u.push(t):(t=a.isString(t)?t.toLowerCase():t)!==s&&u.push(t)}),u.length===Object.keys(o).length));case"not in like":return a.isString(o)?-1===o.indexOf(s):(u=[],o&&o.length?(a.foreach(o,function(t){null==t||a.isString(t)||(t=t.toString()),a.isString(t)&&-1!==t.indexOf(s)||u.push(t)}),u.length===o.length):!!a.isObject(o)&&(a.foreach(o,function(t){r?(null==t||a.isString(t)||(t=t.toString()),a.isString(t)&&-1!==t.indexOf(s)||u.push(t)):(null==t||a.isString(t)||(t=t.toString()),a.isString(t)&&-1!==(t=t.toLowerCase()).indexOf(s)||u.push(t))}),u.length===Object.keys(o).length));case"not":return o!==s;case"like":return-1!==o.indexOf(s);case"not like":return-1===o.indexOf(s);case"regex":return s.test(o);case"func":case"function":return s(o);default:return o===s}})}),"query"===this.scope?this.result=e:this.data1=e),this}},{key:"begin",value:function(){return this.scope="query",this}},{key:"or",value:function(){if("query"===this.scope)for(var t=this.result.length,e=0;e<t;e++)this.query.push(this.result[e]);return this}},{key:"end",value:function(){if("query"===this.scope){for(var t=this.result.length,e=0;e<t;e++)this.query.push(this.result[e]);this.data1=this.query,this.query=[],this.result=[],this.scope=""}return this}},{key:"distinct",value:function(t){if(!this.isEmpty(t=void 0===t?"":t)&&!this.isString(t)||this.isArray(t)||this.isObject(t))throw new Error("Field name must be string.");var e=this.data1,r=[],i=[],n=e.length;if(!this.isEmpty(t)&&this.isString(t))for(var o=0;o<n;o++)void 0===e[o][t]||r[e[o][t]]||(i.push(e[o]),r[e[o][t]]=1);else for(var s=0;s<n;s++)!1===this._findDistinct(r,e[s])&&(i.push(e[s]),r.push(e[s]));return this.data1=i,this}},{key:"fuzzySearch",value:function(t,e){var r=2<arguments.length&&void 0!==arguments[2]&&arguments[2],i=3<arguments.length&&void 0!==arguments[3]&&arguments[3];if(null==t)throw new Error("Query is required.");if(null==e||this.isEmptyArray(e))throw new Error("Field keys is required.");return this.data1=this.fuzzy(this.data1,t,e,r,i),this}},{key:"clean",value:function(){return this.data1=[],this.data2=[],this.query=[],this.result=[],this.metadata={},this.scope="",this.mode="",this.name="",this}},{key:"join",value:function(t,e){if(this.isEmpty(t)||!this.isString(t))throw new Error("Name is required and it must be string.");if(this.fastCheckArrayObject(e))return"shallow"===this.mode?this.data2=this.shallowClone(e):this.data2=this.deepClone(e),this.name=t,this.scope="join",this;throw new Error("Data must be an array object.")}},{key:"merge",value:function(e,r){if("join"!==this.scope)throw new Error("You should join first before doing merge.");if(this.isEmpty(e)||!this.isString(e))throw new Error("Unique identifier key for table 1 is required.");if(this.isEmpty(r)||!this.isString(r))throw new Error("Unique identifier key for table 2 is required.");var i=this.data2.reduce(function(t,e){return t[e[r]]=e,t},{});return this.scope="",this.data1=this.data1.map(function(t){return Object.assign(t,i[t[e]])}),this}},{key:"on",value:function(s,a,u,f){var h=this;if(u=void 0===u||u,f=void 0===f||f,"join"!==h.scope)throw new Error("You should join first before doing join on.");if(this.isEmpty(s)||!this.isString(s))throw new Error("Unique identifier key for table 1 is required.");if(this.isEmpty(a)||!this.isString(a))throw new Error("Unique identifier key for table 2 is required.");var c=h.data2.reduce(function(t,e){return t[e[a]]=e,t},{}),l=[];return h.data1.map(function(r,t){for(var i={},n=Object.keys(h.data1[t]),e=n.length,o=0;o<e;o++)!function(e){n[e]===s?h.name===n[e]?i[n[e]]=u?c[h.data1[t][n[e]]]:h.data2.filter(function(t){return!f&&h.isString(t[a])&&h.isString(r[n[e]])?t[a].toLowerCase()===r[n[e]].toLowerCase():t[a]===r[n[e]]}):(i[h.name]=u?c[h.data1[t][n[e]]]:h.data2.filter(function(t){return!f&&h.isString(t[a])&&h.isString(r[n[e]])?t[a].toLowerCase()===r[n[e]].toLowerCase():t[a]===r[n[e]]}),i[n[e]]=r[n[e]]):i[n[e]]=r[n[e]]}(o);return l.push(i)}),h.scope="",h.data1=l,this}},{key:"orderBy",value:function(t,e,r){return e=void 0!==e&&e,!this.isEmpty(t)&&this.isString(t)&&this.isBoolean(e)&&this.data1.sort(this._sortBy(t,e,r)),this}},{key:"groupDetail",value:function(i,t){if(t=void 0===t?"":t,this.isEmpty(i)||!this.isString(i))throw new Error("name is required and must be string.");var e,r;if(this.isString(t))return e=this.data1.reduce(function(t,e){var r=e[i];return t[r]=(t[r]||[]).concat(e),t},{}),(r=[]).push(_defineProperty({},t||i,e)),this.data1=r,this;throw new Error("group name must be string.")}},{key:"groupBy",value:function(n,o){if(o=void 0===o?[]:o,this.isEmpty(n)||!this.isString(n))throw new Error("name is required and must be string.");var s,t;if(this.isArray(o))return s=o.length,t=this.data1.reduce(function(t,e){if(e.item_count=1,e[n]in t){for(var r=0;r<s;r++)t[e[n]][o[r]]+=e[o[r]];t[e[n]].item_count+=1}else t.__array.push(t[e[n]]=e);for(var i=0;i<s;i++)t[e[n]]["average_"+o[i]]=t[e[n]][o[i]]/t[e[n]].item_count;return t},{__array:[]}),this.data1=t.__array,this;throw new Error("field name for sum must be array.")}},{key:"skip",value:function(t){return!this.isEmpty(t)&&this.isInteger(t)&&(this.data1=this.data1.slice(t)),this}},{key:"take",value:function(t){return this.isEmpty(t)||(t=parseInt(t),this.isInteger(t)&&this.data1.length>t&&(this.data1.length=t)),this}},{key:"paginate",value:function(t,e){var r;return this.isEmpty(t)||this.isEmpty(e)||(t=parseInt(t),e=parseInt(e),this.isInteger(t)&&this.isInteger(e)&&(r=this.data1.length,this.data1=this.data1.slice(--t*e,(t+1)*e),this.metadata={page:t+1,page_size:e,total_page:Math.ceil(r/e),total_records:r})),this}},{key:"promisify",value:function(r){var i=this;return new Promise(function(t,e){try{t(r.call(i,i))}catch(t){e(t)}})}},{key:"exec",value:function(){return this.mode="",this.data1}}]),n}();e.exports=t},{"./helper":2,"./operator":3}],2:[function(t,e,r){var i=function(){function t(){_classCallCheck(this,t)}return _createClass(t,[{key:"isString",value:function(t){return"string"==typeof t||t instanceof String}},{key:"isInteger",value:function(t){return Number.isInteger(t)}},{key:"isBoolean",value:function(t){return"boolean"==typeof t||"object"===_typeof(t)&&null!==t&&"boolean"==typeof t.valueOf()}},{key:"isArray",value:function(t){return void 0!==t&&""!==t&&t&&""!==t&&"object"===_typeof(t)&&t.constructor===Array}},{key:"fastCheckArrayObject",value:function(t){if(!this.isArray(t))return!1;var e=t.length;if(0<e){var r=Math.floor(e/2),e=e-1,i=Math.floor(r/2),n=Math.floor((r+e)/2);if("object"!==_typeof(t[0]))return!1;if(0<i&&"object"!==_typeof(t[i]))return!1;if(i<r&&"object"!==_typeof(t[r]))return!1;if(r<n&&"object"!==_typeof(t[n]))return!1;if("object"!==_typeof(t[e]))return!1}return!0}},{key:"isObject",value:function(t){return void 0!==t&&""!==t&&t&&"object"===_typeof(t)&&t.constructor===Object}},{key:"isEmpty",value:function(t){return null==t||""===t}},{key:"isEmptyArray",value:function(t){return null==t||0===t.length}},{key:"isEmptyObject",value:function(t){return null==t||0===Object.keys(t).length&&t.constructor===Object}},{key:"foreach",value:function(e,t){if(this.isObject(e))for(var r=Object.keys(e),i=Object.keys(e).map(function(t){return e[t]}),n=0,o=r.length;n<o;n++)t(i[n],r[n]);else{if(!Array.isArray(e))throw new Error("Failed to iteration. Data is not an array or object.");for(var s=0,a=e.length;s<a;s++)t(e[s],s)}}},{key:"blockingTest",value:function(t){t=void 0===t?1e3:t;for(var e=Date.now(),r=e+t;Date.now()<r;);return e}},{key:"safeStringify",value:function(t,e){var r=[],t=JSON.stringify(t,function(t,e){if(!(t&&0<t.length)||"$"!==t.charAt(0)&&"_"!==t.charAt(0)){if("object"===_typeof(e)&&null!==e){if(-1!==r.indexOf(e))return;r.push(e)}return e}},e),r=null;return t}},{key:"shallowClone",value:function(t){return[].concat(t)}},{key:"deepClone",value:function(t){if("object"!==_typeof(t)||!t)return t;if("[object Array]"===Object.prototype.toString.apply(t))for(var e=[],r=t.length,i=0;i<r;i++)e[i]=this.deepClone(t[i]);else for(i in e={},t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=this.deepClone(t[i]));return e}},{key:"jsonTransform",value:function(i,n){var o=new t;return{defaultOrNull:function(t){return t&&n.defaults?n.defaults[t]:null},getValue:function(t,e,r){if(void 0!==t){if(null==e||""===e)return t;for(var i,n=t,o=0,s=(i=e.split(".")).length;o<s;o++){if(!(void 0!==n&&i[o]in n))return this.defaultOrNull(r);n=n[i[o]]}return n}},setValue:function(t,e,r){if(void 0!==t&&""!==e&&void 0!==e&&null!=e)for(var i=e.split("."),n=t,o=0,s=i.length;o<s;o++){if(o===i.length-1)return void(n[i[o]]=r);if(!(i[o]in n))return;n=n[i[o]]}},getList:function(){return this.getValue(i,n.list)},make:function(t){var e=this.getValue(i,n.list),r=[];return o.isEmptyObject(e)||(e=this.getList(),r=n.item?e.map(this.iterator.bind(this,n.item)):e,r=this.operate.bind(this,r)(t),r=this.each(r,t),r=this.removeAll(r)),r},removeAll:function(t){return Array.isArray(n.remove)&&o.foreach(t,this.remove),t},remove:function(t){for(var e=0,r=n.remove.length;e<r;e++)delete t[n.remove[e]];return t},operate:function(t,i){return n.operate&&o.foreach(n.operate,function(r){t=t.map(function(t){var e="string"==typeof r.run?new Function("return "+r.run)():r.run;return this.setValue(t,r.on,e(this.getValue(t,r.on),i)),t}.bind(this))}.bind(this)),t},each:function(t,i){return n.each&&t.forEach(function(t,e,r){return n.each(t,e,r,i)}),t},iterator:function(t,i){var n={};return"string"==typeof t?this.getValue(i,t):(o.foreach(t,function(t,e){var r;"string"==typeof t&&0<t.length?n[e]=this.getValue(i,t,e):Array.isArray(t)?(r=t.map(function(t,e){return this.iterator(e,t)}.bind(this,i)),n[e]=r):"object"===_typeof(t)?(r=this.iterator.bind(this,t,i),n[e]=r()):n[e]=""}.bind(this)),n)}}}},{key:"getDescendantProperty",value:function(t,e){var r,i,n,o,s,a,u=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[];if(e){if(-1===(n=e.indexOf("."))?r=e:(r=e.slice(0,n),i=e.slice(n+1)),null!=(o=t[r]))if(i||"string"!=typeof o&&"number"!=typeof o)if("[object Array]"===Object.prototype.toString.call(o))for(s=0,a=o.length;s<a;s++)this.getDescendantProperty(o[s],i,u);else i&&this.getDescendantProperty(o,i,u);else u.push(o)}else u.push(t);return u}},{key:"fuzzy",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[],i=3<arguments.length&&void 0!==arguments[3]&&arguments[3],n=4<arguments.length&&void 0!==arguments[4]&&arguments[4];if(""===e)return t;for(var o=[],s=0;s<t.length;s++){var a=t[s];if(0===r.length){var u=this._fuzzyIsMatch(a,e,i);u&&o.push({item:a,score:u})}else for(var f=0;f<r.length;f++){for(var h=this.getDescendantProperty(a,r[f]),c=!1,l=0;l<h.length;l++){var y=this._fuzzyIsMatch(h[l],e,i);if(y){c=!0,o.push({item:a,score:y});break}}if(c)break}}return n&&o.sort(function(t,e){return t.score-e.score}),o.map(function(t){return t.item})}},{key:"_fuzzyIsMatch",value:function(t,e,r){t=String(t),e=String(e),r||(t=t.toLocaleLowerCase(),e=e.toLocaleLowerCase());r=this._fuzzyNearestIndexesFor(t,e);if(!r)return!1;if(t===e)return 1;for(var i=[0],n=0;n<t.length;n++)" "===t[n]&&i.push(n+1);return r.reduce(function(t,e){return i.includes(e)&&t},!0)?2+r.reduce(function(t,e,r){return t+i.indexOf(e)},0):1<r.length?r[r.length-1]-r[0]+3:3+r[0]}},{key:"_fuzzyNearestIndexesFor",value:function(o,t){var s=t.split(""),a=[];return this._fuzzyIndexesOfFirstLetter(o,t).forEach(function(t,e){var r=t+1;a[e]=[t];for(var i=1;i<s.length;i++){var n=s[i];if(-1===(r=o.indexOf(n,r))){a[e]=!1;break}a[e].push(r),r++}}),!!(a=a.filter(function(t){return!1!==t})).length&&a.sort(function(t,e){return 1===t.length?t[0]-e[0]:(t=t[t.length-1]-t[0])-(e=e[e.length-1]-e[0])})[0]}},{key:"_fuzzyIndexesOfFirstLetter",value:function(t,e){var r=e[0];return t.split("").map(function(t,e){return t===r&&e}).filter(function(t){return!1!==t})}}]),t}();e.exports=i},{}],3:[function(t,e,r){e.exports={unstrict:function(t,e,r){switch(t){case"=":case"==":return e==r;case"!=":return e!=r;default:throw new Error("Comparisons operator is not available!")}}}},{}]},{},[1])(1)});