UNPKG

deep-sort-object

Version:
89 lines (66 loc) 2.72 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.deepSortObject = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 'use strict'; var isPlainObject = require('is-plain-object'); function defaultSortFn(a, b) { return a.localeCompare(b); } function sort(src, comparator) { var out; if (Array.isArray(src)) { return src.map(function (item) { return sort(item, comparator); }); } if (isPlainObject(src)) { out = {}; Object.keys(src).sort(comparator || defaultSortFn).forEach(function (key) { out[key] = sort(src[key], comparator); }); return out; } return src; } module.exports = sort; },{"is-plain-object":2}],2:[function(require,module,exports){ /*! * is-plain-object <https://github.com/jonschlinkert/is-plain-object> * * Copyright (c) 2014-2015, Jon Schlinkert. * Licensed under the MIT License. */ 'use strict'; var isObject = require('isobject'); function isObjectObject(o) { return isObject(o) === true && Object.prototype.toString.call(o) === '[object Object]'; } module.exports = function isPlainObject(o) { var ctor,prot; if (isObjectObject(o) === false) return false; // If has modified constructor ctor = o.constructor; if (typeof ctor !== 'function') return false; // If has modified prototype prot = ctor.prototype; if (isObjectObject(prot) === false) return false; // If constructor does not have an Object-specific method if (prot.hasOwnProperty('isPrototypeOf') === false) { return false; } // Most likely a plain Object return true; }; },{"isobject":3}],3:[function(require,module,exports){ /*! * isobject <https://github.com/jonschlinkert/isobject> * * Copyright (c) 2014-2015, Jon Schlinkert. * Licensed under the MIT License. */ 'use strict'; module.exports = function isObject(val) { return val != null && typeof val === 'object' && !Array.isArray(val); }; },{}]},{},[1])(1) });