From 1e7aa19a1a1e1d125a219a51148b146bf6df885b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 6 Sep 2018 17:28:03 -0700 Subject: [PATCH] [Refactor] `formats`: tiny bit of cleanup. Additionally, `stringify`'s defaults get `format`, even though it isn't necessary due to the line that assigns it to the internal options. This way, however, things are a bit more internally consistent. --- lib/formats.js | 28 ++++++++++++++++++---------- lib/stringify.js | 4 +++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/formats.js b/lib/formats.js index 702da12e..a4ecca78 100644 --- a/lib/formats.js +++ b/lib/formats.js @@ -3,16 +3,24 @@ var replace = String.prototype.replace; var percentTwenties = /%20/g; -module.exports = { - 'default': 'RFC3986', - formatters: { - RFC1738: function (value) { - return replace.call(value, percentTwenties, '+'); - }, - RFC3986: function (value) { - return String(value); - } - }, +var util = require('./utils'); + +var Format = { RFC1738: 'RFC1738', RFC3986: 'RFC3986' }; + +module.exports = util.assign( + { + 'default': Format.RFC3986, + formatters: { + RFC1738: function (value) { + return replace.call(value, percentTwenties, '+'); + }, + RFC3986: function (value) { + return String(value); + } + } + }, + Format +); diff --git a/lib/stringify.js b/lib/stringify.js index 40559b5d..b74c014c 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -24,6 +24,7 @@ var pushToArray = function (arr, valueOrArray) { var toISO = Date.prototype.toISOString; +var defaultFormat = formats['default']; var defaults = { addQueryPrefix: false, allowDots: false, @@ -33,7 +34,8 @@ var defaults = { encode: true, encoder: utils.encode, encodeValuesOnly: false, - formatter: formats.formatters[formats['default']], + format: defaultFormat, + formatter: formats.formatters[defaultFormat], // deprecated indices: false, serializeDate: function serializeDate(date) {