From 54dcaef41d35672f4bce73b92bee41461f807209 Mon Sep 17 00:00:00 2001 From: Almouro Date: Thu, 19 Sep 2019 16:37:02 +0200 Subject: [PATCH] fix: merge options with nested default nested --- package.json | 1 + src/index.js | 45 ++++++++++++++++++++++++--------------------- yarn.lock | 23 ++++++++++++++++++++++- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index c1b7cd7..468273e 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "common-tags": "^1.8.0", "cross-fetch": "^3.0.4", "debug": "^4.1.1", + "defaults-deep": "^0.2.4", "qs": "^6.8.0", "url-join": "^4.0.1", "url-parse": "^1.4.7" diff --git a/src/index.js b/src/index.js index d86cdee..6d35b68 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,7 @@ const urlJoin = require('url-join'); const URL = require('url-parse'); const debug = require('debug')('frisbee'); const boolean = require('boolean'); +const defaults = require('defaults-deep'); // eslint-disable-next-line import/no-unassigned-import require('cross-fetch/polyfill'); @@ -94,28 +95,30 @@ function createFrisbeeResponse(origResp) { class Frisbee { constructor(opts = {}) { - this.opts = { - parse: { - ignoreQueryPrefix: true - }, - stringify: { - addQueryPrefix: true, - format: 'RFC1738', - arrayFormat: 'indices' + this.opts = defaults( + { + preventBodyOnMethods: ['GET', 'HEAD', 'DELETE', 'CONNECT'], + interceptableMethods: METHODS, + mode: 'same-origin', + cache: 'default', + credentials: 'same-origin', + redirect: 'follow', + referrer: 'client', + body: null, + params: null, + logRequest: false, + logResponse: false, + parse: { + ignoreQueryPrefix: true + }, + stringify: { + addQueryPrefix: true, + format: 'RFC1738', + arrayFormat: 'indices' + } }, - preventBodyOnMethods: ['GET', 'HEAD', 'DELETE', 'CONNECT'], - interceptableMethods: METHODS, - mode: 'same-origin', - cache: 'default', - credentials: 'same-origin', - redirect: 'follow', - referrer: 'client', - body: null, - params: null, - logRequest: false, - logResponse: false, - ...opts - }; + opts + ); let localAbortController; Object.defineProperty(this, 'abortController', { diff --git a/yarn.lock b/yarn.lock index 34af631..c1434e1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2863,6 +2863,15 @@ default-require-extensions@^2.0.0: dependencies: strip-bom "^3.0.0" +defaults-deep@^0.2.4: + version "0.2.4" + resolved "https://registry.yarnpkg.com/defaults-deep/-/defaults-deep-0.2.4.tgz#a479cfeafce025810fb93aa8d2dde0ee2d677cc6" + integrity sha512-V6BtqzcMvn0EPOy7f+SfMhfmTawq+7UQdt9yZH0EBK89+IHo5f+Hse/qzTorAXOBrQpxpwb6cB/8OgtaMrT+Fg== + dependencies: + for-own "^0.1.3" + is-extendable "^0.1.1" + lazy-cache "^0.2.3" + defaults@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d" @@ -4141,11 +4150,18 @@ fn-name@^2.0.1: resolved "https://registry.yarnpkg.com/fn-name/-/fn-name-2.0.1.tgz#5214d7537a4d06a4a301c0cc262feb84188002e7" integrity sha1-UhTXU3pNBqSjAcDMJi/rhBiAAuc= -for-in@^1.0.2: +for-in@^1.0.1, for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" integrity sha1-gQaNKVqBQuwKxybG4iAMMPttXoA= +for-own@^0.1.3: + version "0.1.5" + resolved "https://registry.yarnpkg.com/for-own/-/for-own-0.1.5.tgz#5265c681a4f294dabbf17c9509b6763aa84510ce" + integrity sha1-UmXGgaTylNq78XyVCbZ2OqhFEM4= + dependencies: + for-in "^1.0.1" + foreach@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99" @@ -5601,6 +5617,11 @@ latest-version@^5.0.0: dependencies: package-json "^6.3.0" +lazy-cache@^0.2.3: + version "0.2.7" + resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-0.2.7.tgz#7feddf2dcb6edb77d11ef1d117ab5ffdf0ab1b65" + integrity sha1-f+3fLctu23fRHvHRF6tf/fCrG2U= + levenshtein-edit-distance@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/levenshtein-edit-distance/-/levenshtein-edit-distance-1.0.0.tgz#895baf478cce8b5c1a0d27e45d7c1d978a661e49"