mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(util) findObjByNameInArr: add arguments check
This commit is contained in:
parent
ec42e12457
commit
54be194305
1 changed files with 25 additions and 22 deletions
47
lib/util.js
47
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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue