Skip to content

Commit

Permalink
[Refactor] formats: tiny bit of cleanup.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ljharb committed Sep 7, 2018
1 parent 0fab4eb commit 1e7aa19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
28 changes: 18 additions & 10 deletions lib/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
4 changes: 3 additions & 1 deletion lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var pushToArray = function (arr, valueOrArray) {

var toISO = Date.prototype.toISOString;

var defaultFormat = formats['default'];
var defaults = {
addQueryPrefix: false,
allowDots: false,
Expand All @@ -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) {
Expand Down

0 comments on commit 1e7aa19

Please sign in to comment.