(table)
| 78 | |
| 79 | function extractTable(dom, integerTable, fractionTable) { |
| 80 | function extract(table) { |
| 81 | const tbody = table.querySelector('tbody'); |
| 82 | |
| 83 | let tr = tbody.firstElementChild; |
| 84 | |
| 85 | let current; |
| 86 | let results = {}; |
| 87 | |
| 88 | do { |
| 89 | if (tr.firstElementChild.tagName === 'TH') { |
| 90 | if (current) { |
| 91 | for (const language of current.languages) { |
| 92 | if (!results[language]) { |
| 93 | results[language] = Object.fromEntries( |
| 94 | Object.keys(current.rules).map(key => [key, []]) |
| 95 | ); |
| 96 | } |
| 97 | |
| 98 | for (let rule in current.rules) { |
| 99 | results[language][rule] = [].concat(results[language][rule], current.rules[rule]); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | current = { |
| 105 | range: [], |
| 106 | languages: [], |
| 107 | rules: {} |
| 108 | }; |
| 109 | |
| 110 | current.range = getRange(tr); |
| 111 | } else if ( |
| 112 | tr.children[1] instanceof dom.window.HTMLTableCellElement && |
| 113 | tr.children[1].classList.contains('l') |
| 114 | ) { |
| 115 | current.languages = getLocales(tr.children[1]); |
| 116 | } else { |
| 117 | current.rules = getPlurals(tr, current.range); |
| 118 | } |
| 119 | } while ((tr = tr.nextElementSibling)); |
| 120 | |
| 121 | return results; |
| 122 | } |
| 123 | |
| 124 | const integer = extract(integerTable); |
| 125 | const fraction = extract(fractionTable); |
no test coverage detected