From a07b19cc3b1521a82d4fafb6368b7a9775428a05 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 17:23:49 -0800 Subject: [PATCH] sort keys --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 08183f9..04a11d3 100644 --- a/index.js +++ b/index.js @@ -51,9 +51,13 @@ module.exports = function inspect_ (obj, opts, depth, seen) { return obj.inspect(); } else if (typeof obj === 'object' && !isDate(obj) && !isRegExp(obj)) { - var xs = []; + var xs = [], keys = []; for (var key in obj) { - if (!has(obj, key)) continue; + if (has(obj, key)) keys.push(key); + } + keys.sort(); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; if (/[^\w$]/.test(key)) { xs.push(inspect(key) + ': ' + inspect(obj[key], obj)); }