Skip to content

Commit

Permalink
[Refactor] move object key gathering into separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 28, 2017
1 parent 6f2c11e commit aca6265
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
}
if (!isDate(obj) && !isRegExp(obj)) {
var xs = [];
var keys = [];
for (var key in obj) {
if (has(obj, key)) keys.push(key);
}
var keys = objectKeys(obj);
keys.sort();
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
Expand All @@ -134,6 +131,14 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
return String(obj);
};

function objectKeys(obj) {
var keys = [];
for (var key in obj) {
if (has(obj, key)) keys.push(key);
}
return keys;
}

function quote (s) {
return String(s).replace(/"/g, '&quot;');
}
Expand Down

0 comments on commit aca6265

Please sign in to comment.