New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dadata-js

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dadata-js - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

10

dist/cjs.js

@@ -30,3 +30,3 @@ 'use strict';

if (source) {
this.data = new Proxy(source, {});
this.data = source;
}

@@ -39,3 +39,3 @@ }

setSource(source) {
this.data = new Proxy(source, {});
this.data = source;
this.model.setProxy(this.name);

@@ -114,3 +114,3 @@ }

let proxy_name = `${DEFAULTS.CONTAINER_PROXY_PREFIX}${container_name}`;
this[proxy_name] = new Proxy(original, {});
this[proxy_name] = original;
}

@@ -243,5 +243,3 @@ else {

}
else {
return name;
}
return name;
}

@@ -248,0 +246,0 @@ /**

@@ -28,3 +28,3 @@ function getQueryString(params) {

if (source) {
this.data = new Proxy(source, {});
this.data = source;
}

@@ -37,3 +37,3 @@ }

setSource(source) {
this.data = new Proxy(source, {});
this.data = source;
this.model.setProxy(this.name);

@@ -112,3 +112,3 @@ }

let proxy_name = `${DEFAULTS.CONTAINER_PROXY_PREFIX}${container_name}`;
this[proxy_name] = new Proxy(original, {});
this[proxy_name] = original;
}

@@ -241,5 +241,3 @@ else {

}
else {
return name;
}
return name;
}

@@ -246,0 +244,0 @@ /**

@@ -28,3 +28,3 @@ function getQueryString(params) {

if (source) {
this.data = new Proxy(source, {});
this.data = source;
}

@@ -37,3 +37,3 @@ }

setSource(source) {
this.data = new Proxy(source, {});
this.data = source;
this.model.setProxy(this.name);

@@ -112,3 +112,3 @@ }

let proxy_name = `${DEFAULTS.CONTAINER_PROXY_PREFIX}${container_name}`;
this[proxy_name] = new Proxy(original, {});
this[proxy_name] = original;
}

@@ -241,5 +241,3 @@ else {

}
else {
return name;
}
return name;
}

@@ -246,0 +244,0 @@ /**

2

dist/iife.js

@@ -1,1 +0,1 @@

var VueSimpleSuggest=function(){"use strict";function e(e,t){return t?t.split(".").reduce((e,t)=>"object"==typeof e?e[t]:e,e):e}class t{constructor(e,t,r,n){this.data={},this.fields={},this.model=e,this.name=t,this.fields=r,n&&(this.data=new Proxy(n,{}))}setSource(e){this.data=new Proxy(e,{}),this.model.setProxy(this.name)}}var r;!function(e){e.IS_JSON_RESPONSE=!0,e.QUERY_METHOD="GET",e.CONTAINER_PROXY_PREFIX="$"}(r||(r={}));class n{constructor(e=null){this.processors={},this.modifiers={},this.described_containers={},this.containers={},this.addContainer=function(){if(arguments.length>=2)var e=arguments[0],r=arguments[1],n=arguments[2];else{const t=arguments[0];e=t.name,r=t.fields,n=t.source}let s=this.getExtendedFields(e),i=e;s&&(r=Object.assign({},r,s.extended),i=s.name);let o=new t(this,i,r,n);return this.containers[i]=o,this.setProxy(i),this},this.addContainers=(e=>{Array.isArray(e)&&e.forEach(this.addContainer);for(let t in e){const{fields:r,source:n}=e[t];this.addContainer(t,r,n)}return this}),this.parent=e,this.addFieldProcessorsBulk({int:e=>e&&parseInt(e)?+parseInt(e):0,string:e=>"string"==typeof e?e:e?""+e:"",array:e=>Array.isArray(e)?e:[],bool:e=>!!e,usd:e=>"NaN"!=e.toString()&&e.toString().indexOf("$")<0?e+"$":e,kzt:e=>"NaN"!=e.toString()&&e.toString().indexOf("₸")<0?e+"₸":e})}setProxy(e){if(this.getContainer(e)){let t=this.containers[e].data;this[`${r.CONTAINER_PROXY_PREFIX}${e}`]=new Proxy(t,{})}else console.error(`\n BaseAjax::setProxy()\n Container ${e} not found\n `)}createProcessorCallie(e){let t=e.split(".");return e=>{let r=!1,n=e;for(let e of t)if(e.indexOf(":")>=0){let t=e.split(":"),s=t[0],i=JSON.parse(t[1]);if(this.modifiers[s]){let e=this.modifiers[s](n,i);n=e.value||n,r=e.break||r}if(r)break}else n=this.proceedProcessor(e,n);return n}}getContainer(e){return this.containers[e]}proceedProcessor(e,t){return this.processors[e]?this.processors[e](t):void 0}getExtendedFields(e){if(!!~e.indexOf(" extends ")){let t=e.split(" extends ").map(e=>e.replace(/\s/g,"")),r={};if(~t[1].indexOf("[")){t[1].replace(/[\[\]]/g,"").split(",").forEach(e=>{this.described_containers[e]&&(r=Object.assign({},r,this.described_containers[e]))})}else this.described_containers[t[1]]&&(r=Object.assign({},r,this.described_containers[t[1]]));return{name:t[0],extended:r}}return!1}describeContainer(e,t={}){let r=this.getExtendedFields(e),n=e;return r&&(t=Object.assign({},t,r.extended),n=r.name),this.described_containers[n]=t,this}getProcessor(e){if(!~e.indexOf("@"))return e;{let t=e.replace("@","").split("."),r=t[0],n=this.getContainer(r);if(n){let e=t.slice(-1).join(""),r=n.fields[e];return~r.indexOf("@")?this.getProcessor(r):r}}}addModifier(e){let t=e.name||null,r=e.proc||null;return t&&r?(this.modifiers[t]=r,this):(console.error("\n BaseAjax::addModifier()\n You should specify both name and callback\n "),this)}addFieldProcessor(e){let t=e.name,r=e.proc;return t&&r?(this.processors[t]=r,this):(console.error("\n BaseModel::addFieldProcessor()\n You should specify both name and callback\n "),this)}addFieldProcessorsBulk(e){return this.processors=Object.assign({},this.processors,e),this}addModifiersBulk(e){return this.modifiers=Object.assign({},this.modifiers,e),this}getFieldFromContainer(t,r){let n=this.getContainer(t),s=n?n.data:null;return s||console.error(`BaseModel::getFieldFromContainer() Container ${t} not found`),e(s,r)}generateQuery(e){let t,n=e.uri,s=(e.method||r.QUERY_METHOD).toUpperCase(),i=e.container||null;i&&(t=this.getContainer(i));let o=t?this.getFields(i):e.data||null,a=e.mode,d=e.headers||{},u=e.credentials,c=(e.check,!0===e.json||!1===e.json?e.json:r.IS_JSON_RESPONSE);"GET"==s&&o?(n=n+(~n.indexOf("?")?"&":"?")+function(e){return Object.keys(e).map(t=>Array.isArray(e[t])?e[t].map(e=>e?`${encodeURIComponent(t)}[]=${encodeURIComponent(e)}`:"").join("&"):e[t]?`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`:"").join("&")}(o),o=null):"GET"!=s&&(o=JSON.stringify(o));return()=>new Promise((e,t)=>{let r={headers:Object.assign({},d),credentials:u,method:s,mode:a,body:o},i={uri:n,fetch_params:r};this.beforeFetch&&this.beforeFetch.constructor&&this.beforeFetch.call&&this.beforeFetch.apply&&(i=this.beforeFetch(n,r)),fetch(i.uri,i.fetch_params).then(r=>{this.interceptor&&(this.interceptor(r)||t()),r.ok||t(),c?r.json().then(t=>{e(t)}).catch(()=>{let e=new Error("Json parse error");e.type="json",t(e)}):r.text().then(t=>{e(t)}).catch(()=>{let e=new Error("Text retrieve error");e.type="text",t(e)})}).catch(e=>{t(e)})})}parseCondition(t){let r=t.split(" ");for(let t in r){let n=r[t].split(".");if(n.length){let s=n.slice(1,-1).join("."),i=n.slice(-1).join("");if("^"==n[0]&&(r[t]=e(this.parent,s)[i]),"&"==n[0]&&(r[t]=e(this,s)[i]),"@"==n[0]){let e=n[0].replace("@","");r[t]=this.getFieldFromContainer(e,s)[i]}}}return t=r.join(" "),Function.apply(null,[].concat("return "+t))()}getFields(t){let r=this.getContainer(t);if(!Object.keys(r.fields).length)return console.error("\n BaseModel::getFields()\n You have to specify field names\n "),{};if(!r.fields)return r.data||{};let n={};return Object.keys(r.fields).map(t=>{let s=!~t.indexOf("?"),i=r.data,o=t.replace(/\?/g,""),a=o,d=null,u=null,c=!1,l=t.match(/if\((.+)\)/i),h=!0;if(l&&l.length>1&&(h=this.parseCondition(l[1])),h){if(~t.indexOf(".")){let r=t.split(" ")[0].split(".");if(a=r.slice(-1).join(""),"^"==r[0]||"&"==r[0]||0===r[0].indexOf("@")){c=!0;let t=r.slice(1,-1).join(".");if(0===r[0].indexOf("@")){let e=r[0].replace("@","");i=this.getFieldFromContainer(e,t)}else"^"==r[0]&&this.parent?i=e(this.parent,t):"&"==r[0]&&(i=e(this,t))}i||console.error(`BaseModel::getFields() Field ${t} not found`),u=i[a],o=a}let l=t.replace(/if\((.+)\)/gi,"").trim();if(~l.indexOf(" as ")){let e=l.split(" as ");c||(a=e[0]),o=e[1]}if(d=c?u:i[a],s||!s&&d){let e=this.getProcessor(r.fields[t]),s=this.createProcessorCallie(e);n[o]=s?s(d):d}}}),n}}var s=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},d=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},u="undefined"==typeof Promise?require("es6-promise").Promise:Promise,c="https://suggestions.dadata.ru/suggestions/api/4_1/rs",l=["fio","address","party","email","bank"],h={"Content-Type":"application/json",Accept:"application/json"},f={fio:"POST",address:"POST",party:"POST",email:"POST",bank:"POST"},p=["ACTIVE","LIQUIDATING","LIQUIDATED"],y=["LEGAL","INDIVIDUAL"],g=function(e){function t(e,r){s(this,t);var n=a(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.addHeaders(h),n.setToken(r),n.describeContainer("query",{query:"string.strip:300"}).describeContainer("base extends query",{"count?":"int"}).addContainer("fio extends base",{"parts?":"array","gender?":"string"}).addContainer("address extends base",{"locations?":"array","locations_boost?":"array","from_bound?":"bound","to_bound?":"bound"}).addContainer("party extends base",{"status?":"array.party_status","type?":"array.party_types","locations?":"array"}).addContainer("email extends base",{}).addContainer("bank extends base",{"status?":"array.party_status","type?":"array.party_types"}).addContainer("find_address extends query",{}).addContainer("find_party extends query",{"type?":"string.party_types","branch_type?":"string"}).addFieldProcessorsBulk({bound:function(e){return e&&e.value?e:null},party_status:function(e){return p.includes(e)?e:null},party_types:function(e){return y.includes(e)?e:null}}).addModifiersBulk({strip:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return{value:e.substr(0,t)}},allow:function(e,t){return{break:!!~t.indexOf(e)}},default:function(e,t){return{value:e||t}}}),n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,n),i(t,[{key:"beforeFetch",value:function(e,t){return t.headers=o({},t.headers,this.headers),{uri:e,fetch_params:t}}},{key:"addHeaders",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._headers=o({},this._headers,e)}},{key:"setToken",value:function(e){this.token=e,this.addHeaders({Authorization:"Token "+e})}},{key:"suggest",value:function(e,t){return this.getContainer(e)?(this.containers[e].data=o({},t),this.generateQuery({uri:c+"/suggest/"+e,method:f[e],container:e})()):new u(function(t,r){r({error:'Suggestion type "'+e+'" not found'})})}},{key:"detectAddressByIP",value:function(e){return this.generateQuery({uri:c+"/detectAddressByIp",method:"GET",data:{ip:e}})()}},{key:"findById",value:function(e,t){return this.getContainer("find_"+e)?(this.containers["find_"+e].data=o({},t),this.generateQuery({uri:c+"/findById/"+e,method:"POST",container:"find_"+e})()):new u(function(t,r){r({error:'Find by id type "'+e+'" not found'})})}},{key:"checkStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return e&&!l.includes(e)?new u(function(t,r){r({error:'Service "'+e+'" not found'})}):this.generateQuery({uri:c+"/status/"+e,method:"GET"})()}},{key:"headers",get:function(){return this._headers||{}},set:function(e){this._headers=e||{}}}]),t}(),b=function(){try{if(isNaN.apply(null,{}))return function(e){return function(){try{return Promise.resolve(e.apply(this,arguments))}catch(e){return Promise.reject(e)}}}}catch(e){}return function(e){return function(){try{return Promise.resolve(e.apply(this,Array.prototype.slice.call(arguments)))}catch(e){return Promise.reject(e)}}}}();var m=function(){function e(t){s(this,e),this.model=new g(this,t),this.token=t,this._suggestions=[]}return i(e,[{key:"suggest",value:b(function(e,t){var r=this,n=arguments;return function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var s,i,a,u=n[2]||null,c=n[3]||{};return s=r.model.suggest(e,o({query:t,count:u},c)),i=function(e){if(e.suggestions)return r._suggestions=[].concat(d(e.suggestions)),r.suggestions;throw new Error("Result is empty")},a?i?i(s):s:(s=Promise.resolve(s),i?s.then(i):s)},function(e){return console.error(e),[]})})},{key:"clearCache",value:function(){var e=[].concat(d(this._suggestions));return this._suggestions.splice(0),e}},{key:"detectAddressByIP",value:function(){return this.model.detectAddressByIP(arguments[0]||null)}},{key:"suggestions",get:function(){return this._suggestions}}]),e}();return window&&(window.DaData=m),m}();
var VueSimpleSuggest=function(){"use strict";function e(e,t){return t?t.split(".").reduce((e,t)=>"object"==typeof e?e[t]:e,e):e}class t{constructor(e,t,r,n){this.data={},this.fields={},this.model=e,this.name=t,this.fields=r,n&&(this.data=n)}setSource(e){this.data=e,this.model.setProxy(this.name)}}var r;!function(e){e.IS_JSON_RESPONSE=!0,e.QUERY_METHOD="GET",e.CONTAINER_PROXY_PREFIX="$"}(r||(r={}));class n{constructor(e=null){this.processors={},this.modifiers={},this.described_containers={},this.containers={},this.addContainer=function(){if(arguments.length>=2)var e=arguments[0],r=arguments[1],n=arguments[2];else{const t=arguments[0];e=t.name,r=t.fields,n=t.source}let s=this.getExtendedFields(e),i=e;s&&(r=Object.assign({},r,s.extended),i=s.name);let o=new t(this,i,r,n);return this.containers[i]=o,this.setProxy(i),this},this.addContainers=(e=>{Array.isArray(e)&&e.forEach(this.addContainer);for(let t in e){const{fields:r,source:n}=e[t];this.addContainer(t,r,n)}return this}),this.parent=e,this.addFieldProcessorsBulk({int:e=>e&&parseInt(e)?+parseInt(e):0,string:e=>"string"==typeof e?e:e?""+e:"",array:e=>Array.isArray(e)?e:[],bool:e=>!!e,usd:e=>"NaN"!=e.toString()&&e.toString().indexOf("$")<0?e+"$":e,kzt:e=>"NaN"!=e.toString()&&e.toString().indexOf("₸")<0?e+"₸":e})}setProxy(e){if(this.getContainer(e)){let t=this.containers[e].data;this[`${r.CONTAINER_PROXY_PREFIX}${e}`]=t}else console.error(`\n BaseAjax::setProxy()\n Container ${e} not found\n `)}createProcessorCallie(e){let t=e.split(".");return e=>{let r=!1,n=e;for(let e of t)if(e.indexOf(":")>=0){let t=e.split(":"),s=t[0],i=JSON.parse(t[1]);if(this.modifiers[s]){let e=this.modifiers[s](n,i);n=e.value||n,r=e.break||r}if(r)break}else n=this.proceedProcessor(e,n);return n}}getContainer(e){return this.containers[e]}proceedProcessor(e,t){return this.processors[e]?this.processors[e](t):void 0}getExtendedFields(e){if(!!~e.indexOf(" extends ")){let t=e.split(" extends ").map(e=>e.replace(/\s/g,"")),r={};if(~t[1].indexOf("[")){t[1].replace(/[\[\]]/g,"").split(",").forEach(e=>{this.described_containers[e]&&(r=Object.assign({},r,this.described_containers[e]))})}else this.described_containers[t[1]]&&(r=Object.assign({},r,this.described_containers[t[1]]));return{name:t[0],extended:r}}return!1}describeContainer(e,t={}){let r=this.getExtendedFields(e),n=e;return r&&(t=Object.assign({},t,r.extended),n=r.name),this.described_containers[n]=t,this}getProcessor(e){if(~e.indexOf("@")){let t=e.replace("@","").split("."),r=t[0],n=this.getContainer(r);if(n){let e=t.slice(-1).join(""),r=n.fields[e];return~r.indexOf("@")?this.getProcessor(r):r}}return e}addModifier(e){let t=e.name||null,r=e.proc||null;return t&&r?(this.modifiers[t]=r,this):(console.error("\n BaseAjax::addModifier()\n You should specify both name and callback\n "),this)}addFieldProcessor(e){let t=e.name,r=e.proc;return t&&r?(this.processors[t]=r,this):(console.error("\n BaseModel::addFieldProcessor()\n You should specify both name and callback\n "),this)}addFieldProcessorsBulk(e){return this.processors=Object.assign({},this.processors,e),this}addModifiersBulk(e){return this.modifiers=Object.assign({},this.modifiers,e),this}getFieldFromContainer(t,r){let n=this.getContainer(t),s=n?n.data:null;return s||console.error(`BaseModel::getFieldFromContainer() Container ${t} not found`),e(s,r)}generateQuery(e){let t,n=e.uri,s=(e.method||r.QUERY_METHOD).toUpperCase(),i=e.container||null;i&&(t=this.getContainer(i));let o=t?this.getFields(i):e.data||null,a=e.mode,d=e.headers||{},u=e.credentials,c=(e.check,!0===e.json||!1===e.json?e.json:r.IS_JSON_RESPONSE);"GET"==s&&o?(n=n+(~n.indexOf("?")?"&":"?")+function(e){return Object.keys(e).map(t=>Array.isArray(e[t])?e[t].map(e=>e?`${encodeURIComponent(t)}[]=${encodeURIComponent(e)}`:"").join("&"):e[t]?`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`:"").join("&")}(o),o=null):"GET"!=s&&(o=JSON.stringify(o));return()=>new Promise((e,t)=>{let r={headers:Object.assign({},d),credentials:u,method:s,mode:a,body:o},i={uri:n,fetch_params:r};this.beforeFetch&&this.beforeFetch.constructor&&this.beforeFetch.call&&this.beforeFetch.apply&&(i=this.beforeFetch(n,r)),fetch(i.uri,i.fetch_params).then(r=>{this.interceptor&&(this.interceptor(r)||t()),r.ok||t(),c?r.json().then(t=>{e(t)}).catch(()=>{let e=new Error("Json parse error");e.type="json",t(e)}):r.text().then(t=>{e(t)}).catch(()=>{let e=new Error("Text retrieve error");e.type="text",t(e)})}).catch(e=>{t(e)})})}parseCondition(t){let r=t.split(" ");for(let t in r){let n=r[t].split(".");if(n.length){let s=n.slice(1,-1).join("."),i=n.slice(-1).join("");if("^"==n[0]&&(r[t]=e(this.parent,s)[i]),"&"==n[0]&&(r[t]=e(this,s)[i]),"@"==n[0]){let e=n[0].replace("@","");r[t]=this.getFieldFromContainer(e,s)[i]}}}return t=r.join(" "),Function.apply(null,[].concat("return "+t))()}getFields(t){let r=this.getContainer(t);if(!Object.keys(r.fields).length)return console.error("\n BaseModel::getFields()\n You have to specify field names\n "),{};if(!r.fields)return r.data||{};let n={};return Object.keys(r.fields).map(t=>{let s=!~t.indexOf("?"),i=r.data,o=t.replace(/\?/g,""),a=o,d=null,u=null,c=!1,l=t.match(/if\((.+)\)/i),h=!0;if(l&&l.length>1&&(h=this.parseCondition(l[1])),h){if(~t.indexOf(".")){let r=t.split(" ")[0].split(".");if(a=r.slice(-1).join(""),"^"==r[0]||"&"==r[0]||0===r[0].indexOf("@")){c=!0;let t=r.slice(1,-1).join(".");if(0===r[0].indexOf("@")){let e=r[0].replace("@","");i=this.getFieldFromContainer(e,t)}else"^"==r[0]&&this.parent?i=e(this.parent,t):"&"==r[0]&&(i=e(this,t))}i||console.error(`BaseModel::getFields() Field ${t} not found`),u=i[a],o=a}let l=t.replace(/if\((.+)\)/gi,"").trim();if(~l.indexOf(" as ")){let e=l.split(" as ");c||(a=e[0]),o=e[1]}if(d=c?u:i[a],s||!s&&d){let e=this.getProcessor(r.fields[t]),s=this.createProcessorCallie(e);n[o]=s?s(d):d}}}),n}}var s=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},d=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},u="undefined"==typeof Promise?require("es6-promise").Promise:Promise,c="https://suggestions.dadata.ru/suggestions/api/4_1/rs",l=["fio","address","party","email","bank"],h={"Content-Type":"application/json",Accept:"application/json"},f={fio:"POST",address:"POST",party:"POST",email:"POST",bank:"POST"},p=["ACTIVE","LIQUIDATING","LIQUIDATED"],y=["LEGAL","INDIVIDUAL"],g=function(e){function t(e,r){s(this,t);var n=a(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.addHeaders(h),n.setToken(r),n.describeContainer("query",{query:"string.strip:300"}).describeContainer("base extends query",{"count?":"int"}).addContainer("fio extends base",{"parts?":"array","gender?":"string"}).addContainer("address extends base",{"locations?":"array","locations_boost?":"array","from_bound?":"bound","to_bound?":"bound"}).addContainer("party extends base",{"status?":"array.party_status","type?":"array.party_types","locations?":"array"}).addContainer("email extends base",{}).addContainer("bank extends base",{"status?":"array.party_status","type?":"array.party_types"}).addContainer("find_address extends query",{}).addContainer("find_party extends query",{"type?":"string.party_types","branch_type?":"string"}).addFieldProcessorsBulk({bound:function(e){return e&&e.value?e:null},party_status:function(e){return p.includes(e)?e:null},party_types:function(e){return y.includes(e)?e:null}}).addModifiersBulk({strip:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return{value:e.substr(0,t)}},allow:function(e,t){return{break:!!~t.indexOf(e)}},default:function(e,t){return{value:e||t}}}),n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,n),i(t,[{key:"beforeFetch",value:function(e,t){return t.headers=o({},t.headers,this.headers),{uri:e,fetch_params:t}}},{key:"addHeaders",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._headers=o({},this._headers,e)}},{key:"setToken",value:function(e){this.token=e,this.addHeaders({Authorization:"Token "+e})}},{key:"suggest",value:function(e,t){return this.getContainer(e)?(this.containers[e].data=o({},t),this.generateQuery({uri:c+"/suggest/"+e,method:f[e],container:e})()):new u(function(t,r){r({error:'Suggestion type "'+e+'" not found'})})}},{key:"detectAddressByIP",value:function(e){return this.generateQuery({uri:c+"/detectAddressByIp",method:"GET",data:{ip:e}})()}},{key:"findById",value:function(e,t){return this.getContainer("find_"+e)?(this.containers["find_"+e].data=o({},t),this.generateQuery({uri:c+"/findById/"+e,method:"POST",container:"find_"+e})()):new u(function(t,r){r({error:'Find by id type "'+e+'" not found'})})}},{key:"checkStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return e&&!l.includes(e)?new u(function(t,r){r({error:'Service "'+e+'" not found'})}):this.generateQuery({uri:c+"/status/"+e,method:"GET"})()}},{key:"headers",get:function(){return this._headers||{}},set:function(e){this._headers=e||{}}}]),t}(),b=function(){try{if(isNaN.apply(null,{}))return function(e){return function(){try{return Promise.resolve(e.apply(this,arguments))}catch(e){return Promise.reject(e)}}}}catch(e){}return function(e){return function(){try{return Promise.resolve(e.apply(this,Array.prototype.slice.call(arguments)))}catch(e){return Promise.reject(e)}}}}();var m=function(){function e(t){s(this,e),this.model=new g(this,t),this.token=t,this._suggestions=[]}return i(e,[{key:"suggest",value:b(function(e,t){var r=this,n=arguments;return function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var s,i,a,u=n[2]||null,c=n[3]||{};return s=r.model.suggest(e,o({query:t,count:u},c)),i=function(e){if(e.suggestions)return r._suggestions=[].concat(d(e.suggestions)),r.suggestions;throw new Error("Result is empty")},a?i?i(s):s:(s=Promise.resolve(s),i?s.then(i):s)},function(e){return console.error(e),[]})})},{key:"clearCache",value:function(){var e=[].concat(d(this._suggestions));return this._suggestions.splice(0),e}},{key:"detectAddressByIP",value:function(){return this.model.detectAddressByIP(arguments[0]||null)}},{key:"suggestions",get:function(){return this._suggestions}}]),e}();return window&&(window.DaData=m),m}();

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueSimpleSuggest=t()}(this,function(){"use strict";function e(e,t){return t?t.split(".").reduce((e,t)=>"object"==typeof e?e[t]:e,e):e}class t{constructor(e,t,r,n){this.data={},this.fields={},this.model=e,this.name=t,this.fields=r,n&&(this.data=new Proxy(n,{}))}setSource(e){this.data=new Proxy(e,{}),this.model.setProxy(this.name)}}var r;!function(e){e.IS_JSON_RESPONSE=!0,e.QUERY_METHOD="GET",e.CONTAINER_PROXY_PREFIX="$"}(r||(r={}));class n{constructor(e=null){this.processors={},this.modifiers={},this.described_containers={},this.containers={},this.addContainer=function(){if(arguments.length>=2)var e=arguments[0],r=arguments[1],n=arguments[2];else{const t=arguments[0];e=t.name,r=t.fields,n=t.source}let s=this.getExtendedFields(e),i=e;s&&(r=Object.assign({},r,s.extended),i=s.name);let o=new t(this,i,r,n);return this.containers[i]=o,this.setProxy(i),this},this.addContainers=(e=>{Array.isArray(e)&&e.forEach(this.addContainer);for(let t in e){const{fields:r,source:n}=e[t];this.addContainer(t,r,n)}return this}),this.parent=e,this.addFieldProcessorsBulk({int:e=>e&&parseInt(e)?+parseInt(e):0,string:e=>"string"==typeof e?e:e?""+e:"",array:e=>Array.isArray(e)?e:[],bool:e=>!!e,usd:e=>"NaN"!=e.toString()&&e.toString().indexOf("$")<0?e+"$":e,kzt:e=>"NaN"!=e.toString()&&e.toString().indexOf("₸")<0?e+"₸":e})}setProxy(e){if(this.getContainer(e)){let t=this.containers[e].data;this[`${r.CONTAINER_PROXY_PREFIX}${e}`]=new Proxy(t,{})}else console.error(`\n BaseAjax::setProxy()\n Container ${e} not found\n `)}createProcessorCallie(e){let t=e.split(".");return e=>{let r=!1,n=e;for(let e of t)if(e.indexOf(":")>=0){let t=e.split(":"),s=t[0],i=JSON.parse(t[1]);if(this.modifiers[s]){let e=this.modifiers[s](n,i);n=e.value||n,r=e.break||r}if(r)break}else n=this.proceedProcessor(e,n);return n}}getContainer(e){return this.containers[e]}proceedProcessor(e,t){return this.processors[e]?this.processors[e](t):void 0}getExtendedFields(e){if(!!~e.indexOf(" extends ")){let t=e.split(" extends ").map(e=>e.replace(/\s/g,"")),r={};if(~t[1].indexOf("[")){t[1].replace(/[\[\]]/g,"").split(",").forEach(e=>{this.described_containers[e]&&(r=Object.assign({},r,this.described_containers[e]))})}else this.described_containers[t[1]]&&(r=Object.assign({},r,this.described_containers[t[1]]));return{name:t[0],extended:r}}return!1}describeContainer(e,t={}){let r=this.getExtendedFields(e),n=e;return r&&(t=Object.assign({},t,r.extended),n=r.name),this.described_containers[n]=t,this}getProcessor(e){if(!~e.indexOf("@"))return e;{let t=e.replace("@","").split("."),r=t[0],n=this.getContainer(r);if(n){let e=t.slice(-1).join(""),r=n.fields[e];return~r.indexOf("@")?this.getProcessor(r):r}}}addModifier(e){let t=e.name||null,r=e.proc||null;return t&&r?(this.modifiers[t]=r,this):(console.error("\n BaseAjax::addModifier()\n You should specify both name and callback\n "),this)}addFieldProcessor(e){let t=e.name,r=e.proc;return t&&r?(this.processors[t]=r,this):(console.error("\n BaseModel::addFieldProcessor()\n You should specify both name and callback\n "),this)}addFieldProcessorsBulk(e){return this.processors=Object.assign({},this.processors,e),this}addModifiersBulk(e){return this.modifiers=Object.assign({},this.modifiers,e),this}getFieldFromContainer(t,r){let n=this.getContainer(t),s=n?n.data:null;return s||console.error(`BaseModel::getFieldFromContainer() Container ${t} not found`),e(s,r)}generateQuery(e){let t,n=e.uri,s=(e.method||r.QUERY_METHOD).toUpperCase(),i=e.container||null;i&&(t=this.getContainer(i));let o=t?this.getFields(i):e.data||null,a=e.mode,d=e.headers||{},u=e.credentials,c=(e.check,!0===e.json||!1===e.json?e.json:r.IS_JSON_RESPONSE);"GET"==s&&o?(n=n+(~n.indexOf("?")?"&":"?")+function(e){return Object.keys(e).map(t=>Array.isArray(e[t])?e[t].map(e=>e?`${encodeURIComponent(t)}[]=${encodeURIComponent(e)}`:"").join("&"):e[t]?`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`:"").join("&")}(o),o=null):"GET"!=s&&(o=JSON.stringify(o));return()=>new Promise((e,t)=>{let r={headers:Object.assign({},d),credentials:u,method:s,mode:a,body:o},i={uri:n,fetch_params:r};this.beforeFetch&&this.beforeFetch.constructor&&this.beforeFetch.call&&this.beforeFetch.apply&&(i=this.beforeFetch(n,r)),fetch(i.uri,i.fetch_params).then(r=>{this.interceptor&&(this.interceptor(r)||t()),r.ok||t(),c?r.json().then(t=>{e(t)}).catch(()=>{let e=new Error("Json parse error");e.type="json",t(e)}):r.text().then(t=>{e(t)}).catch(()=>{let e=new Error("Text retrieve error");e.type="text",t(e)})}).catch(e=>{t(e)})})}parseCondition(t){let r=t.split(" ");for(let t in r){let n=r[t].split(".");if(n.length){let s=n.slice(1,-1).join("."),i=n.slice(-1).join("");if("^"==n[0]&&(r[t]=e(this.parent,s)[i]),"&"==n[0]&&(r[t]=e(this,s)[i]),"@"==n[0]){let e=n[0].replace("@","");r[t]=this.getFieldFromContainer(e,s)[i]}}}return t=r.join(" "),Function.apply(null,[].concat("return "+t))()}getFields(t){let r=this.getContainer(t);if(!Object.keys(r.fields).length)return console.error("\n BaseModel::getFields()\n You have to specify field names\n "),{};if(!r.fields)return r.data||{};let n={};return Object.keys(r.fields).map(t=>{let s=!~t.indexOf("?"),i=r.data,o=t.replace(/\?/g,""),a=o,d=null,u=null,c=!1,l=t.match(/if\((.+)\)/i),h=!0;if(l&&l.length>1&&(h=this.parseCondition(l[1])),h){if(~t.indexOf(".")){let r=t.split(" ")[0].split(".");if(a=r.slice(-1).join(""),"^"==r[0]||"&"==r[0]||0===r[0].indexOf("@")){c=!0;let t=r.slice(1,-1).join(".");if(0===r[0].indexOf("@")){let e=r[0].replace("@","");i=this.getFieldFromContainer(e,t)}else"^"==r[0]&&this.parent?i=e(this.parent,t):"&"==r[0]&&(i=e(this,t))}i||console.error(`BaseModel::getFields() Field ${t} not found`),u=i[a],o=a}let l=t.replace(/if\((.+)\)/gi,"").trim();if(~l.indexOf(" as ")){let e=l.split(" as ");c||(a=e[0]),o=e[1]}if(d=c?u:i[a],s||!s&&d){let e=this.getProcessor(r.fields[t]),s=this.createProcessorCallie(e);n[o]=s?s(d):d}}}),n}}var s=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},d=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},u="https://suggestions.dadata.ru/suggestions/api/4_1/rs",c=["fio","address","party","email","bank"],l={"Content-Type":"application/json",Accept:"application/json"},h={fio:"POST",address:"POST",party:"POST",email:"POST",bank:"POST"},f=["ACTIVE","LIQUIDATING","LIQUIDATED"],p=["LEGAL","INDIVIDUAL"],y=function(e){function t(e,r){s(this,t);var n=a(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.addHeaders(l),n.setToken(r),n.describeContainer("query",{query:"string.strip:300"}).describeContainer("base extends query",{"count?":"int"}).addContainer("fio extends base",{"parts?":"array","gender?":"string"}).addContainer("address extends base",{"locations?":"array","locations_boost?":"array","from_bound?":"bound","to_bound?":"bound"}).addContainer("party extends base",{"status?":"array.party_status","type?":"array.party_types","locations?":"array"}).addContainer("email extends base",{}).addContainer("bank extends base",{"status?":"array.party_status","type?":"array.party_types"}).addContainer("find_address extends query",{}).addContainer("find_party extends query",{"type?":"string.party_types","branch_type?":"string"}).addFieldProcessorsBulk({bound:function(e){return e&&e.value?e:null},party_status:function(e){return f.includes(e)?e:null},party_types:function(e){return p.includes(e)?e:null}}).addModifiersBulk({strip:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return{value:e.substr(0,t)}},allow:function(e,t){return{break:!!~t.indexOf(e)}},default:function(e,t){return{value:e||t}}}),n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,n),i(t,[{key:"beforeFetch",value:function(e,t){return t.headers=o({},t.headers,this.headers),{uri:e,fetch_params:t}}},{key:"addHeaders",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._headers=o({},this._headers,e)}},{key:"setToken",value:function(e){this.token=e,this.addHeaders({Authorization:"Token "+e})}},{key:"suggest",value:function(e,t){return this.getContainer(e)?(this.containers[e].data=o({},t),this.generateQuery({uri:u+"/suggest/"+e,method:h[e],container:e})()):new Promise(function(t,r){r({error:'Suggestion type "'+e+'" not found'})})}},{key:"detectAddressByIP",value:function(e){return this.generateQuery({uri:u+"/detectAddressByIp",method:"GET",data:{ip:e}})()}},{key:"findById",value:function(e,t){return this.getContainer("find_"+e)?(this.containers["find_"+e].data=o({},t),this.generateQuery({uri:u+"/findById/"+e,method:"POST",container:"find_"+e})()):new Promise(function(t,r){r({error:'Find by id type "'+e+'" not found'})})}},{key:"checkStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return e&&!c.includes(e)?new Promise(function(t,r){r({error:'Service "'+e+'" not found'})}):this.generateQuery({uri:u+"/status/"+e,method:"GET"})()}},{key:"headers",get:function(){return this._headers||{}},set:function(e){this._headers=e||{}}}]),t}(),g=function(){try{if(isNaN.apply(null,{}))return function(e){return function(){try{return Promise.resolve(e.apply(this,arguments))}catch(e){return Promise.reject(e)}}}}catch(e){}return function(e){return function(){try{return Promise.resolve(e.apply(this,Array.prototype.slice.call(arguments)))}catch(e){return Promise.reject(e)}}}}();var b=function(){function e(t){s(this,e),this.model=new y(this,t),this.token=t,this._suggestions=[]}return i(e,[{key:"suggest",value:g(function(e,t){var r=this,n=arguments;return function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var s,i,a,u=n[2]||null,c=n[3]||{};return s=r.model.suggest(e,o({query:t,count:u},c)),i=function(e){if(e.suggestions)return r._suggestions=[].concat(d(e.suggestions)),r.suggestions;throw new Error("Result is empty")},a?i?i(s):s:(s=Promise.resolve(s),i?s.then(i):s)},function(e){return console.error(e),[]})})},{key:"clearCache",value:function(){var e=[].concat(d(this._suggestions));return this._suggestions.splice(0),e}},{key:"detectAddressByIP",value:function(){return this.model.detectAddressByIP(arguments[0]||null)}},{key:"suggestions",get:function(){return this._suggestions}}]),e}();return window&&(window.DaData=b),b});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueSimpleSuggest=t()}(this,function(){"use strict";function e(e,t){return t?t.split(".").reduce((e,t)=>"object"==typeof e?e[t]:e,e):e}class t{constructor(e,t,r,n){this.data={},this.fields={},this.model=e,this.name=t,this.fields=r,n&&(this.data=n)}setSource(e){this.data=e,this.model.setProxy(this.name)}}var r;!function(e){e.IS_JSON_RESPONSE=!0,e.QUERY_METHOD="GET",e.CONTAINER_PROXY_PREFIX="$"}(r||(r={}));class n{constructor(e=null){this.processors={},this.modifiers={},this.described_containers={},this.containers={},this.addContainer=function(){if(arguments.length>=2)var e=arguments[0],r=arguments[1],n=arguments[2];else{const t=arguments[0];e=t.name,r=t.fields,n=t.source}let s=this.getExtendedFields(e),i=e;s&&(r=Object.assign({},r,s.extended),i=s.name);let o=new t(this,i,r,n);return this.containers[i]=o,this.setProxy(i),this},this.addContainers=(e=>{Array.isArray(e)&&e.forEach(this.addContainer);for(let t in e){const{fields:r,source:n}=e[t];this.addContainer(t,r,n)}return this}),this.parent=e,this.addFieldProcessorsBulk({int:e=>e&&parseInt(e)?+parseInt(e):0,string:e=>"string"==typeof e?e:e?""+e:"",array:e=>Array.isArray(e)?e:[],bool:e=>!!e,usd:e=>"NaN"!=e.toString()&&e.toString().indexOf("$")<0?e+"$":e,kzt:e=>"NaN"!=e.toString()&&e.toString().indexOf("₸")<0?e+"₸":e})}setProxy(e){if(this.getContainer(e)){let t=this.containers[e].data;this[`${r.CONTAINER_PROXY_PREFIX}${e}`]=t}else console.error(`\n BaseAjax::setProxy()\n Container ${e} not found\n `)}createProcessorCallie(e){let t=e.split(".");return e=>{let r=!1,n=e;for(let e of t)if(e.indexOf(":")>=0){let t=e.split(":"),s=t[0],i=JSON.parse(t[1]);if(this.modifiers[s]){let e=this.modifiers[s](n,i);n=e.value||n,r=e.break||r}if(r)break}else n=this.proceedProcessor(e,n);return n}}getContainer(e){return this.containers[e]}proceedProcessor(e,t){return this.processors[e]?this.processors[e](t):void 0}getExtendedFields(e){if(!!~e.indexOf(" extends ")){let t=e.split(" extends ").map(e=>e.replace(/\s/g,"")),r={};if(~t[1].indexOf("[")){t[1].replace(/[\[\]]/g,"").split(",").forEach(e=>{this.described_containers[e]&&(r=Object.assign({},r,this.described_containers[e]))})}else this.described_containers[t[1]]&&(r=Object.assign({},r,this.described_containers[t[1]]));return{name:t[0],extended:r}}return!1}describeContainer(e,t={}){let r=this.getExtendedFields(e),n=e;return r&&(t=Object.assign({},t,r.extended),n=r.name),this.described_containers[n]=t,this}getProcessor(e){if(~e.indexOf("@")){let t=e.replace("@","").split("."),r=t[0],n=this.getContainer(r);if(n){let e=t.slice(-1).join(""),r=n.fields[e];return~r.indexOf("@")?this.getProcessor(r):r}}return e}addModifier(e){let t=e.name||null,r=e.proc||null;return t&&r?(this.modifiers[t]=r,this):(console.error("\n BaseAjax::addModifier()\n You should specify both name and callback\n "),this)}addFieldProcessor(e){let t=e.name,r=e.proc;return t&&r?(this.processors[t]=r,this):(console.error("\n BaseModel::addFieldProcessor()\n You should specify both name and callback\n "),this)}addFieldProcessorsBulk(e){return this.processors=Object.assign({},this.processors,e),this}addModifiersBulk(e){return this.modifiers=Object.assign({},this.modifiers,e),this}getFieldFromContainer(t,r){let n=this.getContainer(t),s=n?n.data:null;return s||console.error(`BaseModel::getFieldFromContainer() Container ${t} not found`),e(s,r)}generateQuery(e){let t,n=e.uri,s=(e.method||r.QUERY_METHOD).toUpperCase(),i=e.container||null;i&&(t=this.getContainer(i));let o=t?this.getFields(i):e.data||null,a=e.mode,d=e.headers||{},u=e.credentials,c=(e.check,!0===e.json||!1===e.json?e.json:r.IS_JSON_RESPONSE);"GET"==s&&o?(n=n+(~n.indexOf("?")?"&":"?")+function(e){return Object.keys(e).map(t=>Array.isArray(e[t])?e[t].map(e=>e?`${encodeURIComponent(t)}[]=${encodeURIComponent(e)}`:"").join("&"):e[t]?`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`:"").join("&")}(o),o=null):"GET"!=s&&(o=JSON.stringify(o));return()=>new Promise((e,t)=>{let r={headers:Object.assign({},d),credentials:u,method:s,mode:a,body:o},i={uri:n,fetch_params:r};this.beforeFetch&&this.beforeFetch.constructor&&this.beforeFetch.call&&this.beforeFetch.apply&&(i=this.beforeFetch(n,r)),fetch(i.uri,i.fetch_params).then(r=>{this.interceptor&&(this.interceptor(r)||t()),r.ok||t(),c?r.json().then(t=>{e(t)}).catch(()=>{let e=new Error("Json parse error");e.type="json",t(e)}):r.text().then(t=>{e(t)}).catch(()=>{let e=new Error("Text retrieve error");e.type="text",t(e)})}).catch(e=>{t(e)})})}parseCondition(t){let r=t.split(" ");for(let t in r){let n=r[t].split(".");if(n.length){let s=n.slice(1,-1).join("."),i=n.slice(-1).join("");if("^"==n[0]&&(r[t]=e(this.parent,s)[i]),"&"==n[0]&&(r[t]=e(this,s)[i]),"@"==n[0]){let e=n[0].replace("@","");r[t]=this.getFieldFromContainer(e,s)[i]}}}return t=r.join(" "),Function.apply(null,[].concat("return "+t))()}getFields(t){let r=this.getContainer(t);if(!Object.keys(r.fields).length)return console.error("\n BaseModel::getFields()\n You have to specify field names\n "),{};if(!r.fields)return r.data||{};let n={};return Object.keys(r.fields).map(t=>{let s=!~t.indexOf("?"),i=r.data,o=t.replace(/\?/g,""),a=o,d=null,u=null,c=!1,l=t.match(/if\((.+)\)/i),h=!0;if(l&&l.length>1&&(h=this.parseCondition(l[1])),h){if(~t.indexOf(".")){let r=t.split(" ")[0].split(".");if(a=r.slice(-1).join(""),"^"==r[0]||"&"==r[0]||0===r[0].indexOf("@")){c=!0;let t=r.slice(1,-1).join(".");if(0===r[0].indexOf("@")){let e=r[0].replace("@","");i=this.getFieldFromContainer(e,t)}else"^"==r[0]&&this.parent?i=e(this.parent,t):"&"==r[0]&&(i=e(this,t))}i||console.error(`BaseModel::getFields() Field ${t} not found`),u=i[a],o=a}let l=t.replace(/if\((.+)\)/gi,"").trim();if(~l.indexOf(" as ")){let e=l.split(" as ");c||(a=e[0]),o=e[1]}if(d=c?u:i[a],s||!s&&d){let e=this.getProcessor(r.fields[t]),s=this.createProcessorCallie(e);n[o]=s?s(d):d}}}),n}}var s=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},d=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},u="https://suggestions.dadata.ru/suggestions/api/4_1/rs",c=["fio","address","party","email","bank"],l={"Content-Type":"application/json",Accept:"application/json"},h={fio:"POST",address:"POST",party:"POST",email:"POST",bank:"POST"},f=["ACTIVE","LIQUIDATING","LIQUIDATED"],p=["LEGAL","INDIVIDUAL"],y=function(e){function t(e,r){s(this,t);var n=a(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.addHeaders(l),n.setToken(r),n.describeContainer("query",{query:"string.strip:300"}).describeContainer("base extends query",{"count?":"int"}).addContainer("fio extends base",{"parts?":"array","gender?":"string"}).addContainer("address extends base",{"locations?":"array","locations_boost?":"array","from_bound?":"bound","to_bound?":"bound"}).addContainer("party extends base",{"status?":"array.party_status","type?":"array.party_types","locations?":"array"}).addContainer("email extends base",{}).addContainer("bank extends base",{"status?":"array.party_status","type?":"array.party_types"}).addContainer("find_address extends query",{}).addContainer("find_party extends query",{"type?":"string.party_types","branch_type?":"string"}).addFieldProcessorsBulk({bound:function(e){return e&&e.value?e:null},party_status:function(e){return f.includes(e)?e:null},party_types:function(e){return p.includes(e)?e:null}}).addModifiersBulk({strip:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return{value:e.substr(0,t)}},allow:function(e,t){return{break:!!~t.indexOf(e)}},default:function(e,t){return{value:e||t}}}),n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,n),i(t,[{key:"beforeFetch",value:function(e,t){return t.headers=o({},t.headers,this.headers),{uri:e,fetch_params:t}}},{key:"addHeaders",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._headers=o({},this._headers,e)}},{key:"setToken",value:function(e){this.token=e,this.addHeaders({Authorization:"Token "+e})}},{key:"suggest",value:function(e,t){return this.getContainer(e)?(this.containers[e].data=o({},t),this.generateQuery({uri:u+"/suggest/"+e,method:h[e],container:e})()):new Promise(function(t,r){r({error:'Suggestion type "'+e+'" not found'})})}},{key:"detectAddressByIP",value:function(e){return this.generateQuery({uri:u+"/detectAddressByIp",method:"GET",data:{ip:e}})()}},{key:"findById",value:function(e,t){return this.getContainer("find_"+e)?(this.containers["find_"+e].data=o({},t),this.generateQuery({uri:u+"/findById/"+e,method:"POST",container:"find_"+e})()):new Promise(function(t,r){r({error:'Find by id type "'+e+'" not found'})})}},{key:"checkStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return e&&!c.includes(e)?new Promise(function(t,r){r({error:'Service "'+e+'" not found'})}):this.generateQuery({uri:u+"/status/"+e,method:"GET"})()}},{key:"headers",get:function(){return this._headers||{}},set:function(e){this._headers=e||{}}}]),t}(),g=function(){try{if(isNaN.apply(null,{}))return function(e){return function(){try{return Promise.resolve(e.apply(this,arguments))}catch(e){return Promise.reject(e)}}}}catch(e){}return function(e){return function(){try{return Promise.resolve(e.apply(this,Array.prototype.slice.call(arguments)))}catch(e){return Promise.reject(e)}}}}();var b=function(){function e(t){s(this,e),this.model=new y(this,t),this.token=t,this._suggestions=[]}return i(e,[{key:"suggest",value:g(function(e,t){var r=this,n=arguments;return function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var s,i,a,u=n[2]||null,c=n[3]||{};return s=r.model.suggest(e,o({query:t,count:u},c)),i=function(e){if(e.suggestions)return r._suggestions=[].concat(d(e.suggestions)),r.suggestions;throw new Error("Result is empty")},a?i?i(s):s:(s=Promise.resolve(s),i?s.then(i):s)},function(e){return console.error(e),[]})})},{key:"clearCache",value:function(){var e=[].concat(d(this._suggestions));return this._suggestions.splice(0),e}},{key:"detectAddressByIP",value:function(){return this.model.detectAddressByIP(arguments[0]||null)}},{key:"suggestions",get:function(){return this._suggestions}}]),e}();return window&&(window.DaData=b),b});
{
"name": "dadata-js",
"version": "0.0.4",
"version": "0.1.0",
"description": "A dadata js client",

@@ -35,7 +35,7 @@ "main": "dist/cjs.js",

"dependencies": {
"basemodelts": "^1.4.4",
"basemodelts": "^1.5.0",
"whatwg-fetch": "^2.0.3"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",

@@ -46,3 +46,3 @@ "babel-plugin-es6-promise": "^1.1.1",

"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015-rollup": "^3.0.0",

@@ -64,3 +64,3 @@ "babel-preset-stage-0": "^6.24.1",

"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-regenerator": "^0.5.4",
"rollup-plugin-regenerator": "^0.6.0",
"rollup-plugin-uglify": "^3.0.0",

@@ -74,3 +74,3 @@ "rollup-plugin-vue2": "^0.8.0",

"webpack-cli": "^2.0.8",
"webpack-dev-server": "^3.1.0"
"webpack-dev-server": "^3.2.1"
},

@@ -77,0 +77,0 @@ "jest": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc