Skip to content

Commit

Permalink
chore: apply latest generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Owsiak committed Jan 3, 2018
1 parent 6870ed0 commit 9ea499a
Show file tree
Hide file tree
Showing 30 changed files with 758 additions and 535 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "groupon/legacy"
"extends": "groupon/es5"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/yarn.lock
node_modules/
npm-debug.log
/tmp
Expand Down
18 changes: 9 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: node_js
node_js:
- '4'
- '6'
- '8'
- 4.6.1
- 6.11.5
- 8.9.0
deploy:
provider: script
script: ./node_modules/.bin/nlm release
skip_cleanup: true
'on':
branch: master
node: '8'
- provider: script
script: ./node_modules/.bin/nlm release
skip_cleanup: true
'on':
branch: master
node: 8.9.0
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Generated by generator-nlm -->
<!-- Generated by generator-js -->

# Contributing

Expand Down Expand Up @@ -31,7 +31,7 @@ If you report a bug, please follow these guidelines:

For small documentation changes, you can use [Github's editing feature](https://help.github.com/articles/editing-files-in-another-user-s-repository/).
The only thing to keep in mind is to prefix the commit message with "docs: ".
The detault commit message generated by Github will lead to a failing CI build.
The default commit message generated by Github will lead to a failing CI build.

For larger updates to the documentation
it might be better to follow the [instructions for contributing code below](#contributing-code).
Expand All @@ -52,7 +52,7 @@ The general steps for creating a pull request are:
1. If you're fixing a bug, be sure to write a test *first*.
That way you can validate that the test actually catches the bug and doesn't pass.
1. Make your changes to the code.
Remember to update the tests if you add new features or change behavior.
Remember to update the tests if you add new features or change behavior.
1. Run the tests via `npm test`. This will also run style checks and other validations.
You might see errors about uncommitted files.
This is expected until you commit your changes.
Expand Down
21 changes: 18 additions & 3 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

'use strict';

function StatusCodeError(statusCode, min, max, headers, method, url) {
Error.call(this);

this.message = 'API Request returned a response outside the status code range ' +
'(code: ' + statusCode + ', range: [' + min + ', ' + max + '])';
this.message =
'API Request returned a response outside the status code range ' +
'(code: ' +
statusCode +
', range: [' +
min +
', ' +
max +
'])';
this.headers = headers;
this.statusCode = statusCode;
this.minStatusCode = min;
Expand Down Expand Up @@ -73,7 +81,14 @@ function NotFoundError(min, max, headers, method, url) {
}
exportError(NotFoundError);

StatusCodeError.create = function createError(statusCode, min, max, headers, method, url) {
StatusCodeError.create = function createError(
statusCode,
min,
max,
headers,
method,
url
) {
var error;
switch (statusCode) {
case 301:
Expand Down
67 changes: 41 additions & 26 deletions lib/fetch.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

'use strict';

/* eslint-env browser */
/* global URLSearchParams */
var Url = require('url');

Expand All @@ -51,34 +54,36 @@ if (typeof fetch !== 'function') {
throw new Error('Requires native fetch or polyfill');
}

function _callJSON(res) {
function callJSON(res) {
return res.json();
}

function _callText(res) {
function callText(res) {
return res.text();
}

var reqProperties = {
json: {
value: function json() {
return this.then(_callJSON);
return this.then(callJSON);
},
},

text: {
value: function text() {
return this.then(_callText);
return this.then(callText);
},
},
};

// Blob or BufferSource or FormData or URLSearchParams or USVString
function isValidBody(body) {
return body === undefined ||
return (
body === undefined ||
typeof body === 'string' ||
(typeof FormData !== 'undefined' && body instanceof FormData) ||
(typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams);
(typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams)
);
}

function validateBody(body) {
Expand All @@ -91,15 +96,14 @@ function validateBody(body) {
function generateSearch(queryString, qs) {
var query = assign(qsParser.parse(queryString), qs || {});
var filtered = {};
var queryKeys = Object.keys(query)
.filter(function ensureSet(key) {
var value = query[key];
var isSet = value !== null && value !== undefined;
if (isSet) {
filtered[key] = value;
}
return isSet;
});
var queryKeys = Object.keys(query).filter(function ensureSet(key) {
var value = query[key];
var isSet = value !== null && value !== undefined;
if (isSet) {
filtered[key] = value;
}
return isSet;
});

if (queryKeys.length === 0) return '';
return '?' + qsParser.stringify(filtered);
Expand All @@ -123,7 +127,8 @@ function defaultStatusCode(value, defaultValue) {
if (value >= 0) {
if (typeof value !== 'number') {
throw new TypeError(
'Invalid status code ' + JSON.stringify(value) + ', not a number');
'Invalid status code ' + JSON.stringify(value) + ', not a number'
);
}
return value;
}
Expand All @@ -144,8 +149,7 @@ function verifyAndExtendResponse(url, options, response) {
var max = defaultStatusCode(options.maxStatusCode, 299);

function isAcceptableStatus(code) {
return (min === false || code >= min) &&
(max === false || code <= max);
return (min === false || code >= min) && (max === false || code <= max);
}

var originalHeaders = response.headers;
Expand All @@ -170,14 +174,21 @@ function verifyAndExtendResponse(url, options, response) {

function generateStatusCodeError(code) {
var error = StatusCodeError.create(
code, min, max, response.headers, options.method || 'GET', url);
code,
min,
max,
response.headers,
options.method || 'GET',
url
);

function rejectWithBody(body) {
error.body = body;
throw error;
}

return response.text()
return response
.text()
.then(parseErrorBody)
.then(null, noop)
.then(rejectWithBody);
Expand All @@ -194,14 +205,15 @@ function defaultTimeout(value, defaultValue) {
if (value >= 0) {
if (typeof value !== 'number') {
throw new TypeError(
'Invalid timeout ' + JSON.stringify(value) + ', not a number');
'Invalid timeout ' + JSON.stringify(value) + ', not a number'
);
}
return value;
}
return defaultValue;
}

function _fetch(url, options) {
function fetchUrl(url, options) {
if (typeof url !== 'string') {
throw new TypeError('url has to be a string');
}
Expand All @@ -224,17 +236,20 @@ function _fetch(url, options) {
} else if (form !== undefined && form !== null) {
if (typeof form !== 'object') {
throw new TypeError(
'Invalid form body (' + typeof form + ', expected object)');
'Invalid form body (' + typeof form + ', expected object)'
);
}
defaultHeaders['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
defaultHeaders['Content-Type'] =
'application/x-www-form-urlencoded;charset=UTF-8';
body = qsParser.stringify(form);
}

var auth = options.auth;
if (typeof auth === 'string') {
defaultHeaders.Authorization = 'Basic ' + btoa(auth);
} else if (auth !== null && typeof auth === 'object') {
defaultHeaders.Authorization = 'Basic ' + btoa(auth.username + ':' + auth.password);
defaultHeaders.Authorization =
'Basic ' + btoa(auth.username + ':' + auth.password);
}

var timeout = defaultTimeout(options.timeout, DEFAULT_TIMEOUT);
Expand Down Expand Up @@ -283,4 +298,4 @@ function _fetch(url, options) {
return Object.defineProperties(result, reqProperties);
}

module.exports = _fetch;
module.exports = fetchUrl;
Loading

0 comments on commit 9ea499a

Please sign in to comment.