{"version":3,"file":"index.min.js","sources":["source/index.js"],"sourcesContent":["const isList = (node) => (\r\n node instanceof Array\r\n || node instanceof HTMLCollection\r\n || node instanceof NodeList\r\n);\r\n\r\nconst toList = (...args) => {\r\n const { length } = args;\r\n const [node] = args;\r\n\r\n if (length === 1 && isList(node)) {\r\n return node;\r\n }\r\n\r\n const list = [];\r\n\r\n for (let index = 0; index < length; index++) {\r\n const part = args[index];\r\n if (isList(part)) {\r\n list.push.call(part);\r\n } else {\r\n list.push(part);\r\n }\r\n }\r\n\r\n return list;\r\n};\r\n\r\nconst isNode = (node) => node instanceof HTMLElement;\r\n\r\nconst toNode = (node) => {\r\n // if list we use only first node\r\n if (isList(node)) {\r\n return node.length ? node[0] : null;\r\n }\r\n\r\n return isNode(node) ? node : null;\r\n};\r\n\r\nconst getNodeAt = (list, index = 0) => {\r\n if (isList(list)) {\r\n return list[index];\r\n }\r\n\r\n return list;\r\n};\r\n\r\nconst getLength = (list) => list.length;\r\n\r\nconst getName = (node) => toNode(node).nodeName;\r\n\r\n// Node\r\nconst getChildren = (node) => {\r\n node = toNode(node);\r\n\r\n // if not a node, return empty list\r\n return isNode(node) ? node.children : toList();\r\n};\r\n\r\nconst getChildrenByName = (node, name) => {\r\n name = name.toLowerCase();\r\n const children = getChildren(node);\r\n const { length } = children;\r\n\r\n if (!length) {\r\n return children;\r\n }\r\n\r\n const list = [];\r\n\r\n for (let index = 0; index < children.length; index++) {\r\n const child = children[index];\r\n if (child.nodeName.toLowerCase() === name) {\r\n list.push(child);\r\n }\r\n }\r\n\r\n return list;\r\n};\r\n\r\nconst hasChild = (node, name) => {\r\n const children = getChildren(node);\r\n const { length } = children;\r\n\r\n for (let index = 0; index < length; index++) {\r\n if (children[index].nodeName === name) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n};\r\n\r\nconst getChildAt = (node, index) => getChildren(node)[index];\r\n\r\nconst getNodeParent = (node) => toNode(node).parentNode;\r\n\r\nconst getNodeRoot = (node) => toNode(node).getRootNode();\r\n\r\nconst validateRoot = (root) => {\r\n if (root === undefined || root === document) {\r\n return document.firstElementChild;\r\n }\r\n\r\n if (typeof root === 'string') {\r\n return document.querySelector(root);\r\n }\r\n\r\n return root;\r\n};\r\n\r\nexport default {\r\n isList,\r\n toList,\r\n isNode,\r\n toNode,\r\n getNodeAt,\r\n getLength,\r\n getName,\r\n getChildren,\r\n getChildrenByName,\r\n hasChild,\r\n getChildAt,\r\n getNodeParent,\r\n getNodeRoot,\r\n validateRoot,\r\n};\r\n"],"names":["isList","node","Array","HTMLCollection","NodeList","toList","args","length","list","index","part","push","call","isNode","HTMLElement","toNode","getChildren","children","nodeName","name","toLowerCase","child","parentNode","getRootNode","root","undefined","document","firstElementChild","querySelector"],"mappings":"oMAAA,MAAMA,EAAUC,GACdA,aAAgBC,OACbD,aAAgBE,gBAChBF,aAAgBG,SAGfC,EAAS,IAAIC,WACXC,OAAEA,GAAWD,GACZL,GAAQK,KAEA,IAAXC,GAAgBP,EAAOC,UAClBA,QAGHO,SAED,IAAIC,EAAQ,EAAGA,EAAQF,EAAQE,IAAS,OACrCC,EAAOJ,EAAKG,GACdT,EAAOU,KACJC,KAAKC,KAAKF,KAEVC,KAAKD,UAIPF,GAGHK,EAAUZ,GAASA,aAAgBa,YAEnCC,EAAUd,GAEVD,EAAOC,GACFA,EAAKM,OAASN,EAAK,GAAK,KAG1BY,EAAOZ,GAAQA,EAAO,KAgBzBe,EAAef,MACZc,EAAOd,GAGPY,EAAOZ,GAAQA,EAAKgB,SAAWZ,0DAjBtB,CAACG,EAAMC,EAAQ,IAC3BT,EAAOQ,GACFA,EAAKC,GAGPD,YAGUA,GAASA,EAAKD,eAEhBN,GAASc,EAAOd,GAAMiB,yCAUb,CAACjB,EAAMkB,OACxBA,EAAKC,oBACNH,EAAWD,EAAYf,IACvBM,OAAEA,GAAWU,MAEdV,SACIU,QAGHT,SAED,IAAIC,EAAQ,EAAGA,EAAQQ,EAASV,OAAQE,IAAS,OAC9CY,EAAQJ,EAASR,GACnBY,EAAMH,SAASE,gBAAkBD,KAC9BR,KAAKU,UAIPb,YAGQ,CAACP,EAAMkB,WAChBF,EAAWD,EAAYf,IACvBM,OAAEA,GAAWU,MAEd,IAAIR,EAAQ,EAAGA,EAAQF,EAAQE,OAC9BQ,EAASR,GAAOS,WAAaC,SACxB,SAIJ,cAGU,CAAClB,EAAMQ,IAAUO,EAAYf,GAAMQ,iBAE/BR,GAASc,EAAOd,GAAMqB,uBAExBrB,GAASc,EAAOd,GAAMsB,2BAErBC,QACPC,IAATD,GAAsBA,IAASE,SAC1BA,SAASC,kBAGE,iBAATH,EACFE,SAASE,cAAcJ,GAGzBA"}