{"version":3,"sources":["jsdelivr-header.js","/npm/jqx@0.0.2/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,aAYA,IAAI,OAAS,QAAQ,UACjB,EAAS,QAAQ,KA4CrB,SAAS,IAAK,EAAK,GAEjB,IAAI,EAAO,UAmBX,OAbyB,IAArB,UAAU,SAAc,EAAO,UAAU,IAO7C,IAAI,gBAAgB,SAAQ,SAAU,GACpC,IAAI,EAAS,EAAY,EAAK,WACR,IAAX,IAAwB,EAAK,KAAO,EACjD,IAGO,EAAE,SAAQ,SAAU,EAAS,GAGlC,OAAO,KAAK,MAAM,OAAQ,GAGzB,MAAK,SAAU,EAAM,EAAQ,GAO5B,IAAI,gBAAgB,SAAQ,SAAU,GACpC,IAAI,EAAS,EAAY,EAAM,EAAQ,QACjB,IAAX,IAAwB,EAAO,EAC5C,IAGA,EAAQ,EAGV,IAAG,SAAU,EAAO,EAAQ,GAQ1B,IAAI,gBAAgB,SAAQ,SAAU,GACpC,EAAY,EAAO,EAAQ,EAC7B,IAGA,EAAO,EAET,GAEF,GACF,CAxFA,IAAI,gBAAkB,GAEtB,IAAI,gBAAkB,GAEtB,IAAI,gBAAkB,GAEtB,IAAI,kBAAoB,WACtB,IAAI,gBAAgB,KAAK,MAAM,IAAI,gBAAiB,UACtD,EAEA,IAAI,kBAAoB,WACtB,IAAI,gBAAgB,KAAK,MAAM,IAAI,gBAAiB,UACtD,EAEA,IAAI,kBAAoB,WACtB,IAAI,gBAAgB,KAAK,MAAM,IAAI,gBAAiB,UACtD,EA4EA,OAAO,QAAU","file":"/npm/jqx@0.0.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/jqx@0.0.2/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict'\n\n/**\n* Basic ajax utility. Wraps jQuery#ajax in Q promises and provides\n* a primal API for request / response / error interceptors.\n*\n* Expects a CommonJS environment with both jQuery and Q available.\n*/\n\n/******************************* Dependencies ********************************/\n\n// Third party\nvar jQuery = require('jquery'),\n    Q      = require('q')\n\n/******************************* Interceptors ********************************/\n\n/**\n* `jqx` has three groups of interceptors:\n*     reqInterceptors\n*     resInterceptors\n*     errInterceptors\n* Success interceptors are called with the jQuery success callback arguments:\n* (data, status, jqXhr). For error interceptors, the arguments order is\n* reversed: (error, status, jqXhr), allowing for easier function reuse.\n*\n* If a success interceptor returns a non-undefined value, that value replaces\n* the previous data value. In other words, interceptors are also transformers.\n*/\n\njqx.reqInterceptors = []\n\njqx.resInterceptors = []\n\njqx.errInterceptors = []\n\njqx.addReqInterceptor = function (/* ... interceptors */) {\n  jqx.reqInterceptors.push.apply(jqx.reqInterceptors, arguments)\n}\n\njqx.addResInterceptor = function (/* ... interceptors */) {\n  jqx.resInterceptors.push.apply(jqx.resInterceptors, arguments)\n}\n\njqx.addErrInterceptor = function (/* ... interceptors */) {\n  jqx.errInterceptors.push.apply(jqx.errInterceptors, arguments)\n}\n\n/**************************** Main Ajax Function *****************************/\n\n/**\n* Wrap around the jQuery#ajax method and return a Q promise.\n*\n* Successful requests are resolved with the data value.\n* Failed requests are rejected with the error object.\n*/\n\nfunction jqx (url, opts) {\n  // Grab arguments to pass them to jQuery#ajax\n  var args = arguments\n\n  /**\n  * Figure out which of the two ways of calling jQuery#ajax is used:\n  * (url, opts) or (opts). If there's only one argument, assume it's the opts.\n  */\n  if (arguments.length === 1) opts = arguments[0]\n\n  /**\n  * Apply request interceptors in order. Each interceptor is called with\n  * one argument: the `data` attribute of the options object. If a\n  * non-undefined value is returned, it replaces the data attribute.\n  */\n  jqx.reqInterceptors.forEach(function (interceptor) {\n    var result = interceptor(opts.data)\n    if (typeof result !== 'undefined') opts.data = result\n  })\n\n  // Wrap into a Q promise\n  return Q.promise(function (resolve, reject) {\n\n    // Initiate the jQuery request\n    jQuery.ajax.apply(jQuery, args)\n\n    // Success handler\n    .then(function (data, status, jqXhr) {\n\n      /**\n      * Apply response interceptors in order. Each interceptor is called with\n      * the standard jQuery response arguments. If a non-undefined value is\n      * returned, it replaces the old data object for all subsequent callbacks.\n      */\n      jqx.resInterceptors.forEach(function (interceptor) {\n        var result = interceptor(data, status, jqXhr)\n        if (typeof result !== 'undefined') data = result\n      })\n\n      // Pass the data to the end user callback\n      resolve(data)\n\n    // Failure handler\n    }, function (jqXhr, status, error) {\n\n      /**\n      * Apply error interceptors in order. Each interceptor is called with\n      * the standard jQuery error arguments, but in reversed order:\n      * (error, status, jqXhr). No value replacement is made, although\n      * objects may be mutated by the callbacks.\n      */\n      jqx.errInterceptors.forEach(function (interceptor) {\n        interceptor(error, status, jqXhr)\n      })\n\n      // Pass the error to the end user callback\n      reject(error)\n\n    })\n\n  })\n}\n\n/********************************** Export ***********************************/\n\nmodule.exports = jqx\n"]}