1 | ;
|
2 | /**
|
3 | * count-elements module
|
4 | * @module count-elements
|
5 | * @see module:index
|
6 | */
|
7 | import lang from 'zero-lang';
|
8 |
|
9 | module.exports = (elements) => {
|
10 | let count = 0;
|
11 |
|
12 | function countOne(obj) {
|
13 | if (obj.type !== 'Document' && obj.type !== 'TextNode') {
|
14 | count++;
|
15 | }
|
16 | if (obj.children) {
|
17 | lang.each(obj.children, (child) => {
|
18 | countOne(child);
|
19 | });
|
20 | }
|
21 | }
|
22 |
|
23 | countOne(elements);
|
24 | return count;
|
25 | };
|