summaryrefslogtreecommitdiff
path: root/node_modules/locutus/php/array/count.js.map
blob: 7ca0deb8dd6903e6f30daa2440a4714f1811a5d8 (plain) (blame)
1
{"version":3,"sources":["../../../src/php/array/count.js"],"names":["module","exports","count","mixedVar","mode","key","cnt","constructor","Array","Object","hasOwnProperty"],"mappings":";;AAAAA,OAAOC,OAAP,GAAiB,SAASC,KAAT,CAAgBC,QAAhB,EAA0BC,IAA1B,EAAgC;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAIC,GAAJ;AACA,MAAIC,MAAM,CAAV;;AAEA,MAAIH,aAAa,IAAb,IAAqB,OAAOA,QAAP,KAAoB,WAA7C,EAA0D;AACxD,WAAO,CAAP;AACD,GAFD,MAEO,IAAIA,SAASI,WAAT,KAAyBC,KAAzB,IAAkCL,SAASI,WAAT,KAAyBE,MAA/D,EAAuE;AAC5E,WAAO,CAAP;AACD;;AAED,MAAIL,SAAS,iBAAb,EAAgC;AAC9BA,WAAO,CAAP;AACD;AACD,MAAIA,SAAS,CAAb,EAAgB;AACdA,WAAO,CAAP;AACD;;AAED,OAAKC,GAAL,IAAYF,QAAZ,EAAsB;AACpB,QAAIA,SAASO,cAAT,CAAwBL,GAAxB,CAAJ,EAAkC;AAChCC;AACA,UAAIF,SAAS,CAAT,IAAcD,SAASE,GAAT,CAAd,KACDF,SAASE,GAAT,EAAcE,WAAd,KAA8BC,KAA9B,IACCL,SAASE,GAAT,EAAcE,WAAd,KAA8BE,MAF9B,CAAJ,EAE2C;AACzCH,eAAOJ,MAAMC,SAASE,GAAT,CAAN,EAAqB,CAArB,CAAP;AACD;AACF;AACF;;AAED,SAAOC,GAAP;AACD,CAzCD","file":"count.js","sourcesContent":["module.exports = function count (mixedVar, mode) {\n  //  discuss at: http://locutus.io/php/count/\n  // original by: Kevin van Zonneveld (http://kvz.io)\n  //    input by: Waldo Malqui Silva (http://waldo.malqui.info)\n  //    input by: merabi\n  // bugfixed by: Soren Hansen\n  // bugfixed by: Olivier Louvignes (http://mg-crea.com/)\n  // improved by: Brett Zamir (http://brett-zamir.me)\n  //   example 1: count([[0,0],[0,-4]], 'COUNT_RECURSIVE')\n  //   returns 1: 6\n  //   example 2: count({'one' : [1,2,3,4,5]}, 'COUNT_RECURSIVE')\n  //   returns 2: 6\n\n  var key\n  var cnt = 0\n\n  if (mixedVar === null || typeof mixedVar === 'undefined') {\n    return 0\n  } else if (mixedVar.constructor !== Array && mixedVar.constructor !== Object) {\n    return 1\n  }\n\n  if (mode === 'COUNT_RECURSIVE') {\n    mode = 1\n  }\n  if (mode !== 1) {\n    mode = 0\n  }\n\n  for (key in mixedVar) {\n    if (mixedVar.hasOwnProperty(key)) {\n      cnt++\n      if (mode === 1 && mixedVar[key] &&\n        (mixedVar[key].constructor === Array ||\n          mixedVar[key].constructor === Object)) {\n        cnt += count(mixedVar[key], 1)\n      }\n    }\n  }\n\n  return cnt\n}\n"]}