Skip to content

Commit

Permalink
[Refactor] avoid recreating default replacer
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 11, 2023
1 parent 80d52a1 commit 4e95ebb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ var strRepeat = function repeat(n, char) {
return str;
};

var defaultReplacer = function (parent, key, value) { return value; };

module.exports = function (obj, opts) {
if (!opts) { opts = {}; }
if (typeof opts === 'function') { opts = { cmp: opts }; }
var space = opts.space || '';
if (typeof space === 'number') { space = strRepeat(space, ' '); }
var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
var replacer = opts.replacer ? callBind(opts.replacer) : function (parent, key, value) { return value; };
var replacer = opts.replacer ? callBind(opts.replacer) : defaultReplacer;

var cmpOpt = opts.cmp;
var cmp = cmpOpt && function (node) {
Expand Down

0 comments on commit 4e95ebb

Please sign in to comment.