MCPcopy Create free account
hub / github.com/adobe/react-spectrum / extract

Function extract

scripts/generateAllPlurals.mjs:80–122  ·  view source on GitHub ↗
(table)

Source from the content-addressed store, hash-verified

78
79function 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);

Callers 1

extractTableFunction · 0.85

Calls 3

getRangeFunction · 0.85
getLocalesFunction · 0.85
getPluralsFunction · 0.85

Tested by

no test coverage detected