Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit 0da6829

Browse files
author
Steffan
committed
Merge branch 'release/1.3.2'
2 parents a8e5ba1 + 9d98dfc commit 0da6829

File tree

18 files changed

+640
-475
lines changed

18 files changed

+640
-475
lines changed

.circleci/config.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: node:7.9.0
6+
working_directory: ~/vue-resource
7+
steps:
8+
- run:
9+
name: Update Environment
10+
command: apt-get update && apt-get -y install unzip
11+
- checkout
12+
- run:
13+
name: Install Dependencies
14+
command: yarn
15+
- run:
16+
name: Run Tests
17+
command: yarn test
18+
- run:
19+
name: Build Release
20+
command: yarn run build

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,20 @@ The plugin for [Vue.js](http://vuejs.org) provides services for making web reque
77
- Supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API and [URI Templates](https://medialize.github.io/URI.js/uri-template.html)
88
- Supports [interceptors](docs/http.md#interceptors) for request and response
99
- Supports latest Firefox, Chrome, Safari, Opera and IE9+
10+
- Supports Vue 1.0 & Vue 2.0
1011
- Compact size 14KB (5.3KB gzipped)
1112

1213
## Installation
13-
14-
### NPM
14+
You can install it via [yarn](https://yarnpkg.com/) or [NPM](http://npmjs.org/).
1515
```
16+
$ yarn add vue-resource
1617
$ npm install vue-resource
1718
```
1819

19-
### Bower
20-
```
21-
$ bower install vue-resource
22-
```
23-
2420
### CDN
25-
Available on [jsdelivr](https://cdn.jsdelivr.net/vue.resource/1.3.1/vue-resource.min.js), [cdnjs](https://cdnjs.com/libraries/vue-resource) or [unpkg](https://unpkg.com/[email protected].1/dist/vue-resource.min.js).
21+
Available on [jsdelivr](https://cdn.jsdelivr.net/vue.resource/1.3.2/vue-resource.min.js), [cdnjs](https://cdnjs.com/libraries/vue-resource) or [unpkg](https://unpkg.com/[email protected].2/dist/vue-resource.min.js).
2622
```html
27-
<script src="https://cdn.jsdelivr.net/vue.resource/1.3.1/vue-resource.min.js"></script>
23+
<script src="https://cdn.jsdelivr.net/vue.resource/1.3.2/vue-resource.min.js"></script>
2824
```
2925

3026
## Example
@@ -52,11 +48,11 @@ Available on [jsdelivr](https://cdn.jsdelivr.net/vue.resource/1.3.1/vue-resource
5248

5349
## Changelog
5450

55-
Details changes for each release are documented in the [release notes](https://github.com/vuejs/vue-resource/releases).
51+
Details changes for each release are documented in the [release notes](https://github.com/pagekit/vue-resource/releases).
5652

5753
## Contribution
5854

59-
If you find a bug or want to contribute to the code or documentation, you can help by submitting an [issue](https://github.com/vuejs/vue-resource/issues) or a [pull request](https://github.com/vuejs/vue-resource/pulls).
55+
If you find a bug or want to contribute to the code or documentation, you can help by submitting an [issue](https://github.com/pagekit/vue-resource/issues) or a [pull request](https://github.com/pagekit/vue-resource/pulls).
6056

6157
## License
6258

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-resource",
33
"main": "dist/vue-resource.js",
4-
"version": "1.3.1",
4+
"version": "1.3.2",
55
"description": "The HTTP client for Vue.js",
66
"homepage": "https://github.com/pagekit/vue-resource",
77
"license": "MIT",

dist/vue-resource.common.js

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-resource v1.3.1
2+
* vue-resource v1.3.2
33
* https://github.com/pagekit/vue-resource
44
* Released under the MIT License.
55
*/
@@ -300,6 +300,19 @@ function trim(str) {
300300
return str ? str.replace(/^\s*|\s*$/g, '') : '';
301301
}
302302

303+
function trimEnd(str, chars) {
304+
305+
if (str && chars === undefined) {
306+
return str.replace(/\s+$/, '');
307+
}
308+
309+
if (!str || !chars) {
310+
return str;
311+
}
312+
313+
return str.replace(new RegExp(("[" + chars + "]+$")), '');
314+
}
315+
303316
function toLower(str) {
304317
return str ? str.toLowerCase() : '';
305318
}
@@ -442,8 +455,8 @@ var root = function (options$$1, next) {
442455

443456
var url = next(options$$1);
444457

445-
if (isString(options$$1.root) && !url.match(/^(https?:)?\//)) {
446-
url = options$$1.root + '/' + url;
458+
if (isString(options$$1.root) && !/^(https?:)?\//.test(url)) {
459+
url = trimEnd(options$$1.root, '/') + '/' + url;
447460
}
448461

449462
return url;
@@ -836,42 +849,41 @@ var cors = function (request, next) {
836849
};
837850

838851
/**
839-
* Body Interceptor.
852+
* Form data Interceptor.
840853
*/
841854

842-
var body = function (request, next) {
855+
var form = function (request, next) {
843856

844857
if (isFormData(request.body)) {
845858

846859
request.headers.delete('Content-Type');
847860

848-
} else if (isObject(request.body) || isArray(request.body)) {
861+
} else if (isObject(request.body) && request.emulateJSON) {
849862

850-
if (request.emulateJSON) {
851-
request.body = Url.params(request.body);
852-
request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
853-
} else {
854-
request.body = JSON.stringify(request.body);
855-
}
863+
request.body = Url.params(request.body);
864+
request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
856865
}
857866

858-
next(function (response) {
867+
next();
868+
};
869+
870+
/**
871+
* JSON Interceptor.
872+
*/
859873

860-
Object.defineProperty(response, 'data', {
874+
var json = function (request, next) {
861875

862-
get: function get() {
863-
return this.body;
864-
},
876+
var type = request.headers.get('Content-Type') || '';
865877

866-
set: function set(body) {
867-
this.body = body;
868-
}
878+
if (isObject(request.body) && type.indexOf('application/json') === 0) {
879+
request.body = JSON.stringify(request.body);
880+
}
869881

870-
});
882+
next(function (response) {
871883

872884
return response.bodyText ? when(response.text(), function (text) {
873885

874-
var type = response.headers.get('Content-Type') || '';
886+
type = response.headers.get('Content-Type') || '';
875887

876888
if (type.indexOf('application/json') === 0 || isJson(text)) {
877889

@@ -1299,6 +1311,18 @@ Response.prototype.json = function json () {
12991311
return when(this.text(), function (text) { return JSON.parse(text); });
13001312
};
13011313

1314+
Object.defineProperty(Response.prototype, 'data', {
1315+
1316+
get: function get() {
1317+
return this.body;
1318+
},
1319+
1320+
set: function set(body) {
1321+
this.body = body;
1322+
}
1323+
1324+
});
1325+
13021326
function blobText(body) {
13031327
return new PromiseObj(function (resolve) {
13041328

@@ -1396,8 +1420,8 @@ Http.headers = {
13961420
custom: {}
13971421
};
13981422

1399-
Http.interceptor = {before: before, method: method, body: body, jsonp: jsonp, header: header, cors: cors};
1400-
Http.interceptors = ['before', 'method', 'body', 'jsonp', 'header', 'cors'];
1423+
Http.interceptor = {before: before, method: method, jsonp: jsonp, json: json, form: form, header: header, cors: cors};
1424+
Http.interceptors = ['before', 'method', 'jsonp', 'json', 'form', 'header', 'cors'];
14011425

14021426
['get', 'delete', 'head', 'jsonp'].forEach(function (method$$1) {
14031427

@@ -1409,8 +1433,8 @@ Http.interceptors = ['before', 'method', 'body', 'jsonp', 'header', 'cors'];
14091433

14101434
['post', 'put', 'patch'].forEach(function (method$$1) {
14111435

1412-
Http[method$$1] = function (url, body$$1, options$$1) {
1413-
return this(assign(options$$1 || {}, {url: url, method: method$$1, body: body$$1}));
1436+
Http[method$$1] = function (url, body, options$$1) {
1437+
return this(assign(options$$1 || {}, {url: url, method: method$$1, body: body}));
14141438
};
14151439

14161440
});

dist/vue-resource.es2015.js

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-resource v1.3.1
2+
* vue-resource v1.3.2
33
* https://github.com/pagekit/vue-resource
44
* Released under the MIT License.
55
*/
@@ -298,6 +298,19 @@ function trim(str) {
298298
return str ? str.replace(/^\s*|\s*$/g, '') : '';
299299
}
300300

301+
function trimEnd(str, chars) {
302+
303+
if (str && chars === undefined) {
304+
return str.replace(/\s+$/, '');
305+
}
306+
307+
if (!str || !chars) {
308+
return str;
309+
}
310+
311+
return str.replace(new RegExp(("[" + chars + "]+$")), '');
312+
}
313+
301314
function toLower(str) {
302315
return str ? str.toLowerCase() : '';
303316
}
@@ -440,8 +453,8 @@ var root = function (options$$1, next) {
440453

441454
var url = next(options$$1);
442455

443-
if (isString(options$$1.root) && !url.match(/^(https?:)?\//)) {
444-
url = options$$1.root + '/' + url;
456+
if (isString(options$$1.root) && !/^(https?:)?\//.test(url)) {
457+
url = trimEnd(options$$1.root, '/') + '/' + url;
445458
}
446459

447460
return url;
@@ -834,42 +847,41 @@ var cors = function (request, next) {
834847
};
835848

836849
/**
837-
* Body Interceptor.
850+
* Form data Interceptor.
838851
*/
839852

840-
var body = function (request, next) {
853+
var form = function (request, next) {
841854

842855
if (isFormData(request.body)) {
843856

844857
request.headers.delete('Content-Type');
845858

846-
} else if (isObject(request.body) || isArray(request.body)) {
859+
} else if (isObject(request.body) && request.emulateJSON) {
847860

848-
if (request.emulateJSON) {
849-
request.body = Url.params(request.body);
850-
request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
851-
} else {
852-
request.body = JSON.stringify(request.body);
853-
}
861+
request.body = Url.params(request.body);
862+
request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
854863
}
855864

856-
next(function (response) {
865+
next();
866+
};
867+
868+
/**
869+
* JSON Interceptor.
870+
*/
857871

858-
Object.defineProperty(response, 'data', {
872+
var json = function (request, next) {
859873

860-
get: function get() {
861-
return this.body;
862-
},
874+
var type = request.headers.get('Content-Type') || '';
863875

864-
set: function set(body) {
865-
this.body = body;
866-
}
876+
if (isObject(request.body) && type.indexOf('application/json') === 0) {
877+
request.body = JSON.stringify(request.body);
878+
}
867879

868-
});
880+
next(function (response) {
869881

870882
return response.bodyText ? when(response.text(), function (text) {
871883

872-
var type = response.headers.get('Content-Type') || '';
884+
type = response.headers.get('Content-Type') || '';
873885

874886
if (type.indexOf('application/json') === 0 || isJson(text)) {
875887

@@ -1297,6 +1309,18 @@ Response.prototype.json = function json () {
12971309
return when(this.text(), function (text) { return JSON.parse(text); });
12981310
};
12991311

1312+
Object.defineProperty(Response.prototype, 'data', {
1313+
1314+
get: function get() {
1315+
return this.body;
1316+
},
1317+
1318+
set: function set(body) {
1319+
this.body = body;
1320+
}
1321+
1322+
});
1323+
13001324
function blobText(body) {
13011325
return new PromiseObj(function (resolve) {
13021326

@@ -1394,8 +1418,8 @@ Http.headers = {
13941418
custom: {}
13951419
};
13961420

1397-
Http.interceptor = {before: before, method: method, body: body, jsonp: jsonp, header: header, cors: cors};
1398-
Http.interceptors = ['before', 'method', 'body', 'jsonp', 'header', 'cors'];
1421+
Http.interceptor = {before: before, method: method, jsonp: jsonp, json: json, form: form, header: header, cors: cors};
1422+
Http.interceptors = ['before', 'method', 'jsonp', 'json', 'form', 'header', 'cors'];
13991423

14001424
['get', 'delete', 'head', 'jsonp'].forEach(function (method$$1) {
14011425

@@ -1407,8 +1431,8 @@ Http.interceptors = ['before', 'method', 'body', 'jsonp', 'header', 'cors'];
14071431

14081432
['post', 'put', 'patch'].forEach(function (method$$1) {
14091433

1410-
Http[method$$1] = function (url, body$$1, options$$1) {
1411-
return this(assign(options$$1 || {}, {url: url, method: method$$1, body: body$$1}));
1434+
Http[method$$1] = function (url, body, options$$1) {
1435+
return this(assign(options$$1 || {}, {url: url, method: method$$1, body: body}));
14121436
};
14131437

14141438
});

0 commit comments

Comments
 (0)