Closed jorenbroekema closed 5 months ago
By the looks of things, it's only used for the template code & examples.
I assume these need to still be supported, what would be the best approach here?
Maybe the template package to be used standalone https://www.npmjs.com/package/lodash.template (however, I think Lodash still needs to make utils available inside the function like forEach
).
With regards to template, I think it would be good to just take the templates and turn them into template literals (function that returns template literal if dynamic vars are needed). ES6 has a good method for templating nowadays so then we don't need some third-party templating lib like lodash for it anymore.
Before:
export default `<?xml version="1.0" encoding="UTF-8"?>
<%
var props = dictionary.allTokens.filter(function(prop) {
return prop.attributes.category === 'color';
});
%>
<%= fileHeader({file, commentStyle: 'xml'}) %>
<resources>
<% props.forEach(function(prop) {
%><color name="<%= prop.name %>"><%= prop.value %></color><% if (prop.comment) { %><!-- <%= prop.comment %> --><% } %>
<% }); %>
</resources>`;
After:
export default (props, fileHeader) => `<?xml version="1.0" encoding="UTF-8"?>
${fileHeader}
<resources>
${props.reduce(
(acc, prop) =>
`${acc} <color name="${prop.name}">${prop.value}</color>${
prop.comment ? `<!-- ${prop.comment} -->` : ''
}\n`,
'',
)}
</resources>`;
@tahul
Mostly wanna drop this because Lodash is quite a node_modules bloating thing, and usually modern JS can do it already anyway. We don't use that much of lodash anyway, shouldn't be too much work.