diff --git a/lib/util.js b/lib/util.js index 044dc323..1fee41e5 100644 --- a/lib/util.js +++ b/lib/util.js @@ -549,29 +549,32 @@ * @param name */ this.findObjByNameInArr = function(array, name) { - var ret, - isArray = Util.type.array(array); + var ret; - if (isArray) { - array.some(function(item) { - var is = item.name === name, - isArray = Util.type.array(item); - - if (is) - ret = item; - else if (isArray) - item.some(function(item) { - is = item.name === name; - - if (is) - ret = item.data; - - return is; - }); - - return is; - }); - } + if (!Array.isArray(array)) + throw(Error('array should be array!')); + + if (typeof name !== 'string') + throw(Error('name should be string!')); + + array.some(function(item) { + var is = item.name === name, + isArray = Util.type.array(item); + + if (is) + ret = item; + else if (isArray) + item.some(function(item) { + is = item.name === name; + + if (is) + ret = item.data; + + return is; + }); + + return is; + }); return ret; };