lib/base.js
function canonicalize(obj, stack) {
   stack = stack || [];

   if (utils.indexOf(stack, obj) !== -1) return obj;

   var canonicalizedObj;

   if ('[object Array]' == {}.toString.call(obj)) {
     stack.push(obj);
     canonicalizedObj = utils.map(obj, function(item) {
       return canonicalize(item, stack);
     });
     stack.pop();
   } else if (typeof obj === 'object' && obj !== null) {
     stack.push(obj);
     canonicalizedObj = {};
     utils.forEach(utils.keys(obj).sort(), function(key) {
       canonicalizedObj[key] = canonicalize(obj[key], stack);
     });
     stack.pop();
   } else {
     canonicalizedObj = obj;
   }

   return canonicalizedObj;
 }
function canonicalize(obj, stack) {
   stack = stack || [];

   if (utils.indexOf(stack, obj) !== -1) return obj;

   var canonicalizedObj;

   if ('[object Array]' == {}.toString.call(obj)) {
     stack.push(obj);
     canonicalizedObj = utils.map(obj, function(item) {
       return canonicalize(item, stack);
     });
     stack.pop();
   } else if (typeof obj === 'object' && obj !== null) {
     stack.push(obj);
     canonicalizedObj = {};
     utils.forEach(utils.keys(obj).sort(), function(key) {
       canonicalizedObj[key] = canonicalize(obj[key], stack);
     });
     stack.pop();
   } else {
     canonicalizedObj = obj;
   }

   return canonicalizedObj;
 }
function canonicalize ( obj , stack ) { stack = stack || [ ] ; if ( utils . indexOf ( stack , obj ) !== - 1 ) return obj ; var canonicalizedObj ; if ( '[object Array]' == { } . toString . call ( obj ) ) { stack . push ( obj ) ; canonicalizedObj = utils . map ( obj , function ( item ) { return canonicalize ( item , stack ) ; } ) ; stack . pop ( ) ; } else if ( typeof obj === 'object' && obj !== null ) { stack . push ( obj ) ; canonicalizedObj = { } ; utils . forEach ( utils . keys ( obj ) . sort ( ) , function ( key ) { canonicalizedObj [ key ] = canonicalize ( obj [ key ] , stack ) ; } ) ; stack . pop ( ) ; } else { canonicalizedObj = obj ; } return canonicalizedObj ; }
Return a new object that has the keys in sorted order.
@param {Object} obj
@return {Object}
@api private
Return a new object that has the keys in sorted order .