itako-text-transformer-request
Version:
2 lines • 8.56 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.ItakoTextTransformerRequest=t()}(this,function(){"use strict";function e(e,t){return t={exports:{}},e(t,t.exports),t.exports}var t={};t["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},t.classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},t.createClass=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}}(),t["extends"]=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};var r=e(function(e,r){var n=function(){for(var e=new Array(256),t=0;256>t;++t)e[t]="%"+((16>t?"0":"")+t.toString(16)).toUpperCase();return e}();r.arrayToObject=function(e,t){for(var r=t.plainObjects?Object.create(null):{},n=0;n<e.length;++n)"undefined"!=typeof e[n]&&(r[n]=e[n]);return r},r.merge=function(e,n,o){if(!n)return e;if("object"!==("undefined"==typeof n?"undefined":t["typeof"](n))){if(Array.isArray(e))e.push(n);else{if("object"!==("undefined"==typeof e?"undefined":t["typeof"](e)))return[e,n];e[n]=!0}return e}if("object"!==("undefined"==typeof e?"undefined":t["typeof"](e)))return[e].concat(n);var i=e;return Array.isArray(e)&&!Array.isArray(n)&&(i=r.arrayToObject(e,o)),Object.keys(n).reduce(function(e,t){var i=n[t];return Object.prototype.hasOwnProperty.call(e,t)?e[t]=r.merge(e[t],i,o):e[t]=i,e},i)},r.decode=function(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(t){return e}},r.encode=function(e){if(0===e.length)return e;for(var t="string"==typeof e?e:String(e),r="",o=0;o<t.length;++o){var i=t.charCodeAt(o);45===i||46===i||95===i||126===i||i>=48&&57>=i||i>=65&&90>=i||i>=97&&122>=i?r+=t.charAt(o):128>i?r+=n[i]:2048>i?r+=n[192|i>>6]+n[128|63&i]:55296>i||i>=57344?r+=n[224|i>>12]+n[128|i>>6&63]+n[128|63&i]:(o+=1,i=65536+((1023&i)<<10|1023&t.charCodeAt(o)),r+=n[240|i>>18]+n[128|i>>12&63]+n[128|i>>6&63]+n[128|63&i])}return r},r.compact=function(e,n){if("object"!==("undefined"==typeof e?"undefined":t["typeof"](e))||null===e)return e;var o=n||[],i=o.indexOf(e);if(-1!==i)return o[i];if(o.push(e),Array.isArray(e)){for(var a=[],f=0;f<e.length;++f)"undefined"!=typeof e[f]&&a.push(e[f]);return a}for(var l=Object.keys(e),s=0;s<l.length;++s){var u=l[s];e[u]=r.compact(e[u],o)}return e},r.isRegExp=function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},r.isBuffer=function(e){return null===e||"undefined"==typeof e?!1:!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))}}),n=r&&"object"===("undefined"==typeof r?"undefined":t["typeof"](r))&&"default"in r?r["default"]:r,o=e(function(e){var t=n,r={delimiter:"&",depth:5,arrayLimit:20,parameterLimit:1e3,strictNullHandling:!1,plainObjects:!1,allowPrototypes:!1,allowDots:!1};r.parseValues=function(e,r){for(var n={},o=e.split(r.delimiter,r.parameterLimit===1/0?void 0:r.parameterLimit),i=0;i<o.length;++i){var a=o[i],f=-1===a.indexOf("]=")?a.indexOf("="):a.indexOf("]=")+1;if(-1===f)n[t.decode(a)]="",r.strictNullHandling&&(n[t.decode(a)]=null);else{var l=t.decode(a.slice(0,f)),s=t.decode(a.slice(f+1));Object.prototype.hasOwnProperty.call(n,l)?n[l]=[].concat(n[l]).concat(s):n[l]=s}}return n},r.parseObject=function(e,t,n){if(!e.length)return t;var o,i=e.shift();if("[]"===i)o=[],o=o.concat(r.parseObject(e,t,n));else{o=n.plainObjects?Object.create(null):{};var a="["===i[0]&&"]"===i[i.length-1]?i.slice(1,i.length-1):i,f=parseInt(a,10);!isNaN(f)&&i!==a&&String(f)===a&&f>=0&&n.parseArrays&&f<=n.arrayLimit?(o=[],o[f]=r.parseObject(e,t,n)):o[a]=r.parseObject(e,t,n)}return o},r.parseKeys=function(e,t,n){if(e){var o=n.allowDots?e.replace(/\.([^\.\[]+)/g,"[$1]"):e,i=/^([^\[\]]*)/,a=/(\[[^\[\]]*\])/g,f=i.exec(o),l=[];if(f[1]){if(!n.plainObjects&&Object.prototype.hasOwnProperty(f[1])&&!n.allowPrototypes)return;l.push(f[1])}for(var s=0;null!==(f=a.exec(o))&&s<n.depth;)s+=1,(n.plainObjects||!Object.prototype.hasOwnProperty(f[1].replace(/\[|\]/g,""))||n.allowPrototypes)&&l.push(f[1]);return f&&l.push("["+o.slice(f.index)+"]"),r.parseObject(l,t,n)}},e.exports=function(e,n){var o=n||{};if(o.delimiter="string"==typeof o.delimiter||t.isRegExp(o.delimiter)?o.delimiter:r.delimiter,o.depth="number"==typeof o.depth?o.depth:r.depth,o.arrayLimit="number"==typeof o.arrayLimit?o.arrayLimit:r.arrayLimit,o.parseArrays=o.parseArrays!==!1,o.allowDots="boolean"==typeof o.allowDots?o.allowDots:r.allowDots,o.plainObjects="boolean"==typeof o.plainObjects?o.plainObjects:r.plainObjects,o.allowPrototypes="boolean"==typeof o.allowPrototypes?o.allowPrototypes:r.allowPrototypes,o.parameterLimit="number"==typeof o.parameterLimit?o.parameterLimit:r.parameterLimit,o.strictNullHandling="boolean"==typeof o.strictNullHandling?o.strictNullHandling:r.strictNullHandling,""===e||null===e||"undefined"==typeof e)return o.plainObjects?Object.create(null):{};for(var i="string"==typeof e?r.parseValues(e,o):e,a=o.plainObjects?Object.create(null):{},f=Object.keys(i),l=0;l<f.length;++l){var s=f[l],u=r.parseKeys(s,i[s],o);a=t.merge(a,u,o)}return t.compact(a)}}),i=o&&"object"===("undefined"==typeof o?"undefined":t["typeof"](o))&&"default"in o?o["default"]:o,a=e(function(e){var r=n,o={delimiter:"&",arrayPrefixGenerators:{brackets:function(e){return e+"[]"},indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},strictNullHandling:!1,skipNulls:!1,encode:!0};o.stringify=function(e,t,n,i,a,f,l,s,u){var c=e;if("function"==typeof l)c=l(t,c);else if(r.isBuffer(c))c=String(c);else if(c instanceof Date)c=c.toISOString();else if(null===c){if(i)return f?r.encode(t):t;c=""}if("string"==typeof c||"number"==typeof c||"boolean"==typeof c)return f?[r.encode(t)+"="+r.encode(c)]:[t+"="+c];var p=[];if("undefined"==typeof c)return p;var d;if(Array.isArray(l))d=l;else{var y=Object.keys(c);d=s?y.sort(s):y}for(var b=0;b<d.length;++b){var m=d[b];a&&null===c[m]||(p=Array.isArray(c)?p.concat(o.stringify(c[m],n(t,m),n,i,a,f,l,s,u)):p.concat(o.stringify(c[m],t+(u?"."+m:"["+m+"]"),n,i,a,f,l,s,u)))}return p},e.exports=function(e,r){var n,i,a=e,f=r||{},l="undefined"==typeof f.delimiter?o.delimiter:f.delimiter,s="boolean"==typeof f.strictNullHandling?f.strictNullHandling:o.strictNullHandling,u="boolean"==typeof f.skipNulls?f.skipNulls:o.skipNulls,c="boolean"==typeof f.encode?f.encode:o.encode,p="function"==typeof f.sort?f.sort:null,d="undefined"==typeof f.allowDots?!1:f.allowDots;"function"==typeof f.filter?(i=f.filter,a=i("",a)):Array.isArray(f.filter)&&(n=i=f.filter);var y=[];if("object"!==("undefined"==typeof a?"undefined":t["typeof"](a))||null===a)return"";var b;b=f.arrayFormat in o.arrayPrefixGenerators?f.arrayFormat:"indices"in f?f.indices?"indices":"repeat":"indices";var m=o.arrayPrefixGenerators[b];n||(n=Object.keys(a)),p&&n.sort(p);for(var g=0;g<n.length;++g){var v=n[g];u&&null===a[v]||(y=y.concat(o.stringify(a[v],v,m,s,u,c,i,p,d)))}return y.join(l)}}),f=a&&"object"===("undefined"==typeof a?"undefined":t["typeof"](a))&&"default"in a?a["default"]:a,l=e(function(e){var t=f,r=i;e.exports={stringify:t,parse:r}}),s=l&&"object"===("undefined"==typeof l?"undefined":t["typeof"](l))&&"default"in l?l["default"]:l,u=function(){function e(){var r=arguments.length<=0||void 0===arguments[0]?"text":arguments[0],n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];t.classCallCheck(this,e),this.name="request",this.type=r,this.options=n}return t.createClass(e,[{key:"transform",value:function(e){var r=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=t["extends"]({baseUrl:"",textAs:"",defaults:{},toType:"audio"},n,this.options);return e.map(function(e){if(e.type!==r.type)return e;var n=e;if(o.beforeTransform){var i=o.beforeTransform(e,o);if(i===!1)return e;i instanceof e.constructor&&(n=i)}var a=o.method||"GET",f=n.value,l=t["extends"]({},o.defaults.data,n.options),u=o.baseUrl;o.textAs.length?l[o.textAs]=f:u+=encodeURIComponent(f);var c=t["extends"]({},o.defaults,{method:a,url:u});if(["PUT","POST","PATCH"].indexOf(a.toUpperCase())>-1)c.data=l;else{var p=s.stringify(l);c.url+=p.length?"?"+p:""}return new n.constructor(o.toType,c,{},{transformer:r})})}}]),e}();return u});
//# sourceMappingURL=index.js.map