UNPKG

680 BJavaScriptView Raw
1'use strict'
2
3/**
4 * @description Get the next tag from a node list
5 *
6 * @method getNextTag
7 *
8 * @param {Array} nodes Nodes
9 * @param {Number} i Accumulator
10 *
11 * @return {Array} [] Array containing the next tag
12 */
13function getNextTag (nodes, i) {
14 // loop until we get the next tag (bypassing newlines etc)
15 while (i < nodes.length) {
16 const node = nodes[i]
17
18 if (typeof node === 'object') {
19 return [i, node]
20 } else if (typeof node === 'string' && node.trim().length > 0) {
21 return [i++, node]
22 } else {
23 i++
24 }
25 }
26
27 return [i, { tag: undefined }]
28}
29
30/**
31 * @module tags
32 *
33 * @type {Function}
34 */
35module.exports = getNextTag