function Recursion(node){ var count=0; for (var key in node) { count++; var value = node[key]; delete node[key]; //如果node为叶子节点 if (key.toString() == '$') { for (var attr in value) node[attr] = value[attr]; } else { if (value instanceof Array) { if (value.length > 0) { node["children"] = value; for (var obj in value) Recursion(value[obj]); } } } } if(count==1) node["children"]=[]; } function randomString(len) { len = len || 32; var $chars = 'abcdefhijkmnprstwxyz'; // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1 var maxPos = $chars.length; var pwd = ''; for (i = 0; i < len; i++) { pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); } return pwd; } function compArray(array1,array2){ if((array1&&typeof array1 ==="object"&&array1.constructor===Array)&&(array2&&typeof array2 ==="object"&&array2.constructor===Array)){ if(array1.length==array2.length){ for(var i=0;i 0; }else{ return false; } } exports.randomString = randomString; exports.Recursion = Recursion; exports.compObj = compObj; exports.selectorMatches = selectorMatches;