Skip to content

Commit 1e7aa19

Browse files
committed
[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.
1 parent 0fab4eb commit 1e7aa19

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

lib/formats.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@
33
var replace = String.prototype.replace;
44
var percentTwenties = /%20/g;
55

6-
module.exports = {
7-
'default': 'RFC3986',
8-
formatters: {
9-
RFC1738: function (value) {
10-
return replace.call(value, percentTwenties, '+');
11-
},
12-
RFC3986: function (value) {
13-
return String(value);
14-
}
15-
},
6+
var util = require('./utils');
7+
8+
var Format = {
169
RFC1738: 'RFC1738',
1710
RFC3986: 'RFC3986'
1811
};
12+
13+
module.exports = util.assign(
14+
{
15+
'default': Format.RFC3986,
16+
formatters: {
17+
RFC1738: function (value) {
18+
return replace.call(value, percentTwenties, '+');
19+
},
20+
RFC3986: function (value) {
21+
return String(value);
22+
}
23+
}
24+
},
25+
Format
26+
);

lib/stringify.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var pushToArray = function (arr, valueOrArray) {
2424

2525
var toISO = Date.prototype.toISOString;
2626

27+
var defaultFormat = formats['default'];
2728
var defaults = {
2829
addQueryPrefix: false,
2930
allowDots: false,
@@ -33,7 +34,8 @@ var defaults = {
3334
encode: true,
3435
encoder: utils.encode,
3536
encodeValuesOnly: false,
36-
formatter: formats.formatters[formats['default']],
37+
format: defaultFormat,
38+
formatter: formats.formatters[defaultFormat],
3739
// deprecated
3840
indices: false,
3941
serializeDate: function serializeDate(date) {

0 commit comments

Comments
 (0)