diff --git a/README.md b/README.md index 59a012b5..14681cfc 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ $ npm install vue-resource ``` ### CDN -Available on [jsdelivr](https://cdn.jsdelivr.net/npm/vue-resource@1.5.0), [unpkg](https://unpkg.com/vue-resource@1.5.0) or [cdnjs](https://cdnjs.com/libraries/vue-resource). +Available on [jsdelivr](https://cdn.jsdelivr.net/npm/vue-resource@1.5.1), [unpkg](https://unpkg.com/vue-resource@1.5.1) or [cdnjs](https://cdnjs.com/libraries/vue-resource). ```html - + ``` ## Example diff --git a/bower.json b/bower.json index 3c59d306..63b3cd0b 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "vue-resource", "main": "dist/vue-resource.js", - "version": "1.5.0", + "version": "1.5.1", "description": "The HTTP client for Vue.js", "homepage": "https://github.com/pagekit/vue-resource", "license": "MIT", diff --git a/dist/vue-resource.common.js b/dist/vue-resource.common.js index 9bc863d5..27f59b6a 100644 --- a/dist/vue-resource.common.js +++ b/dist/vue-resource.common.js @@ -1,5 +1,5 @@ /*! - * vue-resource v1.5.0 + * vue-resource v1.5.1 * https://github.com/pagekit/vue-resource * Released under the MIT License. */ diff --git a/dist/vue-resource.esm.js b/dist/vue-resource.esm.js index 08303bc8..9dc07778 100644 --- a/dist/vue-resource.esm.js +++ b/dist/vue-resource.esm.js @@ -1,5 +1,5 @@ /*! - * vue-resource v1.5.0 + * vue-resource v1.5.1 * https://github.com/pagekit/vue-resource * Released under the MIT License. */ diff --git a/dist/vue-resource.js b/dist/vue-resource.js index e9dd6397..563aacd7 100644 --- a/dist/vue-resource.js +++ b/dist/vue-resource.js @@ -1,1563 +1,1563 @@ /*! - * vue-resource v1.5.0 + * vue-resource v1.5.1 * https://github.com/pagekit/vue-resource * Released under the MIT License. */ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : - typeof define === 'function' && define.amd ? define(factory) : - (global.VueResource = factory()); + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.VueResource = factory()); }(this, (function () { 'use strict'; -/** - * Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) - */ + /** + * Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) + */ -var RESOLVED = 0; -var REJECTED = 1; -var PENDING = 2; + var RESOLVED = 0; + var REJECTED = 1; + var PENDING = 2; -function Promise$1(executor) { + function Promise$1(executor) { - this.state = PENDING; - this.value = undefined; - this.deferred = []; + this.state = PENDING; + this.value = undefined; + this.deferred = []; - var promise = this; + var promise = this; - try { - executor(function (x) { - promise.resolve(x); - }, function (r) { - promise.reject(r); - }); - } catch (e) { - promise.reject(e); + try { + executor(function (x) { + promise.resolve(x); + }, function (r) { + promise.reject(r); + }); + } catch (e) { + promise.reject(e); + } } -} -Promise$1.reject = function (r) { - return new Promise$1(function (resolve, reject) { - reject(r); - }); -}; + Promise$1.reject = function (r) { + return new Promise$1(function (resolve, reject) { + reject(r); + }); + }; -Promise$1.resolve = function (x) { - return new Promise$1(function (resolve, reject) { - resolve(x); - }); -}; + Promise$1.resolve = function (x) { + return new Promise$1(function (resolve, reject) { + resolve(x); + }); + }; -Promise$1.all = function all(iterable) { - return new Promise$1(function (resolve, reject) { - var count = 0, result = []; + Promise$1.all = function all(iterable) { + return new Promise$1(function (resolve, reject) { + var count = 0, result = []; - if (iterable.length === 0) { - resolve(result); - } + if (iterable.length === 0) { + resolve(result); + } - function resolver(i) { - return function (x) { - result[i] = x; - count += 1; + function resolver(i) { + return function (x) { + result[i] = x; + count += 1; - if (count === iterable.length) { - resolve(result); - } - }; - } + if (count === iterable.length) { + resolve(result); + } + }; + } - for (var i = 0; i < iterable.length; i += 1) { - Promise$1.resolve(iterable[i]).then(resolver(i), reject); - } - }); -}; + for (var i = 0; i < iterable.length; i += 1) { + Promise$1.resolve(iterable[i]).then(resolver(i), reject); + } + }); + }; -Promise$1.race = function race(iterable) { - return new Promise$1(function (resolve, reject) { - for (var i = 0; i < iterable.length; i += 1) { - Promise$1.resolve(iterable[i]).then(resolve, reject); - } - }); -}; + Promise$1.race = function race(iterable) { + return new Promise$1(function (resolve, reject) { + for (var i = 0; i < iterable.length; i += 1) { + Promise$1.resolve(iterable[i]).then(resolve, reject); + } + }); + }; -var p = Promise$1.prototype; + var p = Promise$1.prototype; -p.resolve = function resolve(x) { - var promise = this; + p.resolve = function resolve(x) { + var promise = this; - if (promise.state === PENDING) { - if (x === promise) { - throw new TypeError('Promise settled with itself.'); - } + if (promise.state === PENDING) { + if (x === promise) { + throw new TypeError('Promise settled with itself.'); + } - var called = false; + var called = false; - try { - var then = x && x['then']; + try { + var then = x && x['then']; - if (x !== null && typeof x === 'object' && typeof then === 'function') { - then.call(x, function (x) { - if (!called) { - promise.resolve(x); - } - called = true; + if (x !== null && typeof x === 'object' && typeof then === 'function') { + then.call(x, function (x) { + if (!called) { + promise.resolve(x); + } + called = true; - }, function (r) { - if (!called) { - promise.reject(r); - } - called = true; - }); + }, function (r) { + if (!called) { + promise.reject(r); + } + called = true; + }); + return; + } + } catch (e) { + if (!called) { + promise.reject(e); + } return; } - } catch (e) { - if (!called) { - promise.reject(e); - } - return; + + promise.state = RESOLVED; + promise.value = x; + promise.notify(); } + }; - promise.state = RESOLVED; - promise.value = x; - promise.notify(); - } -}; + p.reject = function reject(reason) { + var promise = this; -p.reject = function reject(reason) { - var promise = this; + if (promise.state === PENDING) { + if (reason === promise) { + throw new TypeError('Promise settled with itself.'); + } - if (promise.state === PENDING) { - if (reason === promise) { - throw new TypeError('Promise settled with itself.'); + promise.state = REJECTED; + promise.value = reason; + promise.notify(); } + }; - promise.state = REJECTED; - promise.value = reason; - promise.notify(); - } -}; - -p.notify = function notify() { - var promise = this; - - nextTick(function () { - if (promise.state !== PENDING) { - while (promise.deferred.length) { - var deferred = promise.deferred.shift(), - onResolved = deferred[0], - onRejected = deferred[1], - resolve = deferred[2], - reject = deferred[3]; - - try { - if (promise.state === RESOLVED) { - if (typeof onResolved === 'function') { - resolve(onResolved.call(undefined, promise.value)); - } else { - resolve(promise.value); - } - } else if (promise.state === REJECTED) { - if (typeof onRejected === 'function') { - resolve(onRejected.call(undefined, promise.value)); - } else { - reject(promise.value); + p.notify = function notify() { + var promise = this; + + nextTick(function () { + if (promise.state !== PENDING) { + while (promise.deferred.length) { + var deferred = promise.deferred.shift(), + onResolved = deferred[0], + onRejected = deferred[1], + resolve = deferred[2], + reject = deferred[3]; + + try { + if (promise.state === RESOLVED) { + if (typeof onResolved === 'function') { + resolve(onResolved.call(undefined, promise.value)); + } else { + resolve(promise.value); + } + } else if (promise.state === REJECTED) { + if (typeof onRejected === 'function') { + resolve(onRejected.call(undefined, promise.value)); + } else { + reject(promise.value); + } } + } catch (e) { + reject(e); } - } catch (e) { - reject(e); } } - } - }); -}; + }); + }; -p.then = function then(onResolved, onRejected) { - var promise = this; + p.then = function then(onResolved, onRejected) { + var promise = this; - return new Promise$1(function (resolve, reject) { - promise.deferred.push([onResolved, onRejected, resolve, reject]); - promise.notify(); - }); -}; + return new Promise$1(function (resolve, reject) { + promise.deferred.push([onResolved, onRejected, resolve, reject]); + promise.notify(); + }); + }; -p.catch = function (onRejected) { - return this.then(undefined, onRejected); -}; + p.catch = function (onRejected) { + return this.then(undefined, onRejected); + }; -/** - * Promise adapter. - */ + /** + * Promise adapter. + */ + + if (typeof Promise === 'undefined') { + window.Promise = Promise$1; + } -if (typeof Promise === 'undefined') { - window.Promise = Promise$1; -} + function PromiseObj(executor, context) { -function PromiseObj(executor, context) { + if (executor instanceof Promise) { + this.promise = executor; + } else { + this.promise = new Promise(executor.bind(context)); + } - if (executor instanceof Promise) { - this.promise = executor; - } else { - this.promise = new Promise(executor.bind(context)); + this.context = context; } - this.context = context; -} + PromiseObj.all = function (iterable, context) { + return new PromiseObj(Promise.all(iterable), context); + }; -PromiseObj.all = function (iterable, context) { - return new PromiseObj(Promise.all(iterable), context); -}; + PromiseObj.resolve = function (value, context) { + return new PromiseObj(Promise.resolve(value), context); + }; -PromiseObj.resolve = function (value, context) { - return new PromiseObj(Promise.resolve(value), context); -}; + PromiseObj.reject = function (reason, context) { + return new PromiseObj(Promise.reject(reason), context); + }; + + PromiseObj.race = function (iterable, context) { + return new PromiseObj(Promise.race(iterable), context); + }; -PromiseObj.reject = function (reason, context) { - return new PromiseObj(Promise.reject(reason), context); -}; + var p$1 = PromiseObj.prototype; -PromiseObj.race = function (iterable, context) { - return new PromiseObj(Promise.race(iterable), context); -}; + p$1.bind = function (context) { + this.context = context; + return this; + }; -var p$1 = PromiseObj.prototype; + p$1.then = function (fulfilled, rejected) { -p$1.bind = function (context) { - this.context = context; - return this; -}; + if (fulfilled && fulfilled.bind && this.context) { + fulfilled = fulfilled.bind(this.context); + } -p$1.then = function (fulfilled, rejected) { + if (rejected && rejected.bind && this.context) { + rejected = rejected.bind(this.context); + } - if (fulfilled && fulfilled.bind && this.context) { - fulfilled = fulfilled.bind(this.context); - } + return new PromiseObj(this.promise.then(fulfilled, rejected), this.context); + }; - if (rejected && rejected.bind && this.context) { - rejected = rejected.bind(this.context); - } + p$1.catch = function (rejected) { - return new PromiseObj(this.promise.then(fulfilled, rejected), this.context); -}; + if (rejected && rejected.bind && this.context) { + rejected = rejected.bind(this.context); + } -p$1.catch = function (rejected) { + return new PromiseObj(this.promise.catch(rejected), this.context); + }; - if (rejected && rejected.bind && this.context) { - rejected = rejected.bind(this.context); - } + p$1.finally = function (callback) { - return new PromiseObj(this.promise.catch(rejected), this.context); -}; + return this.then(function (value) { + callback.call(this); + return value; + }, function (reason) { + callback.call(this); + return Promise.reject(reason); + } + ); + }; -p$1.finally = function (callback) { + /** + * Utility functions. + */ - return this.then(function (value) { - callback.call(this); - return value; - }, function (reason) { - callback.call(this); - return Promise.reject(reason); - } - ); -}; + var ref = {}; + var hasOwnProperty = ref.hasOwnProperty; + var ref$1 = []; + var slice = ref$1.slice; + var debug = false, ntick; -/** - * Utility functions. - */ + var inBrowser = typeof window !== 'undefined'; -var ref = {}; -var hasOwnProperty = ref.hasOwnProperty; -var ref$1 = []; -var slice = ref$1.slice; -var debug = false, ntick; + function Util (ref) { + var config = ref.config; + var nextTick = ref.nextTick; -var inBrowser = typeof window !== 'undefined'; + ntick = nextTick; + debug = config.debug || !config.silent; + } -function Util (ref) { - var config = ref.config; - var nextTick = ref.nextTick; + function warn(msg) { + if (typeof console !== 'undefined' && debug) { + console.warn('[VueResource warn]: ' + msg); + } + } - ntick = nextTick; - debug = config.debug || !config.silent; -} + function error(msg) { + if (typeof console !== 'undefined') { + console.error(msg); + } + } -function warn(msg) { - if (typeof console !== 'undefined' && debug) { - console.warn('[VueResource warn]: ' + msg); + function nextTick(cb, ctx) { + return ntick(cb, ctx); } -} -function error(msg) { - if (typeof console !== 'undefined') { - console.error(msg); + function trim(str) { + return str ? str.replace(/^\s*|\s*$/g, '') : ''; } -} -function nextTick(cb, ctx) { - return ntick(cb, ctx); -} + function trimEnd(str, chars) { -function trim(str) { - return str ? str.replace(/^\s*|\s*$/g, '') : ''; -} + if (str && chars === undefined) { + return str.replace(/\s+$/, ''); + } -function trimEnd(str, chars) { + if (!str || !chars) { + return str; + } - if (str && chars === undefined) { - return str.replace(/\s+$/, ''); + return str.replace(new RegExp(("[" + chars + "]+$")), ''); } - if (!str || !chars) { - return str; + function toLower(str) { + return str ? str.toLowerCase() : ''; } - return str.replace(new RegExp(("[" + chars + "]+$")), ''); -} - -function toLower(str) { - return str ? str.toLowerCase() : ''; -} + function toUpper(str) { + return str ? str.toUpperCase() : ''; + } -function toUpper(str) { - return str ? str.toUpperCase() : ''; -} + var isArray = Array.isArray; -var isArray = Array.isArray; + function isString(val) { + return typeof val === 'string'; + } -function isString(val) { - return typeof val === 'string'; -} + function isFunction(val) { + return typeof val === 'function'; + } -function isFunction(val) { - return typeof val === 'function'; -} + function isObject(obj) { + return obj !== null && typeof obj === 'object'; + } -function isObject(obj) { - return obj !== null && typeof obj === 'object'; -} + function isPlainObject(obj) { + return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype; + } -function isPlainObject(obj) { - return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype; -} + function isBlob(obj) { + return typeof Blob !== 'undefined' && obj instanceof Blob; + } -function isBlob(obj) { - return typeof Blob !== 'undefined' && obj instanceof Blob; -} + function isFormData(obj) { + return typeof FormData !== 'undefined' && obj instanceof FormData; + } -function isFormData(obj) { - return typeof FormData !== 'undefined' && obj instanceof FormData; -} + function when(value, fulfilled, rejected) { -function when(value, fulfilled, rejected) { + var promise = PromiseObj.resolve(value); - var promise = PromiseObj.resolve(value); + if (arguments.length < 2) { + return promise; + } - if (arguments.length < 2) { - return promise; + return promise.then(fulfilled, rejected); } - return promise.then(fulfilled, rejected); -} + function options(fn, obj, opts) { -function options(fn, obj, opts) { + opts = opts || {}; - opts = opts || {}; + if (isFunction(opts)) { + opts = opts.call(obj); + } - if (isFunction(opts)) { - opts = opts.call(obj); + return merge(fn.bind({$vm: obj, $options: opts}), fn, {$options: opts}); } - return merge(fn.bind({$vm: obj, $options: opts}), fn, {$options: opts}); -} + function each(obj, iterator) { -function each(obj, iterator) { + var i, key; - var i, key; - - if (isArray(obj)) { - for (i = 0; i < obj.length; i++) { - iterator.call(obj[i], obj[i], i); - } - } else if (isObject(obj)) { - for (key in obj) { - if (hasOwnProperty.call(obj, key)) { - iterator.call(obj[key], obj[key], key); + if (isArray(obj)) { + for (i = 0; i < obj.length; i++) { + iterator.call(obj[i], obj[i], i); + } + } else if (isObject(obj)) { + for (key in obj) { + if (hasOwnProperty.call(obj, key)) { + iterator.call(obj[key], obj[key], key); + } } } - } - return obj; -} + return obj; + } -var assign = Object.assign || _assign; + var assign = Object.assign || _assign; -function merge(target) { + function merge(target) { - var args = slice.call(arguments, 1); + var args = slice.call(arguments, 1); - args.forEach(function (source) { - _merge(target, source, true); - }); + args.forEach(function (source) { + _merge(target, source, true); + }); - return target; -} + return target; + } -function defaults(target) { + function defaults(target) { - var args = slice.call(arguments, 1); + var args = slice.call(arguments, 1); - args.forEach(function (source) { + args.forEach(function (source) { - for (var key in source) { - if (target[key] === undefined) { - target[key] = source[key]; + for (var key in source) { + if (target[key] === undefined) { + target[key] = source[key]; + } } - } - }); + }); - return target; -} + return target; + } -function _assign(target) { + function _assign(target) { - var args = slice.call(arguments, 1); + var args = slice.call(arguments, 1); - args.forEach(function (source) { - _merge(target, source); - }); + args.forEach(function (source) { + _merge(target, source); + }); - return target; -} + return target; + } -function _merge(target, source, deep) { - for (var key in source) { - if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { - if (isPlainObject(source[key]) && !isPlainObject(target[key])) { - target[key] = {}; - } - if (isArray(source[key]) && !isArray(target[key])) { - target[key] = []; + function _merge(target, source, deep) { + for (var key in source) { + if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { + if (isPlainObject(source[key]) && !isPlainObject(target[key])) { + target[key] = {}; + } + if (isArray(source[key]) && !isArray(target[key])) { + target[key] = []; + } + _merge(target[key], source[key], deep); + } else if (source[key] !== undefined) { + target[key] = source[key]; } - _merge(target[key], source[key], deep); - } else if (source[key] !== undefined) { - target[key] = source[key]; } } -} -/** - * Root Prefix Transform. - */ + /** + * Root Prefix Transform. + */ + + function root (options$$1, next) { -function root (options$$1, next) { + var url = next(options$$1); - var url = next(options$$1); + if (isString(options$$1.root) && !/^(https?:)?\//.test(url)) { + url = trimEnd(options$$1.root, '/') + '/' + url; + } - if (isString(options$$1.root) && !/^(https?:)?\//.test(url)) { - url = trimEnd(options$$1.root, '/') + '/' + url; + return url; } - return url; -} + /** + * Query Parameter Transform. + */ -/** - * Query Parameter Transform. - */ + function query (options$$1, next) { -function query (options$$1, next) { + var urlParams = Object.keys(Url.options.params), query = {}, url = next(options$$1); - var urlParams = Object.keys(Url.options.params), query = {}, url = next(options$$1); + each(options$$1.params, function (value, key) { + if (urlParams.indexOf(key) === -1) { + query[key] = value; + } + }); - each(options$$1.params, function (value, key) { - if (urlParams.indexOf(key) === -1) { - query[key] = value; - } - }); + query = Url.params(query); - query = Url.params(query); + if (query) { + url += (url.indexOf('?') == -1 ? '?' : '&') + query; + } - if (query) { - url += (url.indexOf('?') == -1 ? '?' : '&') + query; + return url; } - return url; -} + /** + * URL Template v2.0.6 (https://github.com/bramstein/url-template) + */ -/** - * URL Template v2.0.6 (https://github.com/bramstein/url-template) - */ + function expand(url, params, variables) { -function expand(url, params, variables) { + var tmpl = parse(url), expanded = tmpl.expand(params); - var tmpl = parse(url), expanded = tmpl.expand(params); + if (variables) { + variables.push.apply(variables, tmpl.vars); + } - if (variables) { - variables.push.apply(variables, tmpl.vars); + return expanded; } - return expanded; -} + function parse(template) { -function parse(template) { + var operators = ['+', '#', '.', '/', ';', '?', '&'], variables = []; - var operators = ['+', '#', '.', '/', ';', '?', '&'], variables = []; + return { + vars: variables, + expand: function expand(context) { + return template.replace(/\{([^{}]+)\}|([^{}]+)/g, function (_, expression, literal) { + if (expression) { - return { - vars: variables, - expand: function expand(context) { - return template.replace(/\{([^{}]+)\}|([^{}]+)/g, function (_, expression, literal) { - if (expression) { + var operator = null, values = []; - var operator = null, values = []; + if (operators.indexOf(expression.charAt(0)) !== -1) { + operator = expression.charAt(0); + expression = expression.substr(1); + } - if (operators.indexOf(expression.charAt(0)) !== -1) { - operator = expression.charAt(0); - expression = expression.substr(1); - } + expression.split(/,/g).forEach(function (variable) { + var tmp = /([^:*]*)(?::(\d+)|(\*))?/.exec(variable); + values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3])); + variables.push(tmp[1]); + }); - expression.split(/,/g).forEach(function (variable) { - var tmp = /([^:*]*)(?::(\d+)|(\*))?/.exec(variable); - values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3])); - variables.push(tmp[1]); - }); + if (operator && operator !== '+') { - if (operator && operator !== '+') { + var separator = ','; - var separator = ','; + if (operator === '?') { + separator = '&'; + } else if (operator !== '#') { + separator = operator; + } - if (operator === '?') { - separator = '&'; - } else if (operator !== '#') { - separator = operator; + return (values.length !== 0 ? operator : '') + values.join(separator); + } else { + return values.join(','); } - return (values.length !== 0 ? operator : '') + values.join(separator); } else { - return values.join(','); + return encodeReserved(literal); } + }); + } + }; + } - } else { - return encodeReserved(literal); - } - }); - } - }; -} - -function getValues(context, operator, key, modifier) { - - var value = context[key], result = []; + function getValues(context, operator, key, modifier) { - if (isDefined(value) && value !== '') { - if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { - value = value.toString(); + var value = context[key], result = []; - if (modifier && modifier !== '*') { - value = value.substring(0, parseInt(modifier, 10)); - } + if (isDefined(value) && value !== '') { + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { + value = value.toString(); - result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); - } else { - if (modifier === '*') { - if (Array.isArray(value)) { - value.filter(isDefined).forEach(function (value) { - result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); - }); - } else { - Object.keys(value).forEach(function (k) { - if (isDefined(value[k])) { - result.push(encodeValue(operator, value[k], k)); - } - }); + if (modifier && modifier !== '*') { + value = value.substring(0, parseInt(modifier, 10)); } - } else { - var tmp = []; - if (Array.isArray(value)) { - value.filter(isDefined).forEach(function (value) { - tmp.push(encodeValue(operator, value)); - }); + result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); + } else { + if (modifier === '*') { + if (Array.isArray(value)) { + value.filter(isDefined).forEach(function (value) { + result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); + }); + } else { + Object.keys(value).forEach(function (k) { + if (isDefined(value[k])) { + result.push(encodeValue(operator, value[k], k)); + } + }); + } } else { - Object.keys(value).forEach(function (k) { - if (isDefined(value[k])) { - tmp.push(encodeURIComponent(k)); - tmp.push(encodeValue(operator, value[k].toString())); - } - }); - } + var tmp = []; + + if (Array.isArray(value)) { + value.filter(isDefined).forEach(function (value) { + tmp.push(encodeValue(operator, value)); + }); + } else { + Object.keys(value).forEach(function (k) { + if (isDefined(value[k])) { + tmp.push(encodeURIComponent(k)); + tmp.push(encodeValue(operator, value[k].toString())); + } + }); + } - if (isKeyOperator(operator)) { - result.push(encodeURIComponent(key) + '=' + tmp.join(',')); - } else if (tmp.length !== 0) { - result.push(tmp.join(',')); + if (isKeyOperator(operator)) { + result.push(encodeURIComponent(key) + '=' + tmp.join(',')); + } else if (tmp.length !== 0) { + result.push(tmp.join(',')); + } } } + } else { + if (operator === ';') { + result.push(encodeURIComponent(key)); + } else if (value === '' && (operator === '&' || operator === '?')) { + result.push(encodeURIComponent(key) + '='); + } else if (value === '') { + result.push(''); + } } - } else { - if (operator === ';') { - result.push(encodeURIComponent(key)); - } else if (value === '' && (operator === '&' || operator === '?')) { - result.push(encodeURIComponent(key) + '='); - } else if (value === '') { - result.push(''); - } + + return result; } - return result; -} + function isDefined(value) { + return value !== undefined && value !== null; + } -function isDefined(value) { - return value !== undefined && value !== null; -} + function isKeyOperator(operator) { + return operator === ';' || operator === '&' || operator === '?'; + } -function isKeyOperator(operator) { - return operator === ';' || operator === '&' || operator === '?'; -} + function encodeValue(operator, value, key) { -function encodeValue(operator, value, key) { + value = (operator === '+' || operator === '#') ? encodeReserved(value) : encodeURIComponent(value); - value = (operator === '+' || operator === '#') ? encodeReserved(value) : encodeURIComponent(value); + if (key) { + return encodeURIComponent(key) + '=' + value; + } else { + return value; + } + } - if (key) { - return encodeURIComponent(key) + '=' + value; - } else { - return value; + function encodeReserved(str) { + return str.split(/(%[0-9A-Fa-f]{2})/g).map(function (part) { + if (!/%[0-9A-Fa-f]/.test(part)) { + part = encodeURI(part); + } + return part; + }).join(''); } -} -function encodeReserved(str) { - return str.split(/(%[0-9A-Fa-f]{2})/g).map(function (part) { - if (!/%[0-9A-Fa-f]/.test(part)) { - part = encodeURI(part); - } - return part; - }).join(''); -} + /** + * URL Template (RFC 6570) Transform. + */ -/** - * URL Template (RFC 6570) Transform. - */ + function template (options) { -function template (options) { + var variables = [], url = expand(options.url, options.params, variables); - var variables = [], url = expand(options.url, options.params, variables); + variables.forEach(function (key) { + delete options.params[key]; + }); - variables.forEach(function (key) { - delete options.params[key]; - }); + return url; + } - return url; -} + /** + * Service for URL templating. + */ -/** - * Service for URL templating. - */ + function Url(url, params) { -function Url(url, params) { + var self = this || {}, options$$1 = url, transform; - var self = this || {}, options$$1 = url, transform; + if (isString(url)) { + options$$1 = {url: url, params: params}; + } - if (isString(url)) { - options$$1 = {url: url, params: params}; - } + options$$1 = merge({}, Url.options, self.$options, options$$1); - options$$1 = merge({}, Url.options, self.$options, options$$1); + Url.transforms.forEach(function (handler) { - Url.transforms.forEach(function (handler) { + if (isString(handler)) { + handler = Url.transform[handler]; + } - if (isString(handler)) { - handler = Url.transform[handler]; - } + if (isFunction(handler)) { + transform = factory(handler, transform, self.$vm); + } - if (isFunction(handler)) { - transform = factory(handler, transform, self.$vm); - } + }); - }); + return transform(options$$1); + } - return transform(options$$1); -} + /** + * Url options. + */ -/** - * Url options. - */ + Url.options = { + url: '', + root: null, + params: {} + }; -Url.options = { - url: '', - root: null, - params: {} -}; + /** + * Url transforms. + */ -/** - * Url transforms. - */ + Url.transform = {template: template, query: query, root: root}; + Url.transforms = ['template', 'query', 'root']; -Url.transform = {template: template, query: query, root: root}; -Url.transforms = ['template', 'query', 'root']; + /** + * Encodes a Url parameter string. + * + * @param {Object} obj + */ -/** - * Encodes a Url parameter string. - * - * @param {Object} obj - */ + Url.params = function (obj) { -Url.params = function (obj) { + var params = [], escape = encodeURIComponent; - var params = [], escape = encodeURIComponent; + params.add = function (key, value) { - params.add = function (key, value) { + if (isFunction(value)) { + value = value(); + } - if (isFunction(value)) { - value = value(); - } + if (value === null) { + value = ''; + } - if (value === null) { - value = ''; - } + this.push(escape(key) + '=' + escape(value)); + }; - this.push(escape(key) + '=' + escape(value)); - }; + serialize(params, obj); - serialize(params, obj); + return params.join('&').replace(/%20/g, '+'); + }; - return params.join('&').replace(/%20/g, '+'); -}; + /** + * Parse a URL and return its components. + * + * @param {String} url + */ -/** - * Parse a URL and return its components. - * - * @param {String} url - */ + Url.parse = function (url) { -Url.parse = function (url) { + var el = document.createElement('a'); - var el = document.createElement('a'); + if (document.documentMode) { + el.href = url; + url = el.href; + } - if (document.documentMode) { el.href = url; - url = el.href; - } - el.href = url; - - return { - href: el.href, - protocol: el.protocol ? el.protocol.replace(/:$/, '') : '', - port: el.port, - host: el.host, - hostname: el.hostname, - pathname: el.pathname.charAt(0) === '/' ? el.pathname : '/' + el.pathname, - search: el.search ? el.search.replace(/^\?/, '') : '', - hash: el.hash ? el.hash.replace(/^#/, '') : '' + return { + href: el.href, + protocol: el.protocol ? el.protocol.replace(/:$/, '') : '', + port: el.port, + host: el.host, + hostname: el.hostname, + pathname: el.pathname.charAt(0) === '/' ? el.pathname : '/' + el.pathname, + search: el.search ? el.search.replace(/^\?/, '') : '', + hash: el.hash ? el.hash.replace(/^#/, '') : '' + }; }; -}; -function factory(handler, next, vm) { - return function (options$$1) { - return handler.call(vm, options$$1, next); - }; -} + function factory(handler, next, vm) { + return function (options$$1) { + return handler.call(vm, options$$1, next); + }; + } -function serialize(params, obj, scope) { + function serialize(params, obj, scope) { - var array = isArray(obj), plain = isPlainObject(obj), hash; + var array = isArray(obj), plain = isPlainObject(obj), hash; - each(obj, function (value, key) { + each(obj, function (value, key) { - hash = isObject(value) || isArray(value); + hash = isObject(value) || isArray(value); - if (scope) { - key = scope + '[' + (plain || hash ? key : '') + ']'; - } + if (scope) { + key = scope + '[' + (plain || hash ? key : '') + ']'; + } - if (!scope && array) { - params.add(value.name, value.value); - } else if (hash) { - serialize(params, value, key); - } else { - params.add(key, value); - } - }); -} + if (!scope && array) { + params.add(value.name, value.value); + } else if (hash) { + serialize(params, value, key); + } else { + params.add(key, value); + } + }); + } -/** - * XDomain client (Internet Explorer). - */ + /** + * XDomain client (Internet Explorer). + */ -function xdrClient (request) { - return new PromiseObj(function (resolve) { + function xdrClient (request) { + return new PromiseObj(function (resolve) { - var xdr = new XDomainRequest(), handler = function (ref) { - var type = ref.type; + var xdr = new XDomainRequest(), handler = function (ref) { + var type = ref.type; - var status = 0; + var status = 0; - if (type === 'load') { - status = 200; - } else if (type === 'error') { - status = 500; - } + if (type === 'load') { + status = 200; + } else if (type === 'error') { + status = 500; + } - resolve(request.respondWith(xdr.responseText, {status: status})); - }; + resolve(request.respondWith(xdr.responseText, {status: status})); + }; - request.abort = function () { return xdr.abort(); }; + request.abort = function () { return xdr.abort(); }; - xdr.open(request.method, request.getUrl()); + xdr.open(request.method, request.getUrl()); - if (request.timeout) { - xdr.timeout = request.timeout; - } + if (request.timeout) { + xdr.timeout = request.timeout; + } - xdr.onload = handler; - xdr.onabort = handler; - xdr.onerror = handler; - xdr.ontimeout = handler; - xdr.onprogress = function () {}; - xdr.send(request.getBody()); - }); -} + xdr.onload = handler; + xdr.onabort = handler; + xdr.onerror = handler; + xdr.ontimeout = handler; + xdr.onprogress = function () {}; + xdr.send(request.getBody()); + }); + } -/** - * CORS Interceptor. - */ + /** + * CORS Interceptor. + */ -var SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest(); + var SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest(); -function cors (request) { + function cors (request) { - if (inBrowser) { + if (inBrowser) { - var orgUrl = Url.parse(location.href); - var reqUrl = Url.parse(request.getUrl()); + var orgUrl = Url.parse(location.href); + var reqUrl = Url.parse(request.getUrl()); - if (reqUrl.protocol !== orgUrl.protocol || reqUrl.host !== orgUrl.host) { + if (reqUrl.protocol !== orgUrl.protocol || reqUrl.host !== orgUrl.host) { - request.crossOrigin = true; - request.emulateHTTP = false; + request.crossOrigin = true; + request.emulateHTTP = false; - if (!SUPPORTS_CORS) { - request.client = xdrClient; + if (!SUPPORTS_CORS) { + request.client = xdrClient; + } } } + } -} + /** + * Form data Interceptor. + */ -/** - * Form data Interceptor. - */ + function form (request) { -function form (request) { + if (isFormData(request.body)) { + request.headers.delete('Content-Type'); + } else if (isObject(request.body) && request.emulateJSON) { + request.body = Url.params(request.body); + request.headers.set('Content-Type', 'application/x-www-form-urlencoded'); + } - if (isFormData(request.body)) { - request.headers.delete('Content-Type'); - } else if (isObject(request.body) && request.emulateJSON) { - request.body = Url.params(request.body); - request.headers.set('Content-Type', 'application/x-www-form-urlencoded'); } -} + /** + * JSON Interceptor. + */ -/** - * JSON Interceptor. - */ + function json (request) { -function json (request) { + var type = request.headers.get('Content-Type') || ''; - var type = request.headers.get('Content-Type') || ''; + if (isObject(request.body) && type.indexOf('application/json') === 0) { + request.body = JSON.stringify(request.body); + } - if (isObject(request.body) && type.indexOf('application/json') === 0) { - request.body = JSON.stringify(request.body); - } + return function (response) { - return function (response) { + return response.bodyText ? when(response.text(), function (text) { - return response.bodyText ? when(response.text(), function (text) { + var type = response.headers.get('Content-Type') || ''; - var type = response.headers.get('Content-Type') || ''; + if (type.indexOf('application/json') === 0 || isJson(text)) { - if (type.indexOf('application/json') === 0 || isJson(text)) { + try { + response.body = JSON.parse(text); + } catch (e) { + response.body = null; + } - try { - response.body = JSON.parse(text); - } catch (e) { - response.body = null; + } else { + response.body = text; } - } else { - response.body = text; - } + return response; - return response; + }) : response; - }) : response; + }; + } - }; -} + function isJson(str) { -function isJson(str) { + var start = str.match(/^\s*(\[|\{)/); + var end = {'[': /]\s*$/, '{': /}\s*$/}; - var start = str.match(/^\s*(\[|\{)/); - var end = {'[': /]\s*$/, '{': /}\s*$/}; + return start && end[start[1]].test(str); + } - return start && end[start[1]].test(str); -} + /** + * JSONP client (Browser). + */ -/** - * JSONP client (Browser). - */ + function jsonpClient (request) { + return new PromiseObj(function (resolve) { -function jsonpClient (request) { - return new PromiseObj(function (resolve) { + var name = request.jsonp || 'callback', callback = request.jsonpCallback || '_jsonp' + Math.random().toString(36).substr(2), body = null, handler, script; - var name = request.jsonp || 'callback', callback = request.jsonpCallback || '_jsonp' + Math.random().toString(36).substr(2), body = null, handler, script; + handler = function (ref) { + var type = ref.type; - handler = function (ref) { - var type = ref.type; + var status = 0; - var status = 0; + if (type === 'load' && body !== null) { + status = 200; + } else if (type === 'error') { + status = 500; + } - if (type === 'load' && body !== null) { - status = 200; - } else if (type === 'error') { - status = 500; - } + if (status && window[callback]) { + delete window[callback]; + document.body.removeChild(script); + } - if (status && window[callback]) { - delete window[callback]; - document.body.removeChild(script); - } + resolve(request.respondWith(body, {status: status})); + }; - resolve(request.respondWith(body, {status: status})); - }; + window[callback] = function (result) { + body = JSON.stringify(result); + }; - window[callback] = function (result) { - body = JSON.stringify(result); - }; + request.abort = function () { + handler({type: 'abort'}); + }; - request.abort = function () { - handler({type: 'abort'}); - }; + request.params[name] = callback; - request.params[name] = callback; + if (request.timeout) { + setTimeout(request.abort, request.timeout); + } - if (request.timeout) { - setTimeout(request.abort, request.timeout); - } + script = document.createElement('script'); + script.src = request.getUrl(); + script.type = 'text/javascript'; + script.async = true; + script.onload = handler; + script.onerror = handler; - script = document.createElement('script'); - script.src = request.getUrl(); - script.type = 'text/javascript'; - script.async = true; - script.onload = handler; - script.onerror = handler; + document.body.appendChild(script); + }); + } - document.body.appendChild(script); - }); -} + /** + * JSONP Interceptor. + */ -/** - * JSONP Interceptor. - */ + function jsonp (request) { -function jsonp (request) { + if (request.method == 'JSONP') { + request.client = jsonpClient; + } - if (request.method == 'JSONP') { - request.client = jsonpClient; } -} + /** + * Before Interceptor. + */ -/** - * Before Interceptor. - */ + function before (request) { -function before (request) { + if (isFunction(request.before)) { + request.before.call(this, request); + } - if (isFunction(request.before)) { - request.before.call(this, request); } -} + /** + * HTTP method override Interceptor. + */ -/** - * HTTP method override Interceptor. - */ + function method (request) { -function method (request) { + if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { + request.headers.set('X-HTTP-Method-Override', request.method); + request.method = 'POST'; + } - if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { - request.headers.set('X-HTTP-Method-Override', request.method); - request.method = 'POST'; } -} + /** + * Header Interceptor. + */ -/** - * Header Interceptor. - */ + function header (request) { -function header (request) { + var headers = assign({}, Http.headers.common, + !request.crossOrigin ? Http.headers.custom : {}, + Http.headers[toLower(request.method)] + ); - var headers = assign({}, Http.headers.common, - !request.crossOrigin ? Http.headers.custom : {}, - Http.headers[toLower(request.method)] - ); + each(headers, function (value, name) { + if (!request.headers.has(name)) { + request.headers.set(name, value); + } + }); - each(headers, function (value, name) { - if (!request.headers.has(name)) { - request.headers.set(name, value); - } - }); + } -} + /** + * XMLHttp client (Browser). + */ -/** - * XMLHttp client (Browser). - */ + function xhrClient (request) { + return new PromiseObj(function (resolve) { -function xhrClient (request) { - return new PromiseObj(function (resolve) { + var xhr = new XMLHttpRequest(), handler = function (event) { - var xhr = new XMLHttpRequest(), handler = function (event) { + var response = request.respondWith( + 'response' in xhr ? xhr.response : xhr.responseText, { + status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug + statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText) + }); - var response = request.respondWith( - 'response' in xhr ? xhr.response : xhr.responseText, { - status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug - statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText) - }); + each(trim(xhr.getAllResponseHeaders()).split('\n'), function (row) { + response.headers.append(row.slice(0, row.indexOf(':')), row.slice(row.indexOf(':') + 1)); + }); - each(trim(xhr.getAllResponseHeaders()).split('\n'), function (row) { - response.headers.append(row.slice(0, row.indexOf(':')), row.slice(row.indexOf(':') + 1)); - }); + resolve(response); + }; - resolve(response); - }; + request.abort = function () { return xhr.abort(); }; - request.abort = function () { return xhr.abort(); }; + xhr.open(request.method, request.getUrl(), true); - xhr.open(request.method, request.getUrl(), true); + if (request.timeout) { + xhr.timeout = request.timeout; + } - if (request.timeout) { - xhr.timeout = request.timeout; - } + if (request.responseType && 'responseType' in xhr) { + xhr.responseType = request.responseType; + } - if (request.responseType && 'responseType' in xhr) { - xhr.responseType = request.responseType; - } + if (request.withCredentials || request.credentials) { + xhr.withCredentials = true; + } - if (request.withCredentials || request.credentials) { - xhr.withCredentials = true; - } + if (!request.crossOrigin) { + request.headers.set('X-Requested-With', 'XMLHttpRequest'); + } - if (!request.crossOrigin) { - request.headers.set('X-Requested-With', 'XMLHttpRequest'); - } + // deprecated use downloadProgress + if (isFunction(request.progress) && request.method === 'GET') { + xhr.addEventListener('progress', request.progress); + } - // deprecated use downloadProgress - if (isFunction(request.progress) && request.method === 'GET') { - xhr.addEventListener('progress', request.progress); - } + if (isFunction(request.downloadProgress)) { + xhr.addEventListener('progress', request.downloadProgress); + } - if (isFunction(request.downloadProgress)) { - xhr.addEventListener('progress', request.downloadProgress); - } + // deprecated use uploadProgress + if (isFunction(request.progress) && /^(POST|PUT)$/i.test(request.method)) { + xhr.upload.addEventListener('progress', request.progress); + } - // deprecated use uploadProgress - if (isFunction(request.progress) && /^(POST|PUT)$/i.test(request.method)) { - xhr.upload.addEventListener('progress', request.progress); - } + if (isFunction(request.uploadProgress) && xhr.upload) { + xhr.upload.addEventListener('progress', request.uploadProgress); + } - if (isFunction(request.uploadProgress) && xhr.upload) { - xhr.upload.addEventListener('progress', request.uploadProgress); - } + request.headers.forEach(function (value, name) { + xhr.setRequestHeader(name, value); + }); - request.headers.forEach(function (value, name) { - xhr.setRequestHeader(name, value); + xhr.onload = handler; + xhr.onabort = handler; + xhr.onerror = handler; + xhr.ontimeout = handler; + xhr.send(request.getBody()); }); + } - xhr.onload = handler; - xhr.onabort = handler; - xhr.onerror = handler; - xhr.ontimeout = handler; - xhr.send(request.getBody()); - }); -} + /** + * Http client (Node). + */ -/** - * Http client (Node). - */ + function nodeClient (request) { -function nodeClient (request) { + var client = require('got'); - var client = require('got'); + return new PromiseObj(function (resolve) { - return new PromiseObj(function (resolve) { + var url = request.getUrl(); + var body = request.getBody(); + var method = request.method; + var headers = {}, handler; - var url = request.getUrl(); - var body = request.getBody(); - var method = request.method; - var headers = {}, handler; + request.headers.forEach(function (value, name) { + headers[name] = value; + }); - request.headers.forEach(function (value, name) { - headers[name] = value; - }); + client(url, {body: body, method: method, headers: headers}).then(handler = function (resp) { - client(url, {body: body, method: method, headers: headers}).then(handler = function (resp) { + var response = request.respondWith(resp.body, { + status: resp.statusCode, + statusText: trim(resp.statusMessage) + }); - var response = request.respondWith(resp.body, { - status: resp.statusCode, - statusText: trim(resp.statusMessage) - }); + each(resp.headers, function (value, name) { + response.headers.set(name, value); + }); - each(resp.headers, function (value, name) { - response.headers.set(name, value); - }); + resolve(response); - resolve(response); + }, function (error$$1) { return handler(error$$1.response); }); + }); + } - }, function (error$$1) { return handler(error$$1.response); }); - }); -} + /** + * Base client. + */ -/** - * Base client. - */ + function Client (context) { -function Client (context) { + var reqHandlers = [sendRequest], resHandlers = []; - var reqHandlers = [sendRequest], resHandlers = []; + if (!isObject(context)) { + context = null; + } - if (!isObject(context)) { - context = null; - } + function Client(request) { + while (reqHandlers.length) { - function Client(request) { - while (reqHandlers.length) { + var handler = reqHandlers.pop(); - var handler = reqHandlers.pop(); + if (isFunction(handler)) { - if (isFunction(handler)) { + var response = (void 0), next = (void 0); - var response = (void 0), next = (void 0); + response = handler.call(context, request, function (val) { return next = val; }) || next; - response = handler.call(context, request, function (val) { return next = val; }) || next; + if (isObject(response)) { + return new PromiseObj(function (resolve, reject) { - if (isObject(response)) { - return new PromiseObj(function (resolve, reject) { + resHandlers.forEach(function (handler) { + response = when(response, function (response) { + return handler.call(context, response) || response; + }, reject); + }); - resHandlers.forEach(function (handler) { - response = when(response, function (response) { - return handler.call(context, response) || response; - }, reject); - }); + when(response, resolve, reject); - when(response, resolve, reject); + }, context); + } - }, context); - } + if (isFunction(response)) { + resHandlers.unshift(response); + } - if (isFunction(response)) { - resHandlers.unshift(response); + } else { + warn(("Invalid interceptor of type " + (typeof handler) + ", must be a function")); } - - } else { - warn(("Invalid interceptor of type " + (typeof handler) + ", must be a function")); } } - } - Client.use = function (handler) { - reqHandlers.push(handler); - }; + Client.use = function (handler) { + reqHandlers.push(handler); + }; - return Client; -} + return Client; + } -function sendRequest(request) { + function sendRequest(request) { - var client = request.client || (inBrowser ? xhrClient : nodeClient); + var client = request.client || (inBrowser ? xhrClient : nodeClient); - return client(request); -} + return client(request); + } -/** - * HTTP Headers. - */ + /** + * HTTP Headers. + */ -var Headers = function Headers(headers) { - var this$1 = this; + var Headers = function Headers(headers) { + var this$1 = this; - this.map = {}; + this.map = {}; - each(headers, function (value, name) { return this$1.append(name, value); }); -}; + each(headers, function (value, name) { return this$1.append(name, value); }); + }; -Headers.prototype.has = function has (name) { - return getName(this.map, name) !== null; -}; + Headers.prototype.has = function has (name) { + return getName(this.map, name) !== null; + }; -Headers.prototype.get = function get (name) { + Headers.prototype.get = function get (name) { - var list = this.map[getName(this.map, name)]; + var list = this.map[getName(this.map, name)]; - return list ? list.join() : null; -}; + return list ? list.join() : null; + }; -Headers.prototype.getAll = function getAll (name) { - return this.map[getName(this.map, name)] || []; -}; + Headers.prototype.getAll = function getAll (name) { + return this.map[getName(this.map, name)] || []; + }; -Headers.prototype.set = function set (name, value) { - this.map[normalizeName(getName(this.map, name) || name)] = [trim(value)]; -}; + Headers.prototype.set = function set (name, value) { + this.map[normalizeName(getName(this.map, name) || name)] = [trim(value)]; + }; -Headers.prototype.append = function append (name, value) { + Headers.prototype.append = function append (name, value) { - var list = this.map[getName(this.map, name)]; + var list = this.map[getName(this.map, name)]; - if (list) { - list.push(trim(value)); - } else { - this.set(name, value); - } -}; + if (list) { + list.push(trim(value)); + } else { + this.set(name, value); + } + }; -Headers.prototype.delete = function delete$1 (name) { - delete this.map[getName(this.map, name)]; -}; + Headers.prototype.delete = function delete$1 (name) { + delete this.map[getName(this.map, name)]; + }; -Headers.prototype.deleteAll = function deleteAll () { - this.map = {}; -}; + Headers.prototype.deleteAll = function deleteAll () { + this.map = {}; + }; -Headers.prototype.forEach = function forEach (callback, thisArg) { - var this$1 = this; + Headers.prototype.forEach = function forEach (callback, thisArg) { + var this$1 = this; - each(this.map, function (list, name) { - each(list, function (value) { return callback.call(thisArg, value, name, this$1); }); - }); -}; + each(this.map, function (list, name) { + each(list, function (value) { return callback.call(thisArg, value, name, this$1); }); + }); + }; -function getName(map, name) { - return Object.keys(map).reduce(function (prev, curr) { - return toLower(name) === toLower(curr) ? curr : prev; - }, null); -} + function getName(map, name) { + return Object.keys(map).reduce(function (prev, curr) { + return toLower(name) === toLower(curr) ? curr : prev; + }, null); + } -function normalizeName(name) { + function normalizeName(name) { - if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) { - throw new TypeError('Invalid character in header field name'); - } + if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) { + throw new TypeError('Invalid character in header field name'); + } - return trim(name); -} + return trim(name); + } -/** - * HTTP Response. - */ + /** + * HTTP Response. + */ -var Response = function Response(body, ref) { - var url = ref.url; - var headers = ref.headers; - var status = ref.status; - var statusText = ref.statusText; + var Response = function Response(body, ref) { + var url = ref.url; + var headers = ref.headers; + var status = ref.status; + var statusText = ref.statusText; - this.url = url; - this.ok = status >= 200 && status < 300; - this.status = status || 0; - this.statusText = statusText || ''; - this.headers = new Headers(headers); - this.body = body; + this.url = url; + this.ok = status >= 200 && status < 300; + this.status = status || 0; + this.statusText = statusText || ''; + this.headers = new Headers(headers); + this.body = body; - if (isString(body)) { + if (isString(body)) { - this.bodyText = body; + this.bodyText = body; - } else if (isBlob(body)) { + } else if (isBlob(body)) { - this.bodyBlob = body; + this.bodyBlob = body; - if (isBlobText(body)) { - this.bodyText = blobText(body); + if (isBlobText(body)) { + this.bodyText = blobText(body); + } } - } -}; + }; -Response.prototype.blob = function blob () { - return when(this.bodyBlob); -}; + Response.prototype.blob = function blob () { + return when(this.bodyBlob); + }; -Response.prototype.text = function text () { - return when(this.bodyText); -}; + Response.prototype.text = function text () { + return when(this.bodyText); + }; -Response.prototype.json = function json () { - return when(this.text(), function (text) { return JSON.parse(text); }); -}; + Response.prototype.json = function json () { + return when(this.text(), function (text) { return JSON.parse(text); }); + }; -Object.defineProperty(Response.prototype, 'data', { + Object.defineProperty(Response.prototype, 'data', { - get: function get() { - return this.body; - }, + get: function get() { + return this.body; + }, - set: function set(body) { - this.body = body; - } + set: function set(body) { + this.body = body; + } -}); + }); -function blobText(body) { - return new PromiseObj(function (resolve) { + function blobText(body) { + return new PromiseObj(function (resolve) { - var reader = new FileReader(); + var reader = new FileReader(); - reader.readAsText(body); - reader.onload = function () { - resolve(reader.result); - }; + reader.readAsText(body); + reader.onload = function () { + resolve(reader.result); + }; - }); -} + }); + } -function isBlobText(body) { - return body.type.indexOf('text') === 0 || body.type.indexOf('json') !== -1; -} + function isBlobText(body) { + return body.type.indexOf('text') === 0 || body.type.indexOf('json') !== -1; + } -/** - * HTTP Request. - */ + /** + * HTTP Request. + */ -var Request = function Request(options$$1) { + var Request = function Request(options$$1) { - this.body = null; - this.params = {}; + this.body = null; + this.params = {}; - assign(this, options$$1, { - method: toUpper(options$$1.method || 'GET') - }); + assign(this, options$$1, { + method: toUpper(options$$1.method || 'GET') + }); - if (!(this.headers instanceof Headers)) { - this.headers = new Headers(this.headers); - } -}; + if (!(this.headers instanceof Headers)) { + this.headers = new Headers(this.headers); + } + }; -Request.prototype.getUrl = function getUrl () { - return Url(this); -}; + Request.prototype.getUrl = function getUrl () { + return Url(this); + }; -Request.prototype.getBody = function getBody () { - return this.body; -}; + Request.prototype.getBody = function getBody () { + return this.body; + }; -Request.prototype.respondWith = function respondWith (body, options$$1) { - return new Response(body, assign(options$$1 || {}, {url: this.getUrl()})); -}; + Request.prototype.respondWith = function respondWith (body, options$$1) { + return new Response(body, assign(options$$1 || {}, {url: this.getUrl()})); + }; -/** - * Service for sending network requests. - */ + /** + * Service for sending network requests. + */ -var COMMON_HEADERS = {'Accept': 'application/json, text/plain, */*'}; -var JSON_CONTENT_TYPE = {'Content-Type': 'application/json;charset=utf-8'}; + var COMMON_HEADERS = {'Accept': 'application/json, text/plain, */*'}; + var JSON_CONTENT_TYPE = {'Content-Type': 'application/json;charset=utf-8'}; -function Http(options$$1) { + function Http(options$$1) { - var self = this || {}, client = Client(self.$vm); + var self = this || {}, client = Client(self.$vm); - defaults(options$$1 || {}, self.$options, Http.options); + defaults(options$$1 || {}, self.$options, Http.options); - Http.interceptors.forEach(function (handler) { + Http.interceptors.forEach(function (handler) { - if (isString(handler)) { - handler = Http.interceptor[handler]; - } + if (isString(handler)) { + handler = Http.interceptor[handler]; + } - if (isFunction(handler)) { - client.use(handler); - } + if (isFunction(handler)) { + client.use(handler); + } - }); + }); - return client(new Request(options$$1)).then(function (response) { + return client(new Request(options$$1)).then(function (response) { - return response.ok ? response : PromiseObj.reject(response); + return response.ok ? response : PromiseObj.reject(response); - }, function (response) { + }, function (response) { - if (response instanceof Error) { - error(response); - } + if (response instanceof Error) { + error(response); + } - return PromiseObj.reject(response); - }); -} + return PromiseObj.reject(response); + }); + } -Http.options = {}; + Http.options = {}; -Http.headers = { - put: JSON_CONTENT_TYPE, - post: JSON_CONTENT_TYPE, - patch: JSON_CONTENT_TYPE, - delete: JSON_CONTENT_TYPE, - common: COMMON_HEADERS, - custom: {} -}; + Http.headers = { + put: JSON_CONTENT_TYPE, + post: JSON_CONTENT_TYPE, + patch: JSON_CONTENT_TYPE, + delete: JSON_CONTENT_TYPE, + common: COMMON_HEADERS, + custom: {} + }; -Http.interceptor = {before: before, method: method, jsonp: jsonp, json: json, form: form, header: header, cors: cors}; -Http.interceptors = ['before', 'method', 'jsonp', 'json', 'form', 'header', 'cors']; + Http.interceptor = {before: before, method: method, jsonp: jsonp, json: json, form: form, header: header, cors: cors}; + Http.interceptors = ['before', 'method', 'jsonp', 'json', 'form', 'header', 'cors']; -['get', 'delete', 'head', 'jsonp'].forEach(function (method$$1) { + ['get', 'delete', 'head', 'jsonp'].forEach(function (method$$1) { - Http[method$$1] = function (url, options$$1) { - return this(assign(options$$1 || {}, {url: url, method: method$$1})); - }; + Http[method$$1] = function (url, options$$1) { + return this(assign(options$$1 || {}, {url: url, method: method$$1})); + }; -}); + }); -['post', 'put', 'patch'].forEach(function (method$$1) { + ['post', 'put', 'patch'].forEach(function (method$$1) { - Http[method$$1] = function (url, body, options$$1) { - return this(assign(options$$1 || {}, {url: url, method: method$$1, body: body})); - }; + Http[method$$1] = function (url, body, options$$1) { + return this(assign(options$$1 || {}, {url: url, method: method$$1, body: body})); + }; -}); + }); -/** - * Service for interacting with RESTful services. - */ + /** + * Service for interacting with RESTful services. + */ -function Resource(url, params, actions, options$$1) { + function Resource(url, params, actions, options$$1) { - var self = this || {}, resource = {}; + var self = this || {}, resource = {}; - actions = assign({}, - Resource.actions, - actions - ); + actions = assign({}, + Resource.actions, + actions + ); - each(actions, function (action, name) { + each(actions, function (action, name) { - action = merge({url: url, params: assign({}, params)}, options$$1, action); + action = merge({url: url, params: assign({}, params)}, options$$1, action); - resource[name] = function () { - return (self.$http || Http)(opts(action, arguments)); - }; - }); + resource[name] = function () { + return (self.$http || Http)(opts(action, arguments)); + }; + }); - return resource; -} + return resource; + } -function opts(action, args) { + function opts(action, args) { - var options$$1 = assign({}, action), params = {}, body; + var options$$1 = assign({}, action), params = {}, body; - switch (args.length) { + switch (args.length) { - case 2: + case 2: - params = args[0]; - body = args[1]; + params = args[0]; + body = args[1]; - break; + break; - case 1: + case 1: - if (/^(POST|PUT|PATCH)$/i.test(options$$1.method)) { - body = args[0]; - } else { - params = args[0]; - } + if (/^(POST|PUT|PATCH)$/i.test(options$$1.method)) { + body = args[0]; + } else { + params = args[0]; + } - break; + break; - case 0: + case 0: - break; + break; - default: + default: - throw 'Expected up to 2 arguments [params, body], got ' + args.length + ' arguments'; - } + throw 'Expected up to 2 arguments [params, body], got ' + args.length + ' arguments'; + } - options$$1.body = body; - options$$1.params = assign({}, options$$1.params, params); + options$$1.body = body; + options$$1.params = assign({}, options$$1.params, params); - return options$$1; -} + return options$$1; + } -Resource.actions = { + Resource.actions = { - get: {method: 'GET'}, - save: {method: 'POST'}, - query: {method: 'GET'}, - update: {method: 'PUT'}, - remove: {method: 'DELETE'}, - delete: {method: 'DELETE'} + get: {method: 'GET'}, + save: {method: 'POST'}, + query: {method: 'GET'}, + update: {method: 'PUT'}, + remove: {method: 'DELETE'}, + delete: {method: 'DELETE'} -}; + }; -/** - * Install plugin. - */ + /** + * Install plugin. + */ -function plugin(Vue) { + function plugin(Vue) { - if (plugin.installed) { - return; - } + if (plugin.installed) { + return; + } - Util(Vue); + Util(Vue); - Vue.url = Url; - Vue.http = Http; - Vue.resource = Resource; - Vue.Promise = PromiseObj; + Vue.url = Url; + Vue.http = Http; + Vue.resource = Resource; + Vue.Promise = PromiseObj; - Object.defineProperties(Vue.prototype, { + Object.defineProperties(Vue.prototype, { - $url: { - get: function get() { - return options(Vue.url, this, this.$options.url); - } - }, + $url: { + get: function get() { + return options(Vue.url, this, this.$options.url); + } + }, - $http: { - get: function get() { - return options(Vue.http, this, this.$options.http); - } - }, + $http: { + get: function get() { + return options(Vue.http, this, this.$options.http); + } + }, - $resource: { - get: function get() { - return Vue.resource.bind(this); - } - }, + $resource: { + get: function get() { + return Vue.resource.bind(this); + } + }, - $promise: { - get: function get() { - var this$1 = this; + $promise: { + get: function get() { + var this$1 = this; - return function (executor) { return new Vue.Promise(executor, this$1); }; + return function (executor) { return new Vue.Promise(executor, this$1); }; + } } - } - }); -} + }); + } -if (typeof window !== 'undefined' && window.Vue) { - window.Vue.use(plugin); -} + if (typeof window !== 'undefined' && window.Vue) { + window.Vue.use(plugin); + } -return plugin; + return plugin; }))); diff --git a/dist/vue-resource.min.js b/dist/vue-resource.min.js index cc10be74..242f6914 100644 --- a/dist/vue-resource.min.js +++ b/dist/vue-resource.min.js @@ -1,7 +1,7 @@ /*! - * vue-resource v1.5.0 + * vue-resource v1.5.1 * https://github.com/pagekit/vue-resource * Released under the MIT License. */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueResource=e()}(this,function(){"use strict";var t=2;function e(e){this.state=t,this.value=void 0,this.deferred=[];var n=this;try{e(function(t){n.resolve(t)},function(t){n.reject(t)})}catch(t){n.reject(t)}}e.reject=function(t){return new e(function(e,n){n(t)})},e.resolve=function(t){return new e(function(e,n){e(t)})},e.all=function(t){return new e(function(n,o){var r=0,i=[];function s(e){return function(o){i[e]=o,(r+=1)===t.length&&n(i)}}0===t.length&&n(i);for(var u=0;u=200&&a<300,this.status=a||0,this.statusText=c||"",this.headers=new L(u),this.body=t,d(t)?this.bodyText=t:(i=t,"undefined"!=typeof Blob&&i instanceof Blob&&(this.bodyBlob=t,(0===(r=t).type.indexOf("text")||-1!==r.type.indexOf("json"))&&(this.bodyText=(n=t,new o(function(t){var e=new FileReader;e.readAsText(n),e.onload=function(){t(e.result)}})))))};H.prototype.blob=function(){return v(this.bodyBlob)},H.prototype.text=function(){return v(this.bodyText)},H.prototype.json=function(){return v(this.text(),function(t){return JSON.parse(t)})},Object.defineProperty(H.prototype,"data",{get:function(){return this.body},set:function(t){this.body=t}});var B=function(t){var e;this.body=null,this.params={},w(this,t,{method:(e=t.method||"GET",e?e.toUpperCase():"")}),this.headers instanceof L||(this.headers=new L(this.headers))};B.prototype.getUrl=function(){return $(this)},B.prototype.getBody=function(){return this.body},B.prototype.respondWith=function(t,e){return new H(t,w(e||{},{url:this.getUrl()}))};var M={"Content-Type":"application/json;charset=utf-8"};function N(t){var e=this||{},n=function(t){var e=[I],n=[];function r(r){for(;e.length;){var i=e.pop();if(l(i)){var s=void 0,u=void 0;if(m(s=i.call(t,r,function(t){return u=t})||u))return new o(function(e,o){n.forEach(function(e){s=v(s,function(n){return e.call(t,n)||n},o)}),v(s,e,o)},t);l(s)&&n.unshift(s)}else c="Invalid interceptor of type "+typeof i+", must be a function","undefined"!=typeof console&&a&&console.warn("[VueResource warn]: "+c)}var c}return m(t)||(t=null),r.use=function(t){e.push(t)},r}(e.$vm);return function(t){u.call(arguments,1).forEach(function(e){for(var n in e)void 0===t[n]&&(t[n]=e[n])})}(t||{},e.$options,N.options),N.interceptors.forEach(function(t){d(t)&&(t=N.interceptor[t]),l(t)&&n.use(t)}),n(new B(t)).then(function(t){return t.ok?t:o.reject(t)},function(t){var e;return t instanceof Error&&(e=t,"undefined"!=typeof console&&console.error(e)),o.reject(t)})}function D(t,e,n,o){var r=this||{},i={};return g(n=w({},D.actions,n),function(n,s){n=T({url:t,params:w({},e)},o,n),i[s]=function(){return(r.$http||N)(function(t,e){var n,o=w({},t),r={};switch(e.length){case 2:r=e[0],n=e[1];break;case 1:/^(POST|PUT|PATCH)$/i.test(o.method)?n=e[0]:r=e[0];break;case 0:break;default:throw"Expected up to 2 arguments [params, body], got "+e.length+" arguments"}return o.body=n,o.params=w({},o.params,r),o}(n,arguments))}}),i}function J(t){var e,n,r;J.installed||(n=(e=t).config,r=e.nextTick,i=r,a=n.debug||!n.silent,t.url=$,t.http=N,t.resource=D,t.Promise=o,Object.defineProperties(t.prototype,{$url:{get:function(){return b(t.url,this,this.$options.url)}},$http:{get:function(){return b(t.http,this,this.$options.http)}},$resource:{get:function(){return t.resource.bind(this)}},$promise:{get:function(){var e=this;return function(n){return new t.Promise(n,e)}}}}))}return N.options={},N.headers={put:M,post:M,patch:M,delete:M,common:{Accept:"application/json, text/plain, */*"},custom:{}},N.interceptor={before:function(t){l(t.before)&&t.before.call(this,t)},method:function(t){t.emulateHTTP&&/^(PUT|PATCH|DELETE)$/i.test(t.method)&&(t.headers.set("X-HTTP-Method-Override",t.method),t.method="POST")},jsonp:function(t){"JSONP"==t.method&&(t.client=A)},json:function(t){var e=t.headers.get("Content-Type")||"";return m(t.body)&&0===e.indexOf("application/json")&&(t.body=JSON.stringify(t.body)),function(t){return t.bodyText?v(t.text(),function(e){var n,o;if(0===(t.headers.get("Content-Type")||"").indexOf("application/json")||(o=(n=e).match(/^\s*(\[|\{)/))&&{"[":/]\s*$/,"{":/}\s*$/}[o[1]].test(n))try{t.body=JSON.parse(e)}catch(e){t.body=null}else t.body=e;return t}):t}},form:function(t){var e;e=t.body,"undefined"!=typeof FormData&&e instanceof FormData?t.headers.delete("Content-Type"):m(t.body)&&t.emulateJSON&&(t.body=$.params(t.body),t.headers.set("Content-Type","application/x-www-form-urlencoded"))},header:function(t){g(w({},N.headers.common,t.crossOrigin?{}:N.headers.custom,N.headers[p(t.method)]),function(e,n){t.headers.has(n)||t.headers.set(n,e)})},cors:function(t){if(c){var e=$.parse(location.href),n=$.parse(t.getUrl());n.protocol===e.protocol&&n.host===e.host||(t.crossOrigin=!0,t.emulateHTTP=!1,R||(t.client=U))}}},N.interceptors=["before","method","jsonp","json","form","header","cors"],["get","delete","head","jsonp"].forEach(function(t){N[t]=function(e,n){return this(w(n||{},{url:e,method:t}))}}),["post","put","patch"].forEach(function(t){N[t]=function(e,n,o){return this(w(o||{},{url:e,method:t,body:n}))}}),D.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},update:{method:"PUT"},remove:{method:"DELETE"},delete:{method:"DELETE"}},"undefined"!=typeof window&&window.Vue&&window.Vue.use(J),J}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueResource=e()}(this,function(){"use strict";function u(t){this.state=2,this.value=void 0,this.deferred=[];var e=this;try{t(function(t){e.resolve(t)},function(t){e.reject(t)})}catch(t){e.reject(t)}}u.reject=function(n){return new u(function(t,e){e(n)})},u.resolve=function(n){return new u(function(t,e){t(n)})},u.all=function(s){return new u(function(n,t){var o=0,r=[];function e(e){return function(t){r[e]=t,(o+=1)===s.length&&n(r)}}0===s.length&&n(r);for(var i=0;i