Prefer a map and a join as feel it's easier to understand, and I found a case in the wild where Array.prototype.reduce was overwritten (which admittedly is also a danger with map) (#52)

This commit is contained in:
Eoghan Murray
2020-10-15 06:14:57 +01:00
committed by GitHub
parent 1251091d64
commit b3e7d5a476

View File

@@ -35,10 +35,7 @@ function getCssRulesString(s: CSSStyleSheet): string | null {
try {
const rules = s.rules || s.cssRules;
return rules
? Array.from(rules).reduce(
(prev, cur) => prev + getCssRuleString(cur),
'',
)
? Array.from(rules).map(getCssRuleString).join('')
: null;
} catch (error) {
return null;