diff --git a/README.md b/README.md index c4f6f76..b5d050e 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ These are the default styles and settings used by _eyes_. }, pretty: true, // Indent object literals + sortObjectKeys: false, // Sort object keys hideFunctions: false, // Don't output functions at all stream: process.stdout, // Stream to write to, or null maxLength: 2048 // Truncate output if longer diff --git a/lib/eyes.js b/lib/eyes.js index 10d964b..e14676b 100644 --- a/lib/eyes.js +++ b/lib/eyes.js @@ -27,6 +27,7 @@ eyes.defaults = { regexp: 'green', // /\d+/ }, pretty: true, // Indent object literals + sortObjectKeys: false, // Sort object keys hideFunctions: false, showHidden: false, stream: process.stdout, @@ -178,6 +179,9 @@ function stringifyObject(obj, options, level) { var ws = pretty ? '\n' + new(Array)(level * 4 + 1).join(' ') : ' '; var keys = options.showHidden ? Object.keys(obj) : Object.getOwnPropertyNames(obj); + if (options.sortObjectKeys) { + keys = keys.sort(); + } keys.forEach(function (k) { if (Object.prototype.hasOwnProperty.call(obj, k) && !(obj[k] instanceof Function && options.hideFunctions)) {