1
+ ( function webpackUniversalModuleDefinition ( root , factory ) {
2
+ if ( typeof exports === 'object' && typeof module === 'object' )
3
+ module . exports = factory ( ) ;
4
+ else if ( typeof define === 'function' && define . amd )
5
+ define ( [ ] , factory ) ;
6
+ else if ( typeof exports === 'object' )
7
+ exports [ "kinka" ] = factory ( ) ;
8
+ else
9
+ root [ "kinka" ] = factory ( ) ;
10
+ } ) ( window , function ( ) {
11
+ return /******/ ( function ( modules ) { // webpackBootstrap
12
+ /******/ // The module cache
13
+ /******/ var installedModules = { } ;
14
+ /******/
15
+ /******/ // The require function
16
+ /******/ function __webpack_require__ ( moduleId ) {
17
+ /******/
18
+ /******/ // Check if module is in cache
19
+ /******/ if ( installedModules [ moduleId ] ) {
20
+ /******/ return installedModules [ moduleId ] . exports ;
21
+ /******/ }
22
+ /******/ // Create a new module (and put it into the cache)
23
+ /******/ var module = installedModules [ moduleId ] = {
24
+ /******/ i : moduleId ,
25
+ /******/ l : false ,
26
+ /******/ exports : { }
27
+ /******/ } ;
28
+ /******/
29
+ /******/ // Execute the module function
30
+ /******/ modules [ moduleId ] . call ( module . exports , module , module . exports , __webpack_require__ ) ;
31
+ /******/
32
+ /******/ // Flag the module as loaded
33
+ /******/ module . l = true ;
34
+ /******/
35
+ /******/ // Return the exports of the module
36
+ /******/ return module . exports ;
37
+ /******/ }
38
+ /******/
39
+ /******/
40
+ /******/ // expose the modules object (__webpack_modules__)
41
+ /******/ __webpack_require__ . m = modules ;
42
+ /******/
43
+ /******/ // expose the module cache
44
+ /******/ __webpack_require__ . c = installedModules ;
45
+ /******/
46
+ /******/ // define getter function for harmony exports
47
+ /******/ __webpack_require__ . d = function ( exports , name , getter ) {
48
+ /******/ if ( ! __webpack_require__ . o ( exports , name ) ) {
49
+ /******/ Object . defineProperty ( exports , name , { enumerable : true , get : getter } ) ;
50
+ /******/ }
51
+ /******/ } ;
52
+ /******/
53
+ /******/ // define __esModule on exports
54
+ /******/ __webpack_require__ . r = function ( exports ) {
55
+ /******/ if ( typeof Symbol !== 'undefined' && Symbol . toStringTag ) {
56
+ /******/ Object . defineProperty ( exports , Symbol . toStringTag , { value : 'Module' } ) ;
57
+ /******/ }
58
+ /******/ Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
59
+ /******/ } ;
60
+ /******/
61
+ /******/ // create a fake namespace object
62
+ /******/ // mode & 1: value is a module id, require it
63
+ /******/ // mode & 2: merge all properties of value into the ns
64
+ /******/ // mode & 4: return value when already ns object
65
+ /******/ // mode & 8|1: behave like require
66
+ /******/ __webpack_require__ . t = function ( value , mode ) {
67
+ /******/ if ( mode & 1 ) value = __webpack_require__ ( value ) ;
68
+ /******/ if ( mode & 8 ) return value ;
69
+ /******/ if ( ( mode & 4 ) && typeof value === 'object' && value && value . __esModule ) return value ;
70
+ /******/ var ns = Object . create ( null ) ;
71
+ /******/ __webpack_require__ . r ( ns ) ;
72
+ /******/ Object . defineProperty ( ns , 'default' , { enumerable : true , value : value } ) ;
73
+ /******/ if ( mode & 2 && typeof value != 'string' ) for ( var key in value ) __webpack_require__ . d ( ns , key , function ( key ) { return value [ key ] ; } . bind ( null , key ) ) ;
74
+ /******/ return ns ;
75
+ /******/ } ;
76
+ /******/
77
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
78
+ /******/ __webpack_require__ . n = function ( module ) {
79
+ /******/ var getter = module && module . __esModule ?
80
+ /******/ function getDefault ( ) { return module [ 'default' ] ; } :
81
+ /******/ function getModuleExports ( ) { return module ; } ;
82
+ /******/ __webpack_require__ . d ( getter , 'a' , getter ) ;
83
+ /******/ return getter ;
84
+ /******/ } ;
85
+ /******/
86
+ /******/ // Object.prototype.hasOwnProperty.call
87
+ /******/ __webpack_require__ . o = function ( object , property ) { return Object . prototype . hasOwnProperty . call ( object , property ) ; } ;
88
+ /******/
89
+ /******/ // __webpack_public_path__
90
+ /******/ __webpack_require__ . p = "" ;
91
+ /******/
92
+ /******/
93
+ /******/ // Load entry module and return exports
94
+ /******/ return __webpack_require__ ( __webpack_require__ . s = "./lib/kinka.js" ) ;
95
+ /******/ } )
96
+ /************************************************************************/
97
+ /******/ ( {
98
+
99
+ /***/ "./lib/helpers/base.js" :
100
+ /*!*****************************!*\
101
+ !*** ./lib/helpers/base.js ***!
102
+ \*****************************/
103
+ /*! no static exports found */
104
+ /***/ ( function ( module , exports , __webpack_require__ ) {
105
+
106
+ "use strict" ;
107
+ eval ( "\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nfunction merge() {\n var object = {};\n for (var args = [].slice.call(arguments), x = 0; x < args.length; x++) {\n if (isObject(args[x])) for (var attr in args[x]) {\n var value = args[x][attr];\n object[attr] = isObject(value) ? merge(object[attr], value) : value;\n }\n }\n return object;\n}\n\nfunction isObject(value) {\n return !!value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object';\n}\n\n// function pick(object, keys) {\n// var newObject = {}\n// for (var x in keys) newObject[keys[x]] = object[keys[x]]\n// return newObject\n// }\n\nfunction parseJSON(stringifiedData) {\n try {\n return JSON.parse(stringifiedData);\n } catch (e) {\n return stringifiedData;\n }\n}\n\nfunction isUndefined(value, defaultValue) {\n return value === undefined ? defaultValue : value;\n}\n\nmodule.exports = {\n merge: merge,\n isObject: isObject,\n // pick: pick,\n parseJSON: parseJSON,\n isUndefined: isUndefined\n};\n\n//# sourceURL=webpack://kinka/./lib/helpers/base.js?" ) ;
108
+
109
+ /***/ } ) ,
110
+
111
+ /***/ "./lib/helpers/request.js" :
112
+ /*!********************************!*\
113
+ !*** ./lib/helpers/request.js ***!
114
+ \********************************/
115
+ /*! no static exports found */
116
+ /***/ ( function ( module , exports , __webpack_require__ ) {
117
+
118
+ "use strict" ;
119
+ eval ( "\n\nvar baseHelpers = __webpack_require__(/*! ./base */ \"./lib/helpers/base.js\");\nvar createResponse = __webpack_require__(/*! ./response */ \"./lib/helpers/response.js\").createResponse;\n\nvar isObject = baseHelpers.isObject;\nvar merge = baseHelpers.merge;\n\nvar abortableRequests = {};\n\nfunction abortRequest(key) {\n if (abortableRequests[key]) {\n abortableRequests[key].abort();\n removeAbortableKey(key);\n }\n}\n\nfunction getAbortableRequest(key) {\n abortRequest(key);\n abortableRequests[key] = new XMLHttpRequest();\n return abortableRequests[key];\n}\n\nfunction removeAbortableKey(key) {\n abortableRequests[key] = null;\n delete abortableRequests[key];\n}\n\nfunction requestIsSuccess(request, specificSuccessStatus) {\n var status = request.status;\n return specificSuccessStatus ? status === specificSuccessStatus : status >= 200 && status < 300 || status === 101;\n}\n\nfunction setHeaders(request, headers) {\n var headerNames = Object.keys(headers);\n for (var x = 0; x < headerNames.length; x++) {\n request.setRequestHeader(headerNames[x], headers[headerNames[x]]);\n }\n}\n\nfunction getUrlWithQuery(url, query) {\n var parsed = url.split('?');\n var rawUrl = parsed[0];\n var queryString = parsed[1] ? [parsed[1]] : [];\n Object.keys(query).forEach(function (key) {\n queryString.push(key + '=' + encodeURIComponent(query[key]));\n });\n return rawUrl + '?' + queryString.join('&');\n}\n\nfunction getUrl(path, baseURL, query) {\n var protocol = path.slice(0, 4);\n var url = protocol === 'http' || protocol.indexOf('ws') !== -1 || protocol.indexOf('//') !== -1 ? path : baseURL + path;\n return query ? getUrlWithQuery(url, query) : url;\n}\n\nfunction createRequest(method, path, requestOptions, requestData) {\n var requestInspector = this.inspectors.request;\n var responseInspector = this.inspectors.response;\n var options = merge(this.instanceOptions, requestOptions, requestOptions && this.auth && requestOptions.auth && this.auth(requestOptions.auth));\n if (options.body) {\n console.warn('kinka warning: property \"body\" is deprecated and renamed to \"data\" in the 1.0.0 kinka release version. Please use \"data\" property.');\n options.data = options.body;\n }\n if (requestData) {\n options.data = requestData;\n }\n if (requestInspector) {\n options = requestInspector(getUrl(path, this.baseURL, options.query), method, options) || options;\n }\n var abortableKey = options.abortableKey;\n var data = options.data;\n var body = !isObject(data) || data instanceof FormData ? data : JSON.stringify(data);\n var url = getUrl(path, this.baseURL, options.query);\n var request = abortableKey ? getAbortableRequest(abortableKey) : new XMLHttpRequest();\n return new Promise(function (resolve, reject) {\n request.withCredentials = !!options.withAuth;\n request.onreadystatechange = function () {\n if (request.readyState === XMLHttpRequest.DONE) {\n var isError = !requestIsSuccess(request, options.successStatus);\n var response = createResponse(request, isError);\n if (responseInspector) {\n response = responseInspector(url, method, response) || response;\n }\n if (!options.omitCatches && isError) reject(response);else resolve(response);\n request = null;\n if (abortableKey) removeAbortableKey(abortableKey);\n }\n };\n request.open(method.toUpperCase(), url, true);\n request.timeout = options.timeout;\n if (isObject(options.headers)) setHeaders(request, options.headers);\n request.send(body);\n });\n}\n\nmodule.exports = {\n createRequest: createRequest,\n abortRequest: abortRequest\n};\n\n//# sourceURL=webpack://kinka/./lib/helpers/request.js?" ) ;
120
+
121
+ /***/ } ) ,
122
+
123
+ /***/ "./lib/helpers/response.js" :
124
+ /*!*********************************!*\
125
+ !*** ./lib/helpers/response.js ***!
126
+ \*********************************/
127
+ /*! no static exports found */
128
+ /***/ ( function ( module , exports , __webpack_require__ ) {
129
+
130
+ "use strict" ;
131
+ eval ( "\n\nvar parseJSON = __webpack_require__(/*! ./base */ \"./lib/helpers/base.js\").parseJSON;\n\nfunction createResponse(request, isError) {\n var data = request.responseText;\n var parsedData = parseJSON(data);\n return {\n data: isError ? undefined : parsedData,\n err: isError ? parsedData : undefined,\n headers: getHeaders(request),\n isError: !!isError,\n isSuccess: !isError,\n response: request.response,\n status: request.status,\n statusText: request.statusText,\n type: request.responseType\n };\n}\n\nfunction getHeaders(request) {\n return request.getAllResponseHeaders().trim().split(/[\\r\\n]+/).reduce(function (headers, line) {\n var splitChar = ': ';\n var parts = line.split(splitChar);\n headers[parts.shift()] = parts.join(splitChar);\n return headers;\n }, {});\n}\n\nmodule.exports = {\n createResponse: createResponse\n};\n\n//# sourceURL=webpack://kinka/./lib/helpers/response.js?" ) ;
132
+
133
+ /***/ } ) ,
134
+
135
+ /***/ "./lib/kinka.js" :
136
+ /*!**********************!*\
137
+ !*** ./lib/kinka.js ***!
138
+ \**********************/
139
+ /*! no static exports found */
140
+ /***/ ( function ( module , exports , __webpack_require__ ) {
141
+
142
+ "use strict" ;
143
+ eval ( "\n\n/**\n * Copyright (c) acacode, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @flow\n */\nvar baseHelpers = __webpack_require__(/*! ./helpers/base */ \"./lib/helpers/base.js\");\nvar requestHelpers = __webpack_require__(/*! ./helpers/request */ \"./lib/helpers/request.js\");\nvar isUndefined = baseHelpers.isUndefined;\n\nfunction Kinka(instanceOptions) {\n if (!instanceOptions) instanceOptions = {};\n var customMethods = instanceOptions.customMethods;\n this.baseURL = instanceOptions.baseURL || location && location.origin || '';\n this.instanceOptions = {\n omitCatches: isUndefined(instanceOptions.omitCatches, true),\n headers: isUndefined(instanceOptions.headers, {}),\n timeout: isUndefined(instanceOptions.timeout, 0)\n };\n if (customMethods) for (var i in customMethods) {\n this[customMethods[i]] = createMethodHandler(customMethods[i]);\n }this.inspectors = instanceOptions.inspectors || {};\n if (instanceOptions.auth) this.auth = instanceOptions.auth;\n}\n\nfunction createMethodHandler(methodName, hasBody) {\n return function (path, optionsOrData, data) {\n var config = hasBody ? [data, optionsOrData] : [optionsOrData];\n return this.custom(methodName, path, config[0], config[1]);\n };\n}\n\nKinka.prototype = {\n abort: requestHelpers.abortRequest,\n all: Promise.all,\n create: function create(instanceOptions) {\n return new Kinka(instanceOptions);\n },\n custom: requestHelpers.createRequest,\n delete: createMethodHandler('delete'),\n get: createMethodHandler('get'),\n head: createMethodHandler('head'),\n options: createMethodHandler('options'),\n patch: createMethodHandler('patch', true),\n post: createMethodHandler('post', true),\n put: createMethodHandler('put', true)\n};\n\nvar kinka = new Kinka();\n\nif (window) {\n window.kinka = kinka;\n}\n\nmodule.exports = kinka;\n\n//# sourceURL=webpack://kinka/./lib/kinka.js?" ) ;
144
+
145
+ /***/ } )
146
+
147
+ /******/ } ) ;
148
+ } ) ;
0 commit comments