Skip to content

Commit

Permalink
Fix deepObjectValueCheck to use polyfill in place of Object.values
Browse files Browse the repository at this point in the history
  • Loading branch information
Jashepp committed Nov 2, 2017
1 parent e6c3e9e commit 25391f5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/proxy-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ exports.create = (...args)=>{
};

// Alternative is to do: try{ return _.isEqual(JSON.parse(JSON.stringify(obj)),obj); }catch(err){return false;}
const listObjectValues = Object.values || ((obj)=>{
let arr = [];
for(var k in obj) Object.prototype.hasOwnProperty.call(obj,k) && Object.prototype.propertyIsEnumerable.call(obj,k) && arr.push(obj[k]);
return arr;
});
const deepObjectValueCheck = (obj,map=new Map())=>{
if(map.has(obj)) return map.get(obj);
map.set(obj,false);
if(obj.constructor!==Object && obj.constructor!==Array && _.isFunction(obj.constructor)) return false;
for (let val of ((_.isArray(obj) && obj) || ( _.isObject(obj) && Object.values(obj)) || [])) {
for (let val of ((_.isArray(obj) && obj) || ( _.isObject(obj) && listObjectValues(obj)) || [])) {
if(_.isNumber(val) || _.isBoolean(val) || _.isString(val) || _.isNull(val) || _.isUndefined(val) || _.isNaN(val)) continue;
if (_.isConstructed(val) || _.isFunction(val) || _.isDate(val) || _.isPromise(val)) return false;
if(_.isArray(val) || _.isObject(val)){
Expand Down

0 comments on commit 25391f5

Please sign in to comment.