Skip to content

Commit 450680c

Browse files
committed
[Refactor] clean up quoteStyle code
1 parent 44395a8 commit 450680c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ var utilInspect = require('./util.inspect');
6969
var inspectCustom = utilInspect.custom;
7070
var inspectSymbol = isSymbol(inspectCustom) ? inspectCustom : null;
7171

72+
var quotes = {
73+
__proto__: null,
74+
'double': '"',
75+
single: "'"
76+
};
77+
7278
module.exports = function inspect_(obj, options, depth, seen) {
7379
var opts = options || {};
7480

75-
if (has(opts, 'quoteStyle') && (opts.quoteStyle !== 'single' && opts.quoteStyle !== 'double')) {
81+
if (has(opts, 'quoteStyle') && !has(quotes, opts.quoteStyle)) {
7682
throw new TypeError('option "quoteStyle" must be "single" or "double"');
7783
}
7884
if (
@@ -267,7 +273,8 @@ module.exports = function inspect_(obj, options, depth, seen) {
267273
};
268274

269275
function wrapQuotes(s, defaultStyle, opts) {
270-
var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'";
276+
var style = opts.quoteStyle || defaultStyle;
277+
var quoteChar = quotes[style];
271278
return quoteChar + s + quoteChar;
272279
}
273280

0 commit comments

Comments
 (0)