Object.isObject = function(obj){ return obj != null && typeof obj === 'object' && Array.isArray(obj) === false; } Number.isNumber = function(num){ return typeof num ==='number' && isFinite(num); }
Object.find = function(obj = {}, path = ''){ path = path.split('.'); let idx = 0, len = path.length; while(obj != null && idx < len){ obj = obj[path[idx++]] } return (idx && idx == len) ? obj : undefined; }
Object.only = function(obj, keys){ obj = obj || {}; if ('string' == typeof keys) keys = keys.split(/ +/); return keys.reduce(function(ret, key){ if (null == obj[key]) return ret; ret[key] = obj[key]; return ret; }, {}); };
/** * */ Object.only = function(obj, keys){ obj = obj || {}; if ('string' == typeof keys) keys = keys.split(/ +/); return keys.reduce(function(ret, key){ if (null == obj[key]) return ret; ret[key] = obj[key]; return ret; }, {}); };